tape/changer: refactor marking of import/export slots from config
we did this for 'mtx', but missed it for the sg_pt_changer code refactor it into the MtxStatus strut, and call it from both code paths Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
2da7aca8e8
commit
4be4736603
@ -1,45 +1,19 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox::{
|
||||
api::schema::parse_property_string,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
tools::run_command,
|
||||
api2::types::{
|
||||
SLOT_ARRAY_SCHEMA,
|
||||
ScsiTapeChanger,
|
||||
},
|
||||
tape::{
|
||||
changer::{
|
||||
MtxStatus,
|
||||
mtx::{
|
||||
parse_mtx_status,
|
||||
},
|
||||
},
|
||||
api2::types::ScsiTapeChanger,
|
||||
tape::changer::{
|
||||
MtxStatus,
|
||||
mtx::parse_mtx_status,
|
||||
},
|
||||
};
|
||||
|
||||
/// Run 'mtx status' and return parsed result.
|
||||
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");
|
||||
command.args(&["-f", path, "status"]);
|
||||
|
||||
@ -47,12 +21,7 @@ pub fn mtx_status(config: &ScsiTapeChanger) -> Result<MtxStatus, Error> {
|
||||
|
||||
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.import_export = true; // mark as IMPORT/EXPORT
|
||||
}
|
||||
}
|
||||
status.mark_import_export_slots(&config)?;
|
||||
|
||||
Ok(status)
|
||||
}
|
||||
|
Reference in New Issue
Block a user