From: Mira Limbeck <m.limbeck@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 proxmox-backup 2/2] add versions command to proxmox-backup-manager
Date: Tue, 10 Nov 2020 14:22:18 +0100 [thread overview]
Message-ID: <20201110132218.17717-2-m.limbeck@proxmox.com> (raw)
In-Reply-To: <20201110132218.17717-1-m.limbeck@proxmox.com>
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 <m.limbeck@proxmox.com>
---
v2:
- removed the special casing for running kernel and running version
as the get_versions result already contains the complete string
- fixed version string to print 'not correctly installed' instead of
'unknown' if no old_version is available
src/bin/proxmox-backup-manager.rs | 78 +++++++++++++++++++++++++++++++
src/server/report.rs | 1 +
2 files changed, 79 insertions(+)
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index e52c2f76..60af205f 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -363,6 +363,81 @@ async fn report() -> Result<Value, Error> {
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<Value, Error> {
+ 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<APTUpdateInfo> = serde_json::from_value(packages)?;
+ for pkg in packages {
+ let mut version = "not correctly installed";
+ if !pkg.old_version.is_empty() && &pkg.old_version != "unknown" {
+ version = &pkg.old_version;
+ }
+
+ if let Some(extra_info) = pkg.extra_info {
+ println!(
+ "{}: {} ({})",
+ pkg.package,
+ version,
+ extra_info
+ );
+ } else {
+ println!(
+ "{}: {}",
+ pkg.package,
+ version,
+ );
+ }
+ }
+ }
+
+ Ok(Value::Null)
+}
+
fn main() {
proxmox_backup::tools::setup_safe_path_env();
@@ -396,6 +471,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![
// ("<command>", vec![<arg [, arg]>])
+ ("proxmox-backup-manager", vec!["versions", "--verbose"]),
("df", vec!["-h"]),
("lsblk", vec!["--ascii"]),
("zpool", vec!["status"]),
--
2.20.1
next prev parent reply other threads:[~2020-11-10 13:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 13:22 [pbs-devel] [PATCH v2 proxmox-backup 1/2] add extra_info field to APTUpdateInfo Mira Limbeck
2020-11-10 13:22 ` Mira Limbeck [this message]
2020-11-11 17:38 ` [pbs-devel] applied: [PATCH v2 proxmox-backup 2/2] add versions command to proxmox-backup-manager Thomas Lamprecht
2020-11-12 9:12 ` [pbs-devel] [PATCH proxmox-backup] apt: use typed response for get_versions Stefan Reiter
2020-11-12 9:18 ` [pbs-devel] applied: " Thomas Lamprecht
[not found] ` <c16a8594-0f66-eadb-1063-d6309187a4e5@proxmox.com>
2020-11-12 9:29 ` [pbs-devel] applied: [PATCH v2 proxmox-backup 2/2] add versions command to proxmox-backup-manager Thomas Lamprecht
2020-11-11 11:59 ` [pbs-devel] [PATCH v2 proxmox-backup 1/2] add extra_info field to APTUpdateInfo Mira Limbeck
2020-11-11 17:33 ` [pbs-devel] applied: " Thomas Lamprecht
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=20201110132218.17717-2-m.limbeck@proxmox.com \
--to=m.limbeck@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.