tape: proxmox-tape - use API instead of direct functions calls
This commit is contained in:
parent
4470eba551
commit
5243df4712
|
@ -1202,6 +1202,11 @@ pub const SUBDIRS: SubdirMap = &sorted!([
|
||||||
&Router::new()
|
&Router::new()
|
||||||
.post(&API_METHOD_ERASE_MEDIA)
|
.post(&API_METHOD_ERASE_MEDIA)
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"export-media",
|
||||||
|
&Router::new()
|
||||||
|
.put(&API_METHOD_EXPORT_MEDIA)
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"inventory",
|
"inventory",
|
||||||
&Router::new()
|
&Router::new()
|
||||||
|
@ -1211,7 +1216,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([
|
||||||
(
|
(
|
||||||
"label-media",
|
"label-media",
|
||||||
&Router::new()
|
&Router::new()
|
||||||
.put(&API_METHOD_LABEL_MEDIA)
|
.post(&API_METHOD_LABEL_MEDIA)
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"load-media",
|
"load-media",
|
||||||
|
|
|
@ -205,21 +205,16 @@ async fn eject_media(param: Value) -> Result<(), Error> {
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Load media with specified label
|
/// Load media with specified label
|
||||||
async fn load_media(
|
async fn load_media(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_LOAD_MEDIA;
|
let mut client = connect_to_localhost()?;
|
||||||
|
|
||||||
match info.handler {
|
let path = format!("api2/json/tape/drive/{}/load-media", drive);
|
||||||
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
client.put(&path, Some(param)).await?;
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -238,21 +233,16 @@ async fn load_media(
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Export media with specified label
|
/// Export media with specified label
|
||||||
async fn export_media(
|
async fn export_media(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_EXPORT_MEDIA;
|
let mut client = connect_to_localhost()?;
|
||||||
|
|
||||||
match info.handler {
|
let path = format!("api2/json/tape/drive/{}/export-media", drive);
|
||||||
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
client.put(&path, Some(param)).await?;
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -273,21 +263,16 @@ async fn export_media(
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Load media from the specified slot
|
/// Load media from the specified slot
|
||||||
async fn load_media_from_slot(
|
async fn load_media_from_slot(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_LOAD_SLOT;
|
let mut client = connect_to_localhost()?;
|
||||||
|
|
||||||
match info.handler {
|
let path = format!("api2/json/tape/drive/{}/load-slot", drive);
|
||||||
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
client.put(&path, Some(param)).await?;
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -309,21 +294,16 @@ async fn load_media_from_slot(
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Unload media via changer
|
/// Unload media via changer
|
||||||
async fn unload_media(
|
async fn unload_media(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_UNLOAD;
|
let mut client = connect_to_localhost()?;
|
||||||
|
|
||||||
match info.handler {
|
let path = format!("api2/json/tape/drive/{}/unload", drive);
|
||||||
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
client.put(&path, Some(param)).await?;
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -342,27 +322,28 @@ async fn unload_media(
|
||||||
"label-text": {
|
"label-text": {
|
||||||
schema: MEDIA_LABEL_SCHEMA,
|
schema: MEDIA_LABEL_SCHEMA,
|
||||||
},
|
},
|
||||||
},
|
"output-format": {
|
||||||
|
schema: OUTPUT_FORMAT,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Label media
|
/// Label media
|
||||||
async fn label_media(
|
async fn label_media(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
let output_format = get_output_format(¶m);
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
let info = &api2::tape::drive::API_METHOD_LABEL_MEDIA;
|
let mut client = connect_to_localhost()?;
|
||||||
|
|
||||||
let result = match info.handler {
|
let path = format!("api2/json/tape/drive/{}/label-media", drive);
|
||||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
let result = client.post(&path, Some(param)).await?;
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
wait_for_local_worker(result.as_str().unwrap()).await?;
|
view_task_result(client, result, &output_format).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -387,21 +368,21 @@ async fn label_media(
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Read media label
|
/// Read media label
|
||||||
async fn read_label(
|
async fn read_label(param: Value) -> Result<(), Error> {
|
||||||
mut param: Value,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
let output_format = get_output_format(¶m);
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let (config, _digest) = config::drive::config()?;
|
let (config, _digest) = config::drive::config()?;
|
||||||
|
|
||||||
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
let drive = lookup_drive_name(¶m, &config)?;
|
||||||
|
|
||||||
|
let client = connect_to_localhost()?;
|
||||||
|
|
||||||
|
let path = format!("api2/json/tape/drive/{}/read-label", drive);
|
||||||
|
let mut result = client.get(&path, Some(param)).await?;
|
||||||
|
let mut data = result["data"].take();
|
||||||
|
|
||||||
let output_format = get_output_format(¶m);
|
|
||||||
let info = &api2::tape::drive::API_METHOD_READ_LABEL;
|
let info = &api2::tape::drive::API_METHOD_READ_LABEL;
|
||||||
let mut data = match info.handler {
|
|
||||||
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let options = default_table_format_options()
|
let options = default_table_format_options()
|
||||||
.column(ColumnConfig::new("label-text"))
|
.column(ColumnConfig::new("label-text"))
|
||||||
|
|
Loading…
Reference in New Issue