all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/4] tape: compute next-media-label for each tape backup job
Date: Wed,  4 Aug 2021 10:10:48 +0200	[thread overview]
Message-ID: <20210804081050.497395-2-dietmar@proxmox.com> (raw)
In-Reply-To: <20210804081050.497395-1-dietmar@proxmox.com>

---
 src/api2/tape/backup.rs | 28 +++++++++++++++++++++++++---
 src/config/tape_job.rs  |  3 +++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index 8119482f..9f815cad 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -126,9 +126,11 @@ pub fn list_tape_backup_jobs(
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
     let user_info = CachedUserInfo::new()?;
 
-    let (config, digest) = config::tape_job::config()?;
+    let (job_config, digest) = config::tape_job::config()?;
+    let (pool_config, _pool_digest) = config::media_pool::config()?;
+    let (drive_config, _digest) = config::drive::config()?;
 
-    let job_list_iter = config
+    let job_list_iter = job_config
         .convert_to_typed_array("backup")?
         .into_iter()
         .filter(|_job: &TapeBackupJobConfig| {
@@ -137,6 +139,8 @@ pub fn list_tape_backup_jobs(
         });
 
     let mut list = Vec::new();
+    let status_path = Path::new(TAPE_STATUS_DIR);
+    let current_time = proxmox::tools::time::epoch_i64();
 
     for job in job_list_iter {
         let privs = user_info.lookup_privs(&auth_id, &["tape", "job", &job.id]);
@@ -149,7 +153,25 @@ pub fn list_tape_backup_jobs(
 
         let status = compute_schedule_status(&last_state, job.schedule.as_deref())?;
 
-        list.push(TapeBackupJobStatus { config: job, status });
+        let next_run = status.next_run.unwrap_or(current_time);
+
+        let mut next_media_label = None;
+
+        if let Ok(pool) = pool_config.lookup::<MediaPoolConfig>("pool", &job.setup.pool) {
+            let mut changer_name = None;
+            if let Ok(Some((_, name))) = media_changer(&drive_config, &job.setup.drive) {
+                changer_name = Some(name);
+            }
+            if let Ok(mut pool) = MediaPool::with_config(status_path, &pool, changer_name, true) {
+                if pool.start_write_session(next_run, false).is_ok() {
+                    if let Ok(media_id) = pool.guess_next_writable_media(next_run) {
+                        next_media_label = Some(media_id.label.label_text);
+                    }
+                }
+            }
+        }
+
+        list.push(TapeBackupJobStatus { config: job, status, next_media_label });
     }
 
     rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
diff --git a/src/config/tape_job.rs b/src/config/tape_job.rs
index f09200fc..3c265b93 100644
--- a/src/config/tape_job.rs
+++ b/src/config/tape_job.rs
@@ -127,6 +127,9 @@ pub struct TapeBackupJobStatus {
     pub config: TapeBackupJobConfig,
     #[serde(flatten)]
     pub status: JobScheduleStatus,
+    /// Next tape used (best guess)
+    #[serde(skip_serializing_if="Option::is_none")]
+    pub next_media_label: Option<String>,
 }
 
 fn init() -> SectionConfig {
-- 
2.30.2





  reply	other threads:[~2021-08-04  8:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04  8:10 [pbs-devel] [PATCH proxmox-backup 1/4] tape: media_pool: implement guess_next_writable_media() Dietmar Maurer
2021-08-04  8:10 ` Dietmar Maurer [this message]
2021-08-04  8:10 ` [pbs-devel] [PATCH proxmox-backup 3/4] cli: proxmox-tape backup-job list: use status api and display next-run an d next-media-label Dietmar Maurer
2021-08-04  8:10 ` [pbs-devel] [PATCH proxmox-backup 4/4] ui: display next-media-label for tape backup jobs Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210804081050.497395-2-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal