public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH 1/2 proxmox-backup] add additional_info field to APTUpdateInfo
@ 2020-11-10 12:33 Mira Limbeck
  2020-11-10 12:33 ` [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager Mira Limbeck
  0 siblings, 1 reply; 3+ messages in thread
From: Mira Limbeck @ 2020-11-10 12:33 UTC (permalink / raw)
  To: pbs-devel

Add an optional string field to APTUpdateInfo which can be used for
additional information.

This is used for passing running kernel and running version information
in the versions API call together with proxmox-backup and
proxmox-backup-server.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
 src/api2/node/apt.rs  | 35 ++++++++++++++++++++++++++++-------
 src/api2/types/mod.rs |  2 ++
 src/tools/apt.rs      |  1 +
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index aa41d6a5..fcc29bc6 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -276,7 +276,7 @@ pub fn get_versions() -> Result<Value, Error> {
         "zfsutils-linux",
     ];
 
-    fn unknown_package(package: String) -> APTUpdateInfo {
+    fn unknown_package(package: String, additional_info: Option<String>) -> APTUpdateInfo {
         APTUpdateInfo {
             package,
             title: "unknown".into(),
@@ -288,6 +288,7 @@ pub fn get_versions() -> Result<Value, Error> {
             priority: "unknown".into(),
             section: "unknown".into(),
             change_log_url: "unknown".into(),
+            additional_info,
         }
     }
 
@@ -301,14 +302,34 @@ pub fn get_versions() -> Result<Value, Error> {
         },
         None,
     );
-    if let Some(proxmox_backup) = pbs_packages.iter().find(|pkg| pkg.package == "proxmox-backup") {
-        packages.push(proxmox_backup.to_owned());
+
+    let running_kernel = nix::sys::utsname::uname().release().to_owned();
+    if let Some(proxmox_backup) = pbs_packages
+        .iter()
+        .find(|pkg| pkg.package == "proxmox-backup")
+    {
+        let mut proxmox_backup = proxmox_backup.clone();
+        proxmox_backup.additional_info = Some(running_kernel);
+        packages.push(proxmox_backup);
     } else {
-        packages.push(unknown_package("proxmox-backup".into()));
+        packages.push(unknown_package(
+            "proxmox-backup".into(),
+            Some(running_kernel),
+        ));
     }
 
-    if let Some(pkg) = pbs_packages.iter().find(|pkg| pkg.package == "proxmox-backup-server") {
-        packages.push(pkg.to_owned());
+    if let Some(pkg) = pbs_packages
+        .iter()
+        .find(|pkg| pkg.package == "proxmox-backup-server")
+    {
+        let running_version = format!(
+            "{}.{}",
+            crate::api2::version::PROXMOX_PKG_VERSION,
+            crate::api2::version::PROXMOX_PKG_RELEASE
+        );
+        let mut pkg = pkg.clone();
+        pkg.additional_info = Some(running_version);
+        packages.push(pkg);
     }
 
     let mut kernel_pkgs: Vec<APTUpdateInfo> = pbs_packages
@@ -334,7 +355,7 @@ pub fn get_versions() -> Result<Value, Error> {
         }
         match pbs_packages.iter().find(|item| &item.package == pkg) {
             Some(apt_pkg) => packages.push(apt_pkg.to_owned()),
-            None => packages.push(unknown_package(pkg.to_string())),
+            None => packages.push(unknown_package(pkg.to_string(), None)),
         }
     }
 
diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs
index ba9d2da9..03e3ea91 100644
--- a/src/api2/types/mod.rs
+++ b/src/api2/types/mod.rs
@@ -1177,6 +1177,8 @@ pub struct APTUpdateInfo {
     pub section: String,
     /// URL under which the package's changelog can be retrieved
     pub change_log_url: String,
+    /// Additional package information
+    pub additional_info: Option<String>,
 }
 
 #[api()]
diff --git a/src/tools/apt.rs b/src/tools/apt.rs
index 841b7447..30b9bcbe 100644
--- a/src/tools/apt.rs
+++ b/src/tools/apt.rs
@@ -361,6 +361,7 @@ where
                 },
                 priority: priority_res,
                 section: section_res,
+                additional_info: None,
             });
         }
     }
-- 
2.20.1





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager
  2020-11-10 12:33 [pbs-devel] [PATCH 1/2 proxmox-backup] add additional_info field to APTUpdateInfo Mira Limbeck
@ 2020-11-10 12:33 ` Mira Limbeck
  2020-11-10 12:37   ` Mira Limbeck
  0 siblings, 1 reply; 3+ messages in thread
From: Mira Limbeck @ 2020-11-10 12:33 UTC (permalink / raw)
  To: pbs-devel

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>
---
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<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 {
+            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![
     //  ("<command>", vec![<arg [, arg]>])
+        ("proxmox-backup-manager", vec!["versions", "--verbose"]),
         ("df", vec!["-h"]),
         ("lsblk", vec!["--ascii"]),
         ("zpool", vec!["status"]),
-- 
2.20.1





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager
  2020-11-10 12:33 ` [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager Mira Limbeck
@ 2020-11-10 12:37   ` Mira Limbeck
  0 siblings, 0 replies; 3+ messages in thread
From: Mira Limbeck @ 2020-11-10 12:37 UTC (permalink / raw)
  To: pbs-devel

This currently prints 'unknown' instead of 'not correctly installed'. 
Will send a v2 with this fixed.

On 11/10/20 1:33 PM, Mira Limbeck wrote:
> 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>
> ---
> 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<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 {
> +            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![
>       //  ("<command>", vec![<arg [, arg]>])
> +        ("proxmox-backup-manager", vec!["versions", "--verbose"]),
>           ("df", vec!["-h"]),
>           ("lsblk", vec!["--ascii"]),
>           ("zpool", vec!["status"]),




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-10 12:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 12:33 [pbs-devel] [PATCH 1/2 proxmox-backup] add additional_info field to APTUpdateInfo Mira Limbeck
2020-11-10 12:33 ` [pbs-devel] [PATCH 2/2 proxmox-backup] add versions command to proxmox-backup-manager Mira Limbeck
2020-11-10 12:37   ` Mira Limbeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal