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