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 967A867B4E for ; Tue, 10 Nov 2020 13:34:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8AA62208B4 for ; Tue, 10 Nov 2020 13:34:00 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 60FD1208AB for ; Tue, 10 Nov 2020 13:33:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2ED3246067 for ; Tue, 10 Nov 2020 13:33:59 +0100 (CET) From: Mira Limbeck To: pbs-devel@lists.proxmox.com Date: Tue, 10 Nov 2020 13:33:54 +0100 Message-Id: <20201110123354.32590-2-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110123354.32590-1-m.limbeck@proxmox.com> References: <20201110123354.32590-1-m.limbeck@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.227 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an 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. [proxmox-backup-manager.rs] Subject: [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager 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: Tue, 10 Nov 2020 12:34:30 -0000 Add the versions command to proxmox-backup-manager with a similar output to pveversion [-v]. It prints the packages line by line with only the package name, followed by the version and, for proxmox-backup and proxmox-backup-server, some additional information (running kernel, running version). In addition it supports the optional output-format parameter which can be used to print the complete data in either json, json-pretty or text format. If output-format is specified, the --verbose parameter is ignored and the detailed list of packages is printed. With the addition of the versions command, the report is extended as well. Signed-off-by: Mira Limbeck --- When using --output-format text the table requires a wide terminal to look correct, otherwise the output is garbled and does not look like a table. src/bin/proxmox-backup-manager.rs | 76 +++++++++++++++++++++++++++++++ src/server/report.rs | 1 + 2 files changed, 77 insertions(+) diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index e52c2f76..7a165a38 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -363,6 +363,79 @@ async fn report() -> Result { Ok(Value::Null) } +#[api( + input: { + properties: { + verbose: { + type: Boolean, + optional: true, + default: false, + description: "Output verbose package information. It is ignored if output-format is specified.", + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + } + } + } +)] +/// List package versions for important Proxmox Backup Server packages. +async fn get_versions(verbose: bool, param: Value) -> Result { + let output_format = param.get("output-format"); + + if !verbose && output_format.is_none() { + let pkg_version = format!( + "{}.{}", + crate::api2::version::PROXMOX_PKG_VERSION, + crate::api2::version::PROXMOX_PKG_RELEASE + ); + let running_kernel = nix::sys::utsname::uname().release().to_owned(); + + println!( + "proxmox-backup-server/{} (running kernel: {})", + pkg_version, running_kernel + ); + return Ok(Value::Null); + } + + let mut packages = crate::api2::node::apt::get_versions()?; + if let Some(output_format) = output_format { + if let Some(output_format) = output_format.as_str() { + let options = TableFormatOptions::default(); + format_and_print_result_full( + &mut packages, + &crate::api2::node::apt::API_RETURN_SCHEMA_GET_VERSIONS, + output_format, + &options, + ); + } + } else { + // pveversion style print + let packages: Vec = serde_json::from_value(packages)?; + for pkg in packages { + if &pkg.package == "proxmox-backup" { + println!( + "{}: {} (running kernel: {})", + pkg.package, + pkg.old_version, + pkg.additional_info.unwrap() // always set in get_versions() + ); + } else if &pkg.package == "proxmox-backup-server" { + println!( + "{}: {} (running version: {})", + pkg.package, + pkg.old_version, + pkg.additional_info.unwrap() // always set in get_versions() + ); + } else { + println!("{}: {}", pkg.package, pkg.old_version); + } + } + } + + Ok(Value::Null) +} + fn main() { proxmox_backup::tools::setup_safe_path_env(); @@ -396,6 +469,9 @@ fn main() { ) .insert("report", CliCommand::new(&API_METHOD_REPORT) + ) + .insert("versions", + CliCommand::new(&API_METHOD_GET_VERSIONS) ); diff --git a/src/server/report.rs b/src/server/report.rs index 9c6e2406..22e16a14 100644 --- a/src/server/report.rs +++ b/src/server/report.rs @@ -20,6 +20,7 @@ fn files() -> Vec<&'static str> { fn commands() -> Vec<(&'static str, Vec<&'static str>)> { vec![ // ("", vec![]) + ("proxmox-backup-manager", vec!["versions", "--verbose"]), ("df", vec!["-h"]), ("lsblk", vec!["--ascii"]), ("zpool", vec!["status"]), -- 2.20.1