From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1378B7AB1F for ; Mon, 10 May 2021 11:28:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0A5A5160C1 for ; Mon, 10 May 2021 11:28:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 55ED116086 for ; Mon, 10 May 2021 11:28:01 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2760345BC0 for ; Mon, 10 May 2021 11:28:01 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 10 May 2021 11:27:57 +0200 Message-Id: <20210510092800.17956-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210510092800.17956-1-d.csapak@proxmox.com> References: <20210510092800.17956-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v4 3/6] tape/inventory: add completion helper for tape snapshots X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 May 2021 09:28:33 -0000 Signed-off-by: Dominik Csapak --- src/tape/inventory.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs index f9654538..4bb6d4f8 100644 --- a/src/tape/inventory.rs +++ b/src/tape/inventory.rs @@ -54,6 +54,7 @@ use crate::{ tape::{ TAPE_STATUS_DIR, MediaSet, + MediaCatalog, file_formats::{ MediaLabel, MediaSetLabel, @@ -850,3 +851,38 @@ pub fn complete_media_label_text( inventory.map.values().map(|entry| entry.id.label.label_text.clone()).collect() } + +pub fn complete_media_set_snapshots(_arg: &str, param: &HashMap) -> Vec { + let media_set_uuid: Uuid = match param.get("media-set").and_then(|s| s.parse().ok()) { + Some(uuid) => uuid, + None => return Vec::new(), + }; + let status_path = Path::new(TAPE_STATUS_DIR); + let inventory = match Inventory::load(&status_path) { + Ok(inventory) => inventory, + Err(_) => return Vec::new(), + }; + + let mut res = Vec::new(); + let media_ids = inventory.list_used_media().into_iter().filter(|media| { + match &media.media_set_label { + Some(label) => label.uuid == media_set_uuid, + None => false, + } + }); + + for media_id in media_ids { + let catalog = match MediaCatalog::open(status_path, &media_id, false, false) { + Ok(catalog) => catalog, + Err(_) => continue, + }; + + for (store, content) in catalog.content() { + for snapshot in content.snapshot_index.keys() { + res.push(format!("{}:{}", store, snapshot)); + } + } + } + + res +} -- 2.20.1