]> git.proxmox.com Git - pve-manager.git/blame - PVE/API2.pm
api2: dust off root API module a little bit
[pve-manager.git] / PVE / API2.pm
CommitLineData
aff192e6
DM
1package PVE::API2;
2
3use strict;
4use warnings;
5
8747a9ec 6use PVE::pvecfg;
aff192e6 7use PVE::RESTHandler;
3ed61033 8use PVE::JSONSchema;
aff192e6
DM
9
10use base qw(PVE::RESTHandler);
11
12# preload classes
13use PVE::API2::Cluster;
14use PVE::API2::Nodes;
f16eb02d 15use PVE::API2::Pool;
aff192e6
DM
16use PVE::API2::AccessControl;
17use PVE::API2::Storage::Config;
18
19__PACKAGE__->register_method ({
94d7d5ac 20 subclass => "PVE::API2::Cluster",
aff192e6
DM
21 path => 'cluster',
22});
23
24__PACKAGE__->register_method ({
94d7d5ac 25 subclass => "PVE::API2::Nodes",
aff192e6
DM
26 path => 'nodes',
27});
28
29__PACKAGE__->register_method ({
94d7d5ac 30 subclass => "PVE::API2::Storage::Config",
aff192e6
DM
31 path => 'storage',
32});
33
34__PACKAGE__->register_method ({
94d7d5ac 35 subclass => "PVE::API2::AccessControl",
aff192e6
DM
36 path => 'access',
37});
38
f16eb02d 39__PACKAGE__->register_method ({
94d7d5ac 40 subclass => "PVE::API2::Pool",
f16eb02d
DM
41 path => 'pools',
42});
43
aff192e6 44__PACKAGE__->register_method ({
94d7d5ac 45 name => 'index',
aff192e6
DM
46 path => '',
47 method => 'GET',
48 permissions => { user => 'all' },
49 description => "Directory index.",
50 parameters => {
51 additionalProperties => 0,
52 properties => {},
53 },
54 returns => {
55 type => 'array',
56 items => {
57 type => "object",
58 properties => {
59 subdir => { type => 'string' },
60 },
61 },
62 links => [ { rel => 'child', href => "{subdir}" } ],
63 },
64 code => sub {
94d7d5ac
TL
65 my ($param) = @_;
66
8747a9ec 67 my $res = [ { subdir => 'version' } ];
aff192e6
DM
68
69 my $ma = PVE::API2->method_attributes();
70
71 foreach my $info (@$ma) {
72 next if !$info->{subclass};
73
74 my $subpath = $info->{match_re}->[0];
75
76 push @$res, { subdir => $subpath };
77 }
78
79 return $res;
80 }});
81
8747a9ec 82__PACKAGE__->register_method ({
94d7d5ac 83 name => 'version',
8747a9ec
DM
84 path => 'version',
85 method => 'GET',
86 permissions => { user => 'all' },
2d802f8c 87 description => "API version details. The result also includes the global datacenter confguration.",
8747a9ec
DM
88 parameters => {
89 additionalProperties => 0,
90 properties => {},
91 },
92 returns => {
93 type => "object",
94 properties => {
95 version => { type => 'string' },
96 release => { type => 'string' },
97 repoid => { type => 'string' },
98 },
99 },
100 code => sub {
94d7d5ac
TL
101 my ($param) = @_;
102
2d802f8c
DM
103 my $res = PVE::Cluster::cfs_read_file('datacenter.cfg');
104
105 my $vi = PVE::pvecfg::version_info();
106 foreach my $k (qw(version release repoid)) {
107 $res->{$k} = $vi->{$k};
108 }
94d7d5ac 109
2d802f8c 110 return $res;
8747a9ec 111 }});
3ed61033 112
aff192e6 1131;