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 476DF7A077 for ; Thu, 6 May 2021 14:20:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4518C206A0 for ; Thu, 6 May 2021 14:20:10 +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 84CE620683 for ; Thu, 6 May 2021 14:20:09 +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 572A8464F5 for ; Thu, 6 May 2021 14:20:09 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 6 May 2021 14:20:05 +0200 Message-Id: <20210506122008.11297-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210506122008.11297-1-d.csapak@proxmox.com> References: <20210506122008.11297-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [inventory.rs] Subject: [pbs-devel] [PATCH proxmox-backup v3 4/7] 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: Thu, 06 May 2021 12:20:10 -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