changer config cleanup: use Updater
This commit is contained in:
parent
67d00d5c0e
commit
5af3bcf062
|
@ -10,6 +10,7 @@ use proxmox::api::{
|
||||||
ArraySchema,
|
ArraySchema,
|
||||||
IntegerSchema,
|
IntegerSchema,
|
||||||
StringSchema,
|
StringSchema,
|
||||||
|
Updater,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,10 +63,11 @@ Import/Export, i.e. any media in those slots are considered to be
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize,Updater)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// SCSI tape changer
|
/// SCSI tape changer
|
||||||
pub struct ScsiTapeChanger {
|
pub struct ScsiTapeChanger {
|
||||||
|
#[updater(skip)]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
|
|
@ -14,10 +14,9 @@ use pbs_api_types::{
|
||||||
Authid,
|
Authid,
|
||||||
PROXMOX_CONFIG_DIGEST_SCHEMA,
|
PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||||
CHANGER_NAME_SCHEMA,
|
CHANGER_NAME_SCHEMA,
|
||||||
SCSI_CHANGER_PATH_SCHEMA,
|
|
||||||
SLOT_ARRAY_SCHEMA,
|
SLOT_ARRAY_SCHEMA,
|
||||||
EXPORT_SLOT_LIST_SCHEMA,
|
|
||||||
ScsiTapeChanger,
|
ScsiTapeChanger,
|
||||||
|
ScsiTapeChangerUpdater,
|
||||||
LtoTapeDrive,
|
LtoTapeDrive,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,15 +38,9 @@ use crate::{
|
||||||
protected: true,
|
protected: true,
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
name: {
|
config: {
|
||||||
schema: CHANGER_NAME_SCHEMA,
|
type: ScsiTapeChanger,
|
||||||
},
|
flatten: true,
|
||||||
path: {
|
|
||||||
schema: SCSI_CHANGER_PATH_SCHEMA,
|
|
||||||
},
|
|
||||||
"export-slots": {
|
|
||||||
schema: EXPORT_SLOT_LIST_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -56,41 +49,31 @@ use crate::{
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Create a new changer device
|
/// Create a new changer device
|
||||||
pub fn create_changer(
|
pub fn create_changer(config: ScsiTapeChanger) -> Result<(), Error> {
|
||||||
name: String,
|
|
||||||
path: String,
|
|
||||||
export_slots: Option<String>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let _lock = pbs_config::drive::lock()?;
|
let _lock = pbs_config::drive::lock()?;
|
||||||
|
|
||||||
let (mut config, _digest) = pbs_config::drive::config()?;
|
let (mut section_config, _digest) = pbs_config::drive::config()?;
|
||||||
|
|
||||||
let linux_changers = linux_tape_changer_list();
|
let linux_changers = linux_tape_changer_list();
|
||||||
|
|
||||||
check_drive_path(&linux_changers, &path)?;
|
check_drive_path(&linux_changers, &config.path)?;
|
||||||
|
|
||||||
let existing: Vec<ScsiTapeChanger> = config.convert_to_typed_array("changer")?;
|
let existing: Vec<ScsiTapeChanger> = section_config.convert_to_typed_array("changer")?;
|
||||||
|
|
||||||
for changer in existing {
|
for changer in existing {
|
||||||
if changer.name == name {
|
if changer.name == config.name {
|
||||||
bail!("Entry '{}' already exists", name);
|
bail!("Entry '{}' already exists", config.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if changer.path == path {
|
if changer.path == config.path {
|
||||||
bail!("Path '{}' already in use by '{}'", path, changer.name);
|
bail!("Path '{}' already in use by '{}'", config.path, changer.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = ScsiTapeChanger {
|
section_config.set_data(&config.name, "changer", &config)?;
|
||||||
name: name.clone(),
|
|
||||||
path,
|
|
||||||
export_slots,
|
|
||||||
};
|
|
||||||
|
|
||||||
config.set_data(&name, "changer", &item)?;
|
pbs_config::drive::save_config(§ion_config)?;
|
||||||
|
|
||||||
pbs_config::drive::save_config(&config)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -183,13 +166,9 @@ pub enum DeletableProperty {
|
||||||
name: {
|
name: {
|
||||||
schema: CHANGER_NAME_SCHEMA,
|
schema: CHANGER_NAME_SCHEMA,
|
||||||
},
|
},
|
||||||
path: {
|
update: {
|
||||||
schema: SCSI_CHANGER_PATH_SCHEMA,
|
type: ScsiTapeChangerUpdater,
|
||||||
optional: true,
|
flatten: true,
|
||||||
},
|
|
||||||
"export-slots": {
|
|
||||||
schema: EXPORT_SLOT_LIST_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
},
|
||||||
delete: {
|
delete: {
|
||||||
description: "List of properties to delete.",
|
description: "List of properties to delete.",
|
||||||
|
@ -212,8 +191,7 @@ pub enum DeletableProperty {
|
||||||
/// Update a tape changer configuration
|
/// Update a tape changer configuration
|
||||||
pub fn update_changer(
|
pub fn update_changer(
|
||||||
name: String,
|
name: String,
|
||||||
path: Option<String>,
|
update: ScsiTapeChangerUpdater,
|
||||||
export_slots: Option<String>,
|
|
||||||
delete: Option<Vec<DeletableProperty>>,
|
delete: Option<Vec<DeletableProperty>>,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
_param: Value,
|
_param: Value,
|
||||||
|
@ -240,13 +218,13 @@ pub fn update_changer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = path {
|
if let Some(path) = update.path {
|
||||||
let changers = linux_tape_changer_list();
|
let changers = linux_tape_changer_list();
|
||||||
check_drive_path(&changers, &path)?;
|
check_drive_path(&changers, &path)?;
|
||||||
data.path = path;
|
data.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(export_slots) = export_slots {
|
if let Some(export_slots) = update.export_slots {
|
||||||
let slots: Value = parse_property_string(
|
let slots: Value = parse_property_string(
|
||||||
&export_slots, &SLOT_ARRAY_SCHEMA
|
&export_slots, &SLOT_ARRAY_SCHEMA
|
||||||
)?;
|
)?;
|
||||||
|
|
Loading…
Reference in New Issue