add API for apt using libapt-pkg-perl
This commit is contained in:
parent
5e63899bf6
commit
21299915de
140
PVE/API2/APT.pm
Normal file
140
PVE/API2/APT.pm
Normal file
@ -0,0 +1,140 @@
|
||||
package PVE::API2::APT;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use PVE::Tools qw(extract_param);
|
||||
use PVE::SafeSyslog;
|
||||
use PVE::INotify;
|
||||
use PVE::Exception qw(raise_param_exc);
|
||||
use PVE::RESTHandler;
|
||||
use PVE::RPCEnvironment;
|
||||
|
||||
use PVE::JSONSchema qw(get_standard_option);
|
||||
|
||||
use AptPkg::Cache;
|
||||
use AptPkg::Version;
|
||||
use AptPkg::PkgRecords;
|
||||
|
||||
my $apt_cache;
|
||||
|
||||
my $get_apt_cache = sub {
|
||||
|
||||
return $apt_cache if $apt_cache;
|
||||
|
||||
$apt_cache = AptPkg::Cache->new() || die "unable to initialize AptPkg::Cache\n";
|
||||
|
||||
return $apt_cache;
|
||||
};
|
||||
|
||||
use base qw(PVE::RESTHandler);
|
||||
|
||||
__PACKAGE__->register_method({
|
||||
name => 'index',
|
||||
path => '',
|
||||
method => 'GET',
|
||||
description => "Directory index for apt (Advanced Package Tool).",
|
||||
permissions => {
|
||||
user => 'all',
|
||||
},
|
||||
parameters => {
|
||||
additionalProperties => 0,
|
||||
properties => {
|
||||
node => get_standard_option('pve-node'),
|
||||
},
|
||||
},
|
||||
returns => {
|
||||
type => "array",
|
||||
items => {
|
||||
type => "object",
|
||||
properties => {
|
||||
id => { type => 'string' },
|
||||
},
|
||||
},
|
||||
links => [ { rel => 'child', href => "{id}" } ],
|
||||
},
|
||||
code => sub {
|
||||
my ($param) = @_;
|
||||
|
||||
my $res = [
|
||||
{ id => 'update' },
|
||||
{ id => 'upgrade' },
|
||||
{ id => 'changelog' },
|
||||
];
|
||||
|
||||
return $res;
|
||||
}});
|
||||
|
||||
my $assemble_pkginfo = sub {
|
||||
my ($pkgname, $info, $current_ver, $candidate_ver) = @_;
|
||||
|
||||
my $data = {
|
||||
Package => $info->{Name},
|
||||
Title => $info->{ShortDesc},
|
||||
};
|
||||
|
||||
if (my $desc = $info->{LongDesc}) {
|
||||
$desc =~ s/^.*\n\s?//; # remove first line
|
||||
$desc =~ s/\n / /g;
|
||||
$data->{Description} = $desc;
|
||||
}
|
||||
|
||||
foreach my $k (qw(Section Arch Priority)) {
|
||||
$data->{$k} = $candidate_ver->{$k};
|
||||
}
|
||||
|
||||
$data->{Version} = $candidate_ver->{VerStr};
|
||||
$data->{OldVersion} = $current_ver->{VerStr};
|
||||
|
||||
return $data;
|
||||
};
|
||||
|
||||
__PACKAGE__->register_method({
|
||||
name => 'list_updates',
|
||||
path => 'update',
|
||||
method => 'GET',
|
||||
description => "List available updates.",
|
||||
permissions => {
|
||||
check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
|
||||
},
|
||||
protected => 1,
|
||||
proxyto => 'node',
|
||||
parameters => {
|
||||
additionalProperties => 0,
|
||||
properties => {
|
||||
node => get_standard_option('pve-node'),
|
||||
},
|
||||
},
|
||||
returns => {
|
||||
type => "array",
|
||||
items => {
|
||||
type => "object",
|
||||
properties => {},
|
||||
},
|
||||
},
|
||||
code => sub {
|
||||
my ($param) = @_;
|
||||
|
||||
my $pkglist = [];
|
||||
|
||||
my $cache = &$get_apt_cache();
|
||||
my $policy = $cache->policy;
|
||||
my $pkgrecords = $cache->packages();
|
||||
|
||||
foreach my $pkgname (keys %$cache) {
|
||||
my $p = $cache->{$pkgname};
|
||||
next if $p->{SelectedState} ne 'Install';
|
||||
my $current_ver = $p->{CurrentVer};
|
||||
my $candidate_ver = $policy->candidate($p);
|
||||
|
||||
if ($current_ver->{VerStr} ne $candidate_ver->{VerStr}) {
|
||||
my $info = $pkgrecords->lookup($pkgname);
|
||||
my $res = &$assemble_pkginfo($pkgname, $info, $current_ver, $candidate_ver);
|
||||
push @$pkglist, $res;
|
||||
}
|
||||
}
|
||||
|
||||
return $pkglist;
|
||||
}});
|
||||
|
||||
1;
|
@ -1,6 +1,7 @@
|
||||
include ../../defines.mk
|
||||
|
||||
PERLSOURCE = \
|
||||
APT.pm \
|
||||
Subscription.pm \
|
||||
VZDump.pm \
|
||||
Backup.pm \
|
||||
|
@ -29,6 +29,7 @@ use PVE::API2::Storage::Status;
|
||||
use PVE::API2::Qemu;
|
||||
use PVE::API2::OpenVZ;
|
||||
use PVE::API2::VZDump;
|
||||
use PVE::API2::APT;
|
||||
use JSON;
|
||||
|
||||
use base qw(PVE::RESTHandler);
|
||||
@ -78,6 +79,11 @@ __PACKAGE__->register_method ({
|
||||
path => 'storage',
|
||||
});
|
||||
|
||||
__PACKAGE__->register_method ({
|
||||
subclass => "PVE::API2::APT",
|
||||
path => 'apt',
|
||||
});
|
||||
|
||||
__PACKAGE__->register_method ({
|
||||
name => 'index',
|
||||
path => '',
|
||||
@ -102,6 +108,7 @@ __PACKAGE__->register_method ({
|
||||
my ($param) = @_;
|
||||
|
||||
my $result = [
|
||||
{ name => 'apt' },
|
||||
{ name => 'version' },
|
||||
{ name => 'syslog' },
|
||||
{ name => 'bootlog' },
|
||||
|
2
debian/control.in
vendored
2
debian/control.in
vendored
@ -3,7 +3,7 @@ Version: @VERSION@-@PACKAGERELEASE@
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Depends: perl5, libtimedate-perl, libauthen-pam-perl, libintl-perl, rsync, libjson-perl, liblockfile-simple-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl (>= 6.04-1), libnet-http-perl (>= 6.06-1), libhttp-daemon-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, netcat-traditional, pve-cluster (>= 1.0-29), libpve-common-perl, libpve-storage-perl, libterm-readline-gnu-perl, libpve-access-control (>= 3.0-2), libio-socket-ssl-perl, libfilesys-df-perl, libfile-readbackwards-perl, libfile-sync-perl, redhat-cluster-pve, resource-agents-pve, fence-agents-pve, cstream, postfix | mail-transport-agent, libxml-parser-perl, lzop, dtach, libanyevent-perl, libio-compress-perl, liburi-perl, logrotate, libanyevent-http-perl, apt-transport-https
|
||||
Depends: perl5, libtimedate-perl, libauthen-pam-perl, libintl-perl, rsync, libjson-perl, liblockfile-simple-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl (>= 6.04-1), libnet-http-perl (>= 6.06-1), libhttp-daemon-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, netcat-traditional, pve-cluster (>= 1.0-29), libpve-common-perl, libpve-storage-perl, libterm-readline-gnu-perl, libpve-access-control (>= 3.0-2), libio-socket-ssl-perl, libfilesys-df-perl, libfile-readbackwards-perl, libfile-sync-perl, redhat-cluster-pve, resource-agents-pve, fence-agents-pve, cstream, postfix | mail-transport-agent, libxml-parser-perl, lzop, dtach, libanyevent-perl, libio-compress-perl, liburi-perl, logrotate, libanyevent-http-perl, apt-transport-https, libapt-pkg-perl
|
||||
Conflicts: netcat-openbsd, vzdump
|
||||
Replaces: vzdump
|
||||
Provides: vzdump
|
||||
|
Loading…
x
Reference in New Issue
Block a user