]> git.proxmox.com Git - pve-manager.git/blob - PVE/API2.pm
update shipped appliance info index
[pve-manager.git] / PVE / API2.pm
1 package PVE::API2;
2
3 use strict;
4 use warnings;
5
6 use PVE::pvecfg;
7 use PVE::DataCenterConfig;
8 use PVE::GuestHelpers;
9 use PVE::RESTHandler;
10 use PVE::JSONSchema;
11
12 use base qw(PVE::RESTHandler);
13
14 # preload classes
15 use PVE::API2::Cluster;
16 use PVE::API2::Nodes;
17 use PVE::API2::Pool;
18 use PVE::API2::AccessControl;
19 use PVE::API2::Storage::Config;
20
21 __PACKAGE__->register_method ({
22 subclass => "PVE::API2::Cluster",
23 path => 'cluster',
24 });
25
26 __PACKAGE__->register_method ({
27 subclass => "PVE::API2::Nodes",
28 path => 'nodes',
29 });
30
31 __PACKAGE__->register_method ({
32 subclass => "PVE::API2::Storage::Config",
33 path => 'storage',
34 });
35
36 __PACKAGE__->register_method ({
37 subclass => "PVE::API2::AccessControl",
38 path => 'access',
39 });
40
41 __PACKAGE__->register_method ({
42 subclass => "PVE::API2::Pool",
43 path => 'pools',
44 });
45
46 __PACKAGE__->register_method ({
47 name => 'index',
48 path => '',
49 method => 'GET',
50 permissions => { user => 'all' },
51 description => "Directory index.",
52 parameters => {
53 additionalProperties => 0,
54 properties => {},
55 },
56 returns => {
57 type => 'array',
58 items => {
59 type => "object",
60 properties => {
61 subdir => { type => 'string' },
62 },
63 },
64 links => [ { rel => 'child', href => "{subdir}" } ],
65 },
66 code => sub {
67 my ($param) = @_;
68
69 my $res = [ { subdir => 'version' } ];
70
71 my $ma = PVE::API2->method_attributes();
72
73 foreach my $info (@$ma) {
74 next if !$info->{subclass};
75
76 my $subpath = $info->{match_re}->[0];
77
78 push @$res, { subdir => $subpath };
79 }
80
81 return $res;
82 }});
83
84 __PACKAGE__->register_method ({
85 name => 'version',
86 path => 'version',
87 method => 'GET',
88 permissions => { user => 'all' },
89 description => "API version details, including some parts of the global datacenter config.",
90 parameters => {
91 additionalProperties => 0,
92 properties => {},
93 },
94 returns => {
95 type => "object",
96 properties => {
97 version => {
98 type => 'string',
99 description => 'The full pve-manager package version of this node.',
100 },
101 release => {
102 type => 'string',
103 description => 'The current Proxmox VE point release in `x.y` format.',
104 },
105 repoid => {
106 type => 'string',
107 # length 8 is old (< 8.0) short-id, 16 is new short id, 40 is sha1 and 64 is sha256
108 pattern => '[0-9a-fA-F]{8,64}',
109 description => 'The short git revision from which this version was build.',
110 },
111 console => {
112 type => 'string',
113 enum => ['applet', 'vv', 'html5', 'xtermjs'],
114 optional => 1,
115 description => 'The default console viewer to use.',
116 },
117 },
118 },
119 code => sub {
120 my ($param) = @_;
121
122 my $res = {};
123
124 # TODO remove with next major release
125 my $datacenter_confg = eval { PVE::Cluster::cfs_read_file('datacenter.cfg') } // {};
126 for my $k (qw(console)) {
127 $res->{$k} = $datacenter_confg->{$k} if exists $datacenter_confg->{$k};
128 }
129
130 my $version_info = PVE::pvecfg::version_info();
131 # force set all version keys independent of their definedness
132 $res->{$_} = $version_info->{$_} for qw(version release repoid);
133
134 return $res;
135 }});
136 1;