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