add extra_info field to APTUpdateInfo

Add an optional string field to APTUpdateInfo which can be used for
extra 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>
This commit is contained in:
Mira Limbeck 2020-11-10 14:22:17 +01:00 committed by Thomas Lamprecht
parent 1d8f849457
commit 2decf85d6e
3 changed files with 31 additions and 7 deletions

View File

@ -276,7 +276,7 @@ pub fn get_versions() -> Result<Value, Error> {
"zfsutils-linux", "zfsutils-linux",
]; ];
fn unknown_package(package: String) -> APTUpdateInfo { fn unknown_package(package: String, extra_info: Option<String>) -> APTUpdateInfo {
APTUpdateInfo { APTUpdateInfo {
package, package,
title: "unknown".into(), title: "unknown".into(),
@ -288,6 +288,7 @@ pub fn get_versions() -> Result<Value, Error> {
priority: "unknown".into(), priority: "unknown".into(),
section: "unknown".into(), section: "unknown".into(),
change_log_url: "unknown".into(), change_log_url: "unknown".into(),
extra_info,
} }
} }
@ -301,14 +302,34 @@ pub fn get_versions() -> Result<Value, Error> {
}, },
None, 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.extra_info = Some(format!("running kernel: {}", running_kernel));
packages.push(proxmox_backup);
} else { } 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") { if let Some(pkg) = pbs_packages
packages.push(pkg.to_owned()); .iter()
.find(|pkg| pkg.package == "proxmox-backup-server")
{
let running_version = format!(
"running version: {}.{}",
crate::api2::version::PROXMOX_PKG_VERSION,
crate::api2::version::PROXMOX_PKG_RELEASE
);
let mut pkg = pkg.clone();
pkg.extra_info = Some(running_version);
packages.push(pkg);
} }
let mut kernel_pkgs: Vec<APTUpdateInfo> = pbs_packages 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) { match pbs_packages.iter().find(|item| &item.package == pkg) {
Some(apt_pkg) => packages.push(apt_pkg.to_owned()), 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)),
} }
} }

View File

@ -1177,6 +1177,8 @@ pub struct APTUpdateInfo {
pub section: String, pub section: String,
/// URL under which the package's changelog can be retrieved /// URL under which the package's changelog can be retrieved
pub change_log_url: String, pub change_log_url: String,
/// Additional package information
pub extra_info: Option<String>,
} }
#[api()] #[api()]

View File

@ -361,6 +361,7 @@ where
}, },
priority: priority_res, priority: priority_res,
section: section_res, section: section_res,
extra_info: None,
}); });
} }
} }