2011-08-23 07:40:22 +02:00
package PVE::API2 ;
use strict ;
use warnings ;
2011-12-20 07:04:39 +01:00
use PVE::pvecfg ;
2019-11-11 11:28:34 +01:00
use PVE::DataCenterConfig ;
2011-08-23 07:40:22 +02:00
use PVE::RESTHandler ;
2014-04-30 15:28:30 +02:00
use PVE::JSONSchema ;
2011-08-23 07:40:22 +02:00
use base qw( PVE::RESTHandler ) ;
# preload classes
use PVE::API2::Cluster ;
use PVE::API2::Nodes ;
2012-01-27 08:39:46 +01:00
use PVE::API2::Pool ;
2011-08-23 07:40:22 +02:00
use PVE::API2::AccessControl ;
use PVE::API2::Storage::Config ;
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
subclass = > "PVE::API2::Cluster" ,
2011-08-23 07:40:22 +02:00
path = > 'cluster' ,
} ) ;
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
subclass = > "PVE::API2::Nodes" ,
2011-08-23 07:40:22 +02:00
path = > 'nodes' ,
} ) ;
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
subclass = > "PVE::API2::Storage::Config" ,
2011-08-23 07:40:22 +02:00
path = > 'storage' ,
} ) ;
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
subclass = > "PVE::API2::AccessControl" ,
2011-08-23 07:40:22 +02:00
path = > 'access' ,
} ) ;
2012-01-27 08:39:46 +01:00
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
subclass = > "PVE::API2::Pool" ,
2012-01-27 08:39:46 +01:00
path = > 'pools' ,
} ) ;
2011-08-23 07:40:22 +02:00
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
name = > 'index' ,
2011-08-23 07:40:22 +02:00
path = > '' ,
method = > 'GET' ,
permissions = > { user = > 'all' } ,
description = > "Directory index." ,
parameters = > {
additionalProperties = > 0 ,
properties = > { } ,
} ,
returns = > {
type = > 'array' ,
items = > {
type = > "object" ,
properties = > {
subdir = > { type = > 'string' } ,
} ,
} ,
links = > [ { rel = > 'child' , href = > "{subdir}" } ] ,
} ,
code = > sub {
2019-08-22 14:07:45 +02:00
my ( $ param ) = @ _ ;
2011-12-20 07:04:39 +01:00
my $ res = [ { subdir = > 'version' } ] ;
2011-08-23 07:40:22 +02:00
my $ ma = PVE::API2 - > method_attributes ( ) ;
foreach my $ info ( @$ ma ) {
next if ! $ info - > { subclass } ;
my $ subpath = $ info - > { match_re } - > [ 0 ] ;
push @$ res , { subdir = > $ subpath } ;
}
return $ res ;
} } ) ;
2011-12-20 07:04:39 +01:00
__PACKAGE__ - > register_method ( {
2019-08-22 14:07:45 +02:00
name = > 'version' ,
2011-12-20 07:04:39 +01:00
path = > 'version' ,
method = > 'GET' ,
permissions = > { user = > 'all' } ,
2021-11-10 17:26:48 +01:00
description = > "API version details, including some parts of the global datacenter config." ,
2011-12-20 07:04:39 +01:00
parameters = > {
additionalProperties = > 0 ,
properties = > { } ,
} ,
returns = > {
type = > "object" ,
properties = > {
2021-11-10 17:34:39 +01:00
version = > {
type = > 'string' ,
description = > 'The full pve-manager package version of this node.' ,
} ,
release = > {
type = > 'string' ,
description = > 'The current Proxmox VE point release in `x.y` format.' ,
} ,
repoid = > {
type = > 'string' ,
description = > 'The short git revision from which this version was build.' ,
} ,
console = > {
type = > 'string' ,
enum = > [ 'applet' , 'vv' , 'html5' , 'xtermjs' ] ,
optional = > 1 ,
description = > 'The default console viewer to use.' ,
} ,
2011-12-20 07:04:39 +01:00
} ,
} ,
code = > sub {
2019-08-22 14:07:45 +02:00
my ( $ param ) = @ _ ;
2021-11-10 17:26:48 +01:00
my $ res = { } ;
2013-12-10 07:33:09 +01:00
2021-11-10 17:26:48 +01:00
my $ datacenter_confg = eval { PVE::Cluster:: cfs_read_file ( 'datacenter.cfg' ) } // { } ;
for my $ k ( qw( console ) ) {
$ res - > { $ k } = $ datacenter_confg - > { $ k } if exists $ datacenter_confg - > { $ k } ;
2013-12-10 07:33:09 +01:00
}
2019-08-22 14:07:45 +02:00
2021-11-10 17:26:48 +01:00
my $ version_info = PVE::pvecfg:: version_info ( ) ;
# force set all version keys independent of their definedness
$ res - > { $ _ } = $ version_info - > { $ _ } for qw( version release repoid ) ;
2013-12-10 07:33:09 +01:00
return $ res ;
2011-12-20 07:04:39 +01:00
} } ) ;
2014-04-30 15:28:30 +02:00
2011-08-23 07:40:22 +02:00
1 ;