add versions command to proxmox-backup-manager
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>
This commit is contained in:
parent
e754da3ac2
commit
c100fe9108
@ -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)
|
||||
);
|
||||
|
||||
|
||||
|
@ -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"]),
|
||||
|
Loading…
Reference in New Issue
Block a user