Commit 8c1d3a4e authored by Dietmar Maurer's avatar Dietmar Maurer

add/use API for pveversion

We want to be able to diplay that information on the GUI.
parent abc4a675
......@@ -2,12 +2,15 @@ package PVE::API2::APT;
use strict;
use warnings;
use POSIX;
use File::stat ();
use IO::File;
use File::Basename;
use LWP::UserAgent;
use PVE::pvecfg;
use PVE::Tools qw(extract_param);
use PVE::Cluster;
use PVE::SafeSyslog;
......@@ -60,8 +63,9 @@ __PACKAGE__->register_method({
my ($param) = @_;
my $res = [
{ id => 'update' },
{ id => 'changelog' },
{ id => 'update' },
{ id => 'versions' },
];
return $res;
......@@ -378,4 +382,81 @@ __PACKAGE__->register_method({
return $data;
}});
__PACKAGE__->register_method({
name => 'versions',
path => 'versions',
method => 'GET',
description => "Get package information for important Proxmox packages.",
permissions => {
check => ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
},
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
},
},
returns => {
type => "array",
items => {
type => "object",
properties => {},
},
},
code => sub {
my ($param) = @_;
my $pkgname = $param->{name};
my $cache = &$get_apt_cache();
my $policy = $cache->policy;
my $pkgrecords = $cache->packages();
# try to use a resonable ordering (most important things first)
my @list = qw(proxmox-ve-2.6.32 pve-manager);
foreach my $pkgname (keys %$cache) {
if ($pkgname =~ m/pve-kernel-/) {
my $p = $cache->{$pkgname};
push @list, $pkgname if $p && $p->{CurrentState} eq 'Installed';
}
}
push @list, qw(lvm2 clvm corosync-pve openais-pve libqb0 redhat-cluster-pve resource-agents-pve fence-agents-pve pve-cluster qemu-server pve-firmware libpve-common-perl libpve-access-control libpve-storage-perl vncterm vzctl vzprocps vzquota pve-qemu-kvm ksm-control-daemon);
my $pkglist = [];
my (undef, undef, $kernel_release) = POSIX::uname();
my $pvever = PVE::pvecfg::version_text();
foreach my $pkgname (@list) {
my $p = $cache->{$pkgname};
my $info = $pkgrecords->lookup($pkgname);
my $candidate_ver = $policy->candidate($p);
my $res;
if (my $current_ver = $p->{CurrentVer}) {
$res = &$assemble_pkginfo($pkgname, $info, $current_ver,
$candidate_ver || $current_ver);
} elsif ($candidate_ver) {
$res = &$assemble_pkginfo($pkgname, $info, $candidate_ver,
$candidate_ver);
delete $res->{OldVersion};
} else {
next;
}
$res->{CurrentState} = $p->{CurrentState};
# hack: add some useful information (used by 'pveversion -v')
if ($pkgname eq 'pve-manager') {
$res->{ManagerVersion} = $pvever;
} elsif ($pkgname eq 'proxmox-ve-2.6.32') {
$res->{RunningKernel} = $kernel_release;
}
push @$pkglist, $res;
}
return $pkglist;
}});
1;
#!/usr/bin/perl -w
use strict;
use POSIX;
use Getopt::Long;
use PVE::pvecfg;
use PVE::API2::APT;
sub read_pkglist {
my $pkglist = {};
open (TMP, "dpkg-query --show -f '\${PACKAGE} \${VERSION} \${STATUS}\n'|") ||
die "cant exec dpkg-query\n";
while (defined (my $line = <TMP>)) {
if ($line =~ m/^(\S+)\s+(\S+)\s+install\s+ok\s+installed$/) {
my ($pkg, $version) = ($1, $2);
$pkglist->{$pkg} = $version;
}
}
return $pkglist;
my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'});
my $pkglist = {};
foreach my $pkg (@$pkgarray) {
$pkglist->{$pkg->{Package}} = $pkg;
}
my $pkglist = read_pkglist();
sub print_status {
my ($pkg, $repoid) = @_;
my ($pkg) = @_;
my $pkginfo = $pkglist->{$pkg};
if (!$pkginfo) {
print "$pkg: unknown package - internal error\n";
return;
}
my $version = "not correctly installed";
if ($pkglist->{$pkg}) {
$version = $pkglist->{$pkg};
if ($pkginfo->{OldVersion} && $pkginfo->{CurrentState} eq 'Installed') {
$version = $pkginfo->{OldVersion};
}
if ($repoid) {
print "$pkg: $version ($repoid)\n";
if ($pkginfo->{RunningKernel}) {
print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n";
} elsif ($pkginfo->{ManagerVersion}) {
print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n";
} else {
print "$pkg: $version\n";
}
......@@ -58,49 +54,17 @@ if (scalar (@ARGV) != 0) {
exit (-1);
}
my $ver = PVE::pvecfg::package();
$ver .= '/';
$ver .= PVE::pvecfg::version();
$ver .= '/';
$ver .= PVE::pvecfg::repoid();
my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
my (undef, undef, $kver) = POSIX::uname();
my $kver = `uname -r`;
chomp $kver;
if (!$opt_verbose) {
print "$ver\n";
print "$ver (running kernel: $kver)\n";
exit (0);
}
print_status ("pve-manager", $ver);
print "running kernel: $kver\n";
my @list = qw(lvm2 clvm corosync-pve openais-pve libqb0 redhat-cluster-pve resource-agents-pve fence-agents-pve pve-cluster qemu-server pve-firmware libpve-common-perl libpve-access-control libpve-storage-perl vncterm vzctl vzprocps vzquota);
my $pkg = 'proxmox-ve-2.6.18';
if (my $v = $pkglist->{$pkg}) {
print "$pkg: $v\n";
push @list, 'pve-qemu-kvm-2.6.18';
}
$pkg = 'proxmox-ve-2.6.24';
if (my $v = $pkglist->{$pkg}) {
print "$pkg: $v\n";
push @list, 'pve-qemu-kvm';
}
$pkg = 'proxmox-ve-2.6.32';
if (my $v = $pkglist->{$pkg}) {
print "$pkg: $v\n";
push @list, 'pve-qemu-kvm';
push @list, 'ksm-control-daemon';
}
foreach $pkg (grep { m/^pve-kernel-/ } keys %$pkglist) {
print "$pkg: $pkglist->{$pkg}\n";
}
foreach my $p (@list) {
print_status ($p);
foreach my $pkg (@$pkgarray) {
print_status($pkg->{Package});
}
exit 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment