tape: mtx_status - consider new export-slots property
This commit is contained in:
parent
38ae42b11a
commit
d5035c5600
@ -52,7 +52,7 @@ pub async fn get_status(name: String) -> Result<Vec<MtxStatusEntry>, Error> {
|
|||||||
let data: ScsiTapeChanger = config.lookup("changer", &name)?;
|
let data: ScsiTapeChanger = config.lookup("changer", &name)?;
|
||||||
|
|
||||||
let status = tokio::task::spawn_blocking(move || {
|
let status = tokio::task::spawn_blocking(move || {
|
||||||
mtx_status(&data.path)
|
mtx_status(&data)
|
||||||
}).await??;
|
}).await??;
|
||||||
|
|
||||||
let state_path = Path::new(TAPE_STATUS_DIR);
|
let state_path = Path::new(TAPE_STATUS_DIR);
|
||||||
|
@ -56,7 +56,7 @@ impl MediaChange for LinuxTapeDrive {
|
|||||||
None => bail!("drive '{}' has no associated changer", self.name),
|
None => bail!("drive '{}' has no associated changer", self.name),
|
||||||
};
|
};
|
||||||
|
|
||||||
let status = mtx_status(&changer.path)?;
|
let status = mtx_status(&changer)?;
|
||||||
|
|
||||||
let drivenum = self.changer_drive_id.unwrap_or(0);
|
let drivenum = self.changer_drive_id.unwrap_or(0);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ impl MediaChange for LinuxTapeDrive {
|
|||||||
|
|
||||||
let drivenum = self.changer_drive_id.unwrap_or(0);
|
let drivenum = self.changer_drive_id.unwrap_or(0);
|
||||||
|
|
||||||
let status = mtx_status(&changer.path)?;
|
let status = mtx_status(&changer)?;
|
||||||
|
|
||||||
unload_to_free_slot(&self.name, &changer.path, &status, drivenum)
|
unload_to_free_slot(&self.name, &changer.path, &status, drivenum)
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ impl MediaChange for LinuxTapeDrive {
|
|||||||
None => return Ok(Vec::new()),
|
None => return Ok(Vec::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let status = mtx_status(&changer.path)?;
|
let status = mtx_status(&changer)?;
|
||||||
|
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
|
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
use proxmox::tools::Uuid;
|
use proxmox::{
|
||||||
|
tools::Uuid,
|
||||||
|
api::schema::parse_property_string,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
tools::run_command,
|
tools::run_command,
|
||||||
|
api2::types::{
|
||||||
|
SLOT_ARRAY_SCHEMA,
|
||||||
|
ScsiTapeChanger,
|
||||||
|
},
|
||||||
tape::{
|
tape::{
|
||||||
Inventory,
|
Inventory,
|
||||||
changer::{
|
changer::{
|
||||||
@ -17,14 +25,35 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Run 'mtx status' and return parsed result.
|
/// Run 'mtx status' and return parsed result.
|
||||||
pub fn mtx_status(path: &str) -> Result<MtxStatus, Error> {
|
pub fn mtx_status(config: &ScsiTapeChanger) -> Result<MtxStatus, Error> {
|
||||||
|
|
||||||
|
let path = &config.path;
|
||||||
|
|
||||||
|
let mut export_slots: HashSet<u64> = HashSet::new();
|
||||||
|
|
||||||
|
if let Some(slots) = &config.export_slots {
|
||||||
|
let slots: Value = parse_property_string(&slots, &SLOT_ARRAY_SCHEMA)?;
|
||||||
|
export_slots = slots
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter_map(|v| v.as_u64())
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
let mut command = std::process::Command::new("mtx");
|
let mut command = std::process::Command::new("mtx");
|
||||||
command.args(&["-f", path, "status"]);
|
command.args(&["-f", path, "status"]);
|
||||||
|
|
||||||
let output = run_command(command, None)?;
|
let output = run_command(command, None)?;
|
||||||
|
|
||||||
let status = parse_mtx_status(&output)?;
|
let mut status = parse_mtx_status(&output)?;
|
||||||
|
|
||||||
|
for (i, entry) in status.slots.iter_mut().enumerate() {
|
||||||
|
let slot = i as u64 + 1;
|
||||||
|
if export_slots.contains(&slot) {
|
||||||
|
entry.0 = true; // mark as IMPORT/EXPORT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(status)
|
Ok(status)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ pub fn update_online_status(state_path: &Path) -> Result<OnlineStatusMap, Error>
|
|||||||
let mut map = OnlineStatusMap::new(&config)?;
|
let mut map = OnlineStatusMap::new(&config)?;
|
||||||
|
|
||||||
for changer in changers {
|
for changer in changers {
|
||||||
let status = match mtx_status(&changer.path) {
|
let status = match mtx_status(&changer) {
|
||||||
Ok(status) => status,
|
Ok(status) => status,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("unable to get changer '{}' status - {}", changer.name, err);
|
eprintln!("unable to get changer '{}' status - {}", changer.name, err);
|
||||||
|
Loading…
Reference in New Issue
Block a user