Commit af05769e authored by Dietmar Maurer's avatar Dietmar Maurer

add API to query version info

Normaly all nodes should have the same version, so /api2/json/version is
good enough for most situations. But you can also query the version on
each node using /api2/json/nodes/{node}/version
parent c69fc44a
......@@ -4,6 +4,7 @@ use strict;
use warnings;
use Apache2::Const qw(:http);
use PVE::pvecfg;
use PVE::RESTHandler;
use base qw(PVE::RESTHandler);
......@@ -57,7 +58,7 @@ __PACKAGE__->register_method ({
code => sub {
my ($resp, $param) = @_;
my $res = [];
my $res = [ { subdir => 'version' } ];
my $ma = PVE::API2->method_attributes();
......@@ -72,4 +73,27 @@ __PACKAGE__->register_method ({
return $res;
}});
__PACKAGE__->register_method ({
name => 'version',
path => 'version',
method => 'GET',
permissions => { user => 'all' },
description => "API version details",
parameters => {
additionalProperties => 0,
properties => {},
},
returns => {
type => "object",
properties => {
version => { type => 'string' },
release => { type => 'string' },
repoid => { type => 'string' },
},
},
code => sub {
my ($resp, $param) = @_;
return PVE::pvecfg::version_info();
}});
1;
......@@ -92,6 +92,7 @@ __PACKAGE__->register_method ({
my ($param) = @_;
my $result = [
{ name => 'version' },
{ name => 'syslog' },
{ name => 'status' },
{ name => 'tasks' },
......@@ -115,6 +116,33 @@ __PACKAGE__->register_method ({
return $result;
}});
__PACKAGE__->register_method ({
name => 'version',
path => 'version',
method => 'GET',
proxyto => 'node',
permissions => { user => 'all' },
description => "API version details",
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
},
},
returns => {
type => "object",
properties => {
version => { type => 'string' },
release => { type => 'string' },
repoid => { type => 'string' },
},
},
code => sub {
my ($resp, $param) = @_;
return PVE::pvecfg::version_info();
}});
__PACKAGE__->register_method({
name => 'beancounters_failcnt',
path => 'ubcfailcnt',
......@@ -266,8 +294,7 @@ __PACKAGE__->register_method({
};
$res->{pveversion} = PVE::pvecfg::package() . "/" .
PVE::pvecfg::version() . "/" .
PVE::pvecfg::repoid();
PVE::pvecfg::version_text();
my $dinfo = df('/', 1); # output is bytes
......
......@@ -17,7 +17,7 @@ all: pvecfg.pm ${SUBDIRS}
REPOID=`../repoid.pl ../.git`
pvecfg.pm: pvecfg.pm.in
sed -e s/@VERSION@/${VERSION}/ -e s/@PACKAGE@/${PACKAGE}/ -e s/@REPOID@/${REPOID}/ $< >$@.tmp
sed -e s/@VERSION@/${VERSION}/ -e s/@PACKAGERELEASE@/${PACKAGERELEASE}/ -e s/@PACKAGE@/${PACKAGE}/ -e s/@REPOID@/${REPOID}/ $< >$@.tmp
mv $@.tmp $@
%:
......
......@@ -12,8 +12,26 @@ sub version {
return '@VERSION@';
}
sub release {
return '@PACKAGERELEASE@';
}
sub repoid {
return '@REPOID@';
}
# this is diplayed on the GUI
sub version_text {
return '@VERSION@-@PACKAGERELEASE@/@REPOID@';
}
# this is returned by the API
sub version_info {
return {
'version' => '@VERSION@',
'release' => '@PACKAGERELEASE@',
'repoid' => '@REPOID@',
}
}
1;
......@@ -42,7 +42,7 @@ if (my $cookie = $r->headers_in->{Cookie}) {
$token = PVE::AccessControl::assemble_csrf_prevention_token($username);
}
}
my $version = PVE::pvecfg::version() . "/" . PVE::pvecfg::repoid();
my $version = PVE::pvecfg::version_text();
$username = '' if !$username;
my $cgi = CGI->new($r);
......
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