tape: rename changer_id to label_text

This commit is contained in:
Dietmar Maurer
2021-01-13 13:26:59 +01:00
parent 9738dd545f
commit 8446fbca85
19 changed files with 171 additions and 171 deletions

View File

@ -5,18 +5,18 @@ use proxmox::tools::email::sendmail;
/// Send email to a person to request a manual media change
pub fn send_load_media_email(
drive: &str,
changer_id: &str,
label_text: &str,
to: &str,
) -> Result<(), Error> {
let subject = format!("Load Media '{}' request for drive '{}'", changer_id, drive);
let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive);
let mut text = String::new();
text.push_str("Please insert the requested media into the backup drive.\n\n");
text.push_str(&format!("Drive: {}\n", drive));
text.push_str(&format!("Media: {}\n", changer_id));
text.push_str(&format!("Media: {}\n", label_text));
sendmail(
&[to],

View File

@ -32,17 +32,17 @@ pub trait MediaChange {
/// Load media from storage slot into drive
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error>;
/// Load media by changer-id into drive
/// Load media by label-text into drive
///
/// This unloads first if the drive is already loaded with another media.
///
/// Note: This refuses to load media inside import/export
/// slots. Also, you cannot load cleaning units with this
/// interface.
fn load_media(&mut self, changer_id: &str) -> Result<(), Error> {
fn load_media(&mut self, label_text: &str) -> Result<(), Error> {
if changer_id.starts_with("CLN") {
bail!("unable to load media '{}' (seems top be a a cleaning units)", changer_id);
if label_text.starts_with("CLN") {
bail!("unable to load media '{}' (seems top be a a cleaning units)", label_text);
}
let mut status = self.status()?;
@ -52,10 +52,10 @@ pub trait MediaChange {
// already loaded?
for (i, drive_status) in status.drives.iter().enumerate() {
if let ElementStatus::VolumeTag(ref tag) = drive_status.status {
if *tag == changer_id {
if *tag == label_text {
if i as u64 != self.drive_number() {
bail!("unable to load media '{}' - media in wrong drive ({} != {})",
changer_id, i, self.drive_number());
label_text, i, self.drive_number());
}
return Ok(()) // already loaded
}
@ -76,9 +76,9 @@ pub trait MediaChange {
let mut slot = None;
for (i, (import_export, element_status)) in status.slots.iter().enumerate() {
if let ElementStatus::VolumeTag(tag) = element_status {
if *tag == changer_id {
if *tag == label_text {
if *import_export {
bail!("unable to load media '{}' - inside import/export slot", changer_id);
bail!("unable to load media '{}' - inside import/export slot", label_text);
}
slot = Some(i+1);
break;
@ -87,7 +87,7 @@ pub trait MediaChange {
}
let slot = match slot {
None => bail!("unable to find media '{}' (offline?)", changer_id),
None => bail!("unable to find media '{}' (offline?)", label_text),
Some(slot) => slot,
};
@ -97,11 +97,11 @@ pub trait MediaChange {
/// Unload media from drive (eject media if necessary)
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error>;
/// List online media changer IDs (barcodes)
/// List online media labels (label_text/barcodes)
///
/// List acessible (online) changer IDs. This does not include
/// List acessible (online) label texts. This does not include
/// media inside import-export slots or cleaning media.
fn online_media_changer_ids(&mut self) -> Result<Vec<String>, Error> {
fn online_media_label_texts(&mut self) -> Result<Vec<String>, Error> {
let status = self.status()?;
let mut list = Vec::new();
@ -166,13 +166,13 @@ pub trait MediaChange {
/// By moving the media to an empty import-export slot. Returns
/// Some(slot) if the media was exported. Returns None if the media is
/// not online (already exported).
fn export_media(&mut self, changer_id: &str) -> Result<Option<u64>, Error> {
fn export_media(&mut self, label_text: &str) -> Result<Option<u64>, Error> {
let status = self.status()?;
let mut unload_from_drive = false;
if let Some(drive_status) = status.drives.get(self.drive_number() as usize) {
if let ElementStatus::VolumeTag(ref tag) = drive_status.status {
if tag == changer_id {
if tag == label_text {
unload_from_drive = true;
}
}
@ -189,7 +189,7 @@ pub trait MediaChange {
}
} else {
if let ElementStatus::VolumeTag(ref tag) = element_status {
if tag == changer_id {
if tag == label_text {
from = Some(i as u64 + 1);
}
}

View File

@ -269,7 +269,7 @@ pub fn request_and_load_media(
if let Ok(Some(media_id)) = handle.read_label() {
worker.log(format!(
"found media label {} ({})",
media_id.label.changer_id,
media_id.label.label_text,
media_id.label.uuid.to_string(),
));
if media_id.label.uuid == *uuid {
@ -285,9 +285,9 @@ pub fn request_and_load_media(
"virtual" => {
let mut tape = VirtualTapeDrive::deserialize(config)?;
let changer_id = label.changer_id.clone();
let label_text = label.label_text.clone();
tape.load_media(&changer_id)?;
tape.load_media(&label_text)?;
let mut handle: Box<dyn TapeDriver> = Box::new(tape.open()?);
@ -298,12 +298,12 @@ pub fn request_and_load_media(
"linux" => {
let drive_config = LinuxTapeDrive::deserialize(config)?;
let changer_id = label.changer_id.clone();
let label_text = label.label_text.clone();
if drive_config.changer.is_some() {
let mut changer = MtxMediaChanger::with_drive_config(&drive_config)?;
changer.load_media(&changer_id)?;
changer.load_media(&label_text)?;
let mut handle: Box<dyn TapeDriver> = Box::new(drive_config.open()?);
@ -312,11 +312,11 @@ pub fn request_and_load_media(
return Ok((handle, media_id));
}
worker.log(format!("Please insert media '{}' into drive '{}'", changer_id, drive));
worker.log(format!("Please insert media '{}' into drive '{}'", label_text, drive));
let to = "root@localhost"; // fixme
send_load_media_email(drive, &changer_id, to)?;
send_load_media_email(drive, &label_text, to)?;
let mut last_media_uuid = None;
let mut last_error = None;
@ -340,7 +340,7 @@ pub fn request_and_load_media(
if media_id.label.uuid == label.uuid {
worker.log(format!(
"found media label {} ({})",
media_id.label.changer_id,
media_id.label.label_text,
media_id.label.uuid.to_string(),
));
return Ok((Box::new(handle), media_id));
@ -348,7 +348,7 @@ pub fn request_and_load_media(
if Some(media_id.label.uuid.clone()) != last_media_uuid {
worker.log(format!(
"wrong media label {} ({})",
media_id.label.changer_id,
media_id.label.label_text,
media_id.label.uuid.to_string(),
));
last_media_uuid = Some(media_id.label.uuid);

View File

@ -157,7 +157,7 @@ impl VirtualTapeHandle {
Ok(())
}
fn online_media_changer_ids(&self) -> Result<Vec<String>, Error> {
fn online_media_label_texts(&self) -> Result<Vec<String>, Error> {
let mut list = Vec::new();
for entry in std::fs::read_dir(&self.path)? {
let entry = entry?;
@ -389,12 +389,12 @@ impl MediaChange for VirtualTapeHandle {
// slot-assignment here.
let mut slots = Vec::new();
let changer_ids = self.online_media_changer_ids()?;
let max_slots = ((changer_ids.len() + 7)/8) * 8;
let label_texts = self.online_media_label_texts()?;
let max_slots = ((label_texts.len() + 7)/8) * 8;
for i in 0..max_slots {
if let Some(changer_id) = changer_ids.get(i) {
slots.push((false, ElementStatus::VolumeTag(changer_id.clone())));
if let Some(label_text) = label_texts.get(i) {
slots.push((false, ElementStatus::VolumeTag(label_text.clone())));
} else {
slots.push((false, ElementStatus::Empty));
}
@ -407,7 +407,7 @@ impl MediaChange for VirtualTapeHandle {
bail!("media tranfer is not implemented!");
}
fn export_media(&mut self, _changer_id: &str) -> Result<Option<u64>, Error> {
fn export_media(&mut self, _label_text: &str) -> Result<Option<u64>, Error> {
bail!("media export is not implemented!");
}
@ -416,13 +416,13 @@ impl MediaChange for VirtualTapeHandle {
bail!("invalid slot ID {}", slot);
}
let changer_ids = self.online_media_changer_ids()?;
let label_texts = self.online_media_label_texts()?;
if slot > changer_ids.len() as u64 {
if slot > label_texts.len() as u64 {
bail!("slot {} is empty", slot);
}
self.load_media(&changer_ids[slot as usize - 1])
self.load_media(&label_texts[slot as usize - 1])
}
/// Try to load media
@ -479,9 +479,9 @@ impl MediaChange for VirtualTapeDrive {
handle.transfer_media(from, to)
}
fn export_media(&mut self, changer_id: &str) -> Result<Option<u64>, Error> {
fn export_media(&mut self, label_text: &str) -> Result<Option<u64>, Error> {
let mut handle = self.open()?;
handle.export_media(changer_id)
handle.export_media(label_text)
}
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error> {
@ -489,9 +489,9 @@ impl MediaChange for VirtualTapeDrive {
handle.load_media_from_slot(slot)
}
fn load_media(&mut self, changer_id: &str) -> Result<(), Error> {
fn load_media(&mut self, label_text: &str) -> Result<(), Error> {
let mut handle = self.open()?;
handle.load_media(changer_id)
handle.load_media(label_text)
}
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error> {
@ -500,9 +500,9 @@ impl MediaChange for VirtualTapeDrive {
Ok(())
}
fn online_media_changer_ids(&mut self) -> Result<Vec<String>, Error> {
fn online_media_label_texts(&mut self) -> Result<Vec<String>, Error> {
let handle = self.open()?;
handle.online_media_changer_ids()
handle.online_media_label_texts()
}
fn clean_drive(&mut self) -> Result<(), Error> {

View File

@ -164,8 +164,8 @@ pub struct ChunkArchiveEntryHeader {
pub struct MediaLabel {
/// Unique ID
pub uuid: Uuid,
/// Media Changer ID or Barcode
pub changer_id: String,
/// Media label text (or Barcode)
pub label_text: String,
/// Creation time stamp
pub ctime: i64,
}

View File

@ -213,10 +213,10 @@ impl Inventory {
self.map.get(uuid).map(|entry| &entry.id)
}
/// find media by changer_id
pub fn find_media_by_changer_id(&self, changer_id: &str) -> Option<&MediaId> {
/// find media by label_text
pub fn find_media_by_label_text(&self, label_text: &str) -> Option<&MediaId> {
for (_uuid, entry) in &self.map {
if entry.id.label.changer_id == changer_id {
if entry.id.label.label_text == label_text {
return Some(&entry.id);
}
}
@ -534,10 +534,10 @@ impl Inventory {
// Helpers to simplify testing
/// Genreate and insert a new free tape (test helper)
pub fn generate_free_tape(&mut self, changer_id: &str, ctime: i64) -> Uuid {
pub fn generate_free_tape(&mut self, label_text: &str, ctime: i64) -> Uuid {
let label = MediaLabel {
changer_id: changer_id.to_string(),
label_text: label_text.to_string(),
uuid: Uuid::generate(),
ctime,
};
@ -552,13 +552,13 @@ impl Inventory {
/// (test helper)
pub fn generate_assigned_tape(
&mut self,
changer_id: &str,
label_text: &str,
pool: &str,
ctime: i64,
) -> Uuid {
let label = MediaLabel {
changer_id: changer_id.to_string(),
label_text: label_text.to_string(),
uuid: Uuid::generate(),
ctime,
};
@ -575,12 +575,12 @@ impl Inventory {
/// Genreate and insert a used tape (test helper)
pub fn generate_used_tape(
&mut self,
changer_id: &str,
label_text: &str,
set: MediaSetLabel,
ctime: i64,
) -> Uuid {
let label = MediaLabel {
changer_id: changer_id.to_string(),
label_text: label_text.to_string(),
uuid: Uuid::generate(),
ctime,
};
@ -735,7 +735,7 @@ pub fn complete_media_set_uuid(
}
/// List of known media labels (barcodes)
pub fn complete_media_changer_id(
pub fn complete_media_label_text(
_arg: &str,
_param: &HashMap<String, String>,
) -> Vec<String> {
@ -745,5 +745,5 @@ pub fn complete_media_changer_id(
Err(_) => return Vec::new(),
};
inventory.map.values().map(|entry| entry.id.label.changer_id.clone()).collect()
inventory.map.values().map(|entry| entry.id.label.label_text.clone()).collect()
}

View File

@ -317,7 +317,7 @@ impl MediaPool {
}
}
if self.media_is_expired(&media, current_time) {
println!("found expired media on media '{}'", media.changer_id());
println!("found expired media on media '{}'", media.label_text());
expired_media.push(media);
}
}
@ -335,7 +335,7 @@ impl MediaPool {
bail!("alloc writable media in pool '{}' failed: no usable media found", self.name());
}
Some(media) => {
println!("reuse expired media '{}'", media.changer_id());
println!("reuse expired media '{}'", media.label_text());
let seq_nr = self.current_media_set.media_list().len() as u64;
let set = MediaSetLabel::with_data(&pool, self.current_media_set.uuid().clone(), seq_nr, current_time);
@ -494,7 +494,7 @@ impl BackupMedia {
}
/// Returns the media label (Barcode)
pub fn changer_id(&self) -> &str {
&self.id.label.changer_id
pub fn label_text(&self) -> &str {
&self.id.label.label_text
}
}

View File

@ -99,8 +99,8 @@ pub fn mtx_status_to_online_set(status: &MtxStatus, inventory: &Inventory) -> Ha
let mut online_set = HashSet::new();
for drive_status in status.drives.iter() {
if let ElementStatus::VolumeTag(ref changer_id) = drive_status.status {
if let Some(media_id) = inventory.find_media_by_changer_id(changer_id) {
if let ElementStatus::VolumeTag(ref label_text) = drive_status.status {
if let Some(media_id) = inventory.find_media_by_label_text(label_text) {
online_set.insert(media_id.label.uuid.clone());
}
}
@ -108,8 +108,8 @@ pub fn mtx_status_to_online_set(status: &MtxStatus, inventory: &Inventory) -> Ha
for (import_export, slot_status) in status.slots.iter() {
if *import_export { continue; }
if let ElementStatus::VolumeTag(ref changer_id) = slot_status {
if let Some(media_id) = inventory.find_media_by_changer_id(changer_id) {
if let ElementStatus::VolumeTag(ref label_text) = slot_status {
if let Some(media_id) = inventory.find_media_by_label_text(label_text) {
online_set.insert(media_id.label.uuid.clone());
}
}
@ -146,7 +146,7 @@ pub fn update_online_status(state_path: &Path) -> Result<OnlineStatusMap, Error>
let vtapes: Vec<VirtualTapeDrive> = config.convert_to_typed_array("virtual")?;
for mut vtape in vtapes {
let media_list = match vtape.online_media_changer_ids() {
let media_list = match vtape.online_media_label_texts() {
Ok(media_list) => media_list,
Err(err) => {
eprintln!("unable to get changer '{}' status - {}", vtape.name, err);
@ -155,8 +155,8 @@ pub fn update_online_status(state_path: &Path) -> Result<OnlineStatusMap, Error>
};
let mut online_set = HashSet::new();
for changer_id in media_list {
if let Some(media_id) = inventory.find_media_by_changer_id(&changer_id) {
for label_text in media_list {
if let Some(media_id) = inventory.find_media_by_label_text(&label_text) {
online_set.insert(media_id.label.uuid.clone());
}
}
@ -173,13 +173,13 @@ pub fn update_changer_online_status(
drive_config: &SectionConfigData,
inventory: &mut Inventory,
changer_name: &str,
changer_id_list: &Vec<String>,
label_text_list: &Vec<String>,
) -> Result<(), Error> {
let mut online_map = OnlineStatusMap::new(drive_config)?;
let mut online_set = HashSet::new();
for changer_id in changer_id_list.iter() {
if let Some(media_id) = inventory.find_media_by_changer_id(&changer_id) {
for label_text in label_text_list.iter() {
if let Some(media_id) = inventory.find_media_by_label_text(&label_text) {
online_set.insert(media_id.label.uuid.clone());
}
}

View File

@ -150,11 +150,11 @@ impl PoolWriter {
for media_uuid in self.pool.current_media_list()? {
let media = self.pool.lookup_media(media_uuid)?;
let changer_id = media.changer_id();
if let Some(slot) = changer.export_media(changer_id)? {
worker.log(format!("exported media '{}' to import/export slot {}", changer_id, slot));
let label_text = media.label_text();
if let Some(slot) = changer.export_media(label_text)? {
worker.log(format!("exported media '{}' to import/export slot {}", label_text, slot));
} else {
worker.warn(format!("export failed - media '{}' is not online", changer_id));
worker.warn(format!("export failed - media '{}' is not online", label_text));
}
}