tape: cli cleanup - avoid api redefinition
This commit is contained in:
parent
4917f1e2d4
commit
a3c709ef21
@ -86,7 +86,7 @@ pub fn load_media(drive: String, changer_id: String) -> Result<(), Error> {
|
|||||||
#[api(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
name: {
|
drive: {
|
||||||
schema: DRIVE_ID_SCHEMA,
|
schema: DRIVE_ID_SCHEMA,
|
||||||
},
|
},
|
||||||
slot: {
|
slot: {
|
||||||
@ -99,18 +99,18 @@ pub fn load_media(drive: String, changer_id: String) -> Result<(), Error> {
|
|||||||
)]
|
)]
|
||||||
/// Unload media via changer
|
/// Unload media via changer
|
||||||
pub fn unload(
|
pub fn unload(
|
||||||
name: String,
|
drive: String,
|
||||||
slot: Option<u64>,
|
slot: Option<u64>,
|
||||||
_param: Value,
|
_param: Value,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
let mut drive: LinuxTapeDrive = config.lookup("linux", &name)?;
|
let mut drive_config: LinuxTapeDrive = config.lookup("linux", &drive)?;
|
||||||
|
|
||||||
let changer: ScsiTapeChanger = match drive.changer {
|
let changer: ScsiTapeChanger = match drive_config.changer {
|
||||||
Some(ref changer) => config.lookup("changer", changer)?,
|
Some(ref changer) => config.lookup("changer", changer)?,
|
||||||
None => bail!("drive '{}' has no associated changer", name),
|
None => bail!("drive '{}' has no associated changer", drive),
|
||||||
};
|
};
|
||||||
|
|
||||||
let drivenum: u64 = 0;
|
let drivenum: u64 = 0;
|
||||||
@ -118,7 +118,7 @@ pub fn unload(
|
|||||||
if let Some(slot) = slot {
|
if let Some(slot) = slot {
|
||||||
mtx_unload(&changer.path, slot, drivenum)
|
mtx_unload(&changer.path, slot, drivenum)
|
||||||
} else {
|
} else {
|
||||||
drive.unload_media()
|
drive_config.unload_media()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,15 +15,12 @@ use proxmox_backup::{
|
|||||||
self,
|
self,
|
||||||
types::{
|
types::{
|
||||||
CHANGER_ID_SCHEMA,
|
CHANGER_ID_SCHEMA,
|
||||||
LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
ScsiTapeChanger,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tape::{
|
tape::{
|
||||||
complete_changer_path,
|
complete_changer_path,
|
||||||
},
|
},
|
||||||
config::{
|
config::{
|
||||||
self,
|
|
||||||
drive::{
|
drive::{
|
||||||
complete_drive_name,
|
complete_drive_name,
|
||||||
complete_changer_name,
|
complete_changer_name,
|
||||||
@ -43,20 +40,20 @@ pub fn changer_commands() -> CommandLineInterface {
|
|||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"remove",
|
"remove",
|
||||||
CliCommand::new(&API_METHOD_DELETE_CHANGER)
|
CliCommand::new(&api2::config::changer::API_METHOD_DELETE_CHANGER)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_changer_name)
|
.completion_cb("name", complete_changer_name)
|
||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"create",
|
"create",
|
||||||
CliCommand::new(&API_METHOD_CREATE_CHANGER)
|
CliCommand::new(&api2::config::changer::API_METHOD_CREATE_CHANGER)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_drive_name)
|
.completion_cb("name", complete_drive_name)
|
||||||
.completion_cb("path", complete_changer_path)
|
.completion_cb("path", complete_changer_path)
|
||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"update",
|
"update",
|
||||||
CliCommand::new(&API_METHOD_UPDATE_CHANGER)
|
CliCommand::new(&api2::config::changer::API_METHOD_UPDATE_CHANGER)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_changer_name)
|
.completion_cb("name", complete_changer_name)
|
||||||
.completion_cb("path", complete_changer_path)
|
.completion_cb("path", complete_changer_path)
|
||||||
@ -67,7 +64,7 @@ pub fn changer_commands() -> CommandLineInterface {
|
|||||||
.completion_cb("name", complete_changer_name)
|
.completion_cb("name", complete_changer_name)
|
||||||
)
|
)
|
||||||
.insert("transfer",
|
.insert("transfer",
|
||||||
CliCommand::new(&API_METHOD_TRANSFER)
|
CliCommand::new(&api2::tape::changer::API_METHOD_TRANSFER)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_changer_name)
|
.completion_cb("name", complete_changer_name)
|
||||||
)
|
)
|
||||||
@ -76,33 +73,6 @@ pub fn changer_commands() -> CommandLineInterface {
|
|||||||
cmd_def.into()
|
cmd_def.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
schema: LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Create a new changer device
|
|
||||||
fn create_changer(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::changer::API_METHOD_CREATE_CHANGER;
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
@ -210,61 +180,6 @@ fn get_config(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Delete a tape changer configuration
|
|
||||||
fn delete_changer(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::changer::API_METHOD_DELETE_CHANGER;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
schema: LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Update a tape changer configuration
|
|
||||||
fn update_changer(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::changer::API_METHOD_UPDATE_CHANGER;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
@ -302,40 +217,3 @@ fn get_status(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
from: {
|
|
||||||
description: "Source slot number",
|
|
||||||
minimum: 1,
|
|
||||||
},
|
|
||||||
to: {
|
|
||||||
description: "Destination slot number",
|
|
||||||
minimum: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Transfers media from one slot to another
|
|
||||||
fn transfer(
|
|
||||||
name: String,
|
|
||||||
from: u64,
|
|
||||||
to: u64,
|
|
||||||
_param: Value,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
|
||||||
|
|
||||||
let data: ScsiTapeChanger = config.lookup("changer", &name)?;
|
|
||||||
|
|
||||||
let mut command = std::process::Command::new("mtx");
|
|
||||||
command.args(&["-f", &data.path, "transfer", &from.to_string(), &to.to_string()]);
|
|
||||||
|
|
||||||
proxmox_backup::tools::run_command(command, None)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -15,8 +15,6 @@ use proxmox_backup::{
|
|||||||
self,
|
self,
|
||||||
types::{
|
types::{
|
||||||
DRIVE_ID_SCHEMA,
|
DRIVE_ID_SCHEMA,
|
||||||
CHANGER_ID_SCHEMA,
|
|
||||||
LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tape::{
|
tape::{
|
||||||
@ -41,13 +39,13 @@ pub fn drive_commands() -> CommandLineInterface {
|
|||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"remove",
|
"remove",
|
||||||
CliCommand::new(&API_METHOD_DELETE_DRIVE)
|
CliCommand::new(&api2::config::drive::API_METHOD_DELETE_DRIVE)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_linux_drive_name)
|
.completion_cb("name", complete_linux_drive_name)
|
||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"create",
|
"create",
|
||||||
CliCommand::new(&API_METHOD_CREATE_LINUX_DRIVE)
|
CliCommand::new(&api2::config::drive::API_METHOD_CREATE_DRIVE)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_drive_name)
|
.completion_cb("name", complete_drive_name)
|
||||||
.completion_cb("path", complete_drive_path)
|
.completion_cb("path", complete_drive_path)
|
||||||
@ -55,7 +53,7 @@ pub fn drive_commands() -> CommandLineInterface {
|
|||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"update",
|
"update",
|
||||||
CliCommand::new(&API_METHOD_UPDATE_LINUX_DRIVE)
|
CliCommand::new(&api2::config::drive::API_METHOD_UPDATE_DRIVE)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["name"])
|
||||||
.completion_cb("name", complete_linux_drive_name)
|
.completion_cb("name", complete_linux_drive_name)
|
||||||
.completion_cb("path", complete_drive_path)
|
.completion_cb("path", complete_drive_path)
|
||||||
@ -63,52 +61,21 @@ pub fn drive_commands() -> CommandLineInterface {
|
|||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"load",
|
"load",
|
||||||
CliCommand::new(&API_METHOD_LOAD_SLOT)
|
CliCommand::new(&api2::tape::drive::API_METHOD_LOAD_SLOT)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["drive"])
|
||||||
.completion_cb("name", complete_linux_drive_name)
|
.completion_cb("drive", complete_linux_drive_name)
|
||||||
)
|
)
|
||||||
.insert(
|
.insert(
|
||||||
"unload",
|
"unload",
|
||||||
CliCommand::new(&API_METHOD_UNLOAD)
|
CliCommand::new(&api2::tape::drive::API_METHOD_UNLOAD)
|
||||||
.arg_param(&["name"])
|
.arg_param(&["drive"])
|
||||||
.completion_cb("name", complete_linux_drive_name)
|
.completion_cb("drive", complete_linux_drive_name)
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
cmd_def.into()
|
cmd_def.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: DRIVE_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
schema: LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
},
|
|
||||||
changer: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Create a new drive
|
|
||||||
fn create_linux_drive(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::drive::API_METHOD_CREATE_DRIVE;
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
@ -218,122 +185,3 @@ fn get_config(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: DRIVE_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Delete a drive configuration
|
|
||||||
fn delete_drive(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::drive::API_METHOD_DELETE_DRIVE;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: DRIVE_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
schema: LINUX_DRIVE_PATH_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
changer: {
|
|
||||||
schema: CHANGER_ID_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Update a drive configuration
|
|
||||||
fn update_linux_drive(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::config::drive::API_METHOD_UPDATE_DRIVE;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
drive: {
|
|
||||||
schema: DRIVE_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
slot: {
|
|
||||||
type: u64,
|
|
||||||
description: "Source slot number",
|
|
||||||
minimum: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Load media via changer from slot
|
|
||||||
fn load_slot(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_LOAD_SLOT;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
|
||||||
input: {
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
schema: DRIVE_ID_SCHEMA,
|
|
||||||
},
|
|
||||||
slot: {
|
|
||||||
description: "Target slot number. If omitted, defaults to the slot that the drive was loaded from.",
|
|
||||||
type: u64,
|
|
||||||
minimum: 1,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
/// Unload media via changer
|
|
||||||
fn unload(
|
|
||||||
param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_UNLOAD;
|
|
||||||
|
|
||||||
match info.handler {
|
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user