]>
Commit | Line | Data |
---|---|---|
aff192e6 DM |
1 | package PVE::API2; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
8747a9ec | 6 | use PVE::pvecfg; |
3ac3653e | 7 | use PVE::DataCenterConfig; |
aff192e6 | 8 | use PVE::RESTHandler; |
3ed61033 | 9 | use PVE::JSONSchema; |
aff192e6 DM |
10 | |
11 | use base qw(PVE::RESTHandler); | |
12 | ||
13 | # preload classes | |
14 | use PVE::API2::Cluster; | |
15 | use PVE::API2::Nodes; | |
f16eb02d | 16 | use PVE::API2::Pool; |
aff192e6 DM |
17 | use PVE::API2::AccessControl; |
18 | use PVE::API2::Storage::Config; | |
19 | ||
20 | __PACKAGE__->register_method ({ | |
94d7d5ac | 21 | subclass => "PVE::API2::Cluster", |
aff192e6 DM |
22 | path => 'cluster', |
23 | }); | |
24 | ||
25 | __PACKAGE__->register_method ({ | |
94d7d5ac | 26 | subclass => "PVE::API2::Nodes", |
aff192e6 DM |
27 | path => 'nodes', |
28 | }); | |
29 | ||
30 | __PACKAGE__->register_method ({ | |
94d7d5ac | 31 | subclass => "PVE::API2::Storage::Config", |
aff192e6 DM |
32 | path => 'storage', |
33 | }); | |
34 | ||
35 | __PACKAGE__->register_method ({ | |
94d7d5ac | 36 | subclass => "PVE::API2::AccessControl", |
aff192e6 DM |
37 | path => 'access', |
38 | }); | |
39 | ||
f16eb02d | 40 | __PACKAGE__->register_method ({ |
94d7d5ac | 41 | subclass => "PVE::API2::Pool", |
f16eb02d DM |
42 | path => 'pools', |
43 | }); | |
44 | ||
aff192e6 | 45 | __PACKAGE__->register_method ({ |
94d7d5ac | 46 | name => 'index', |
aff192e6 DM |
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 { | |
94d7d5ac TL |
66 | my ($param) = @_; |
67 | ||
8747a9ec | 68 | my $res = [ { subdir => 'version' } ]; |
aff192e6 DM |
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 | ||
8747a9ec | 83 | __PACKAGE__->register_method ({ |
94d7d5ac | 84 | name => 'version', |
8747a9ec DM |
85 | path => 'version', |
86 | method => 'GET', | |
87 | permissions => { user => 'all' }, | |
b2eec1b6 | 88 | description => "API version details, including some parts of the global datacenter config.", |
8747a9ec DM |
89 | parameters => { |
90 | additionalProperties => 0, | |
91 | properties => {}, | |
92 | }, | |
93 | returns => { | |
94 | type => "object", | |
95 | properties => { | |
96 | version => { type => 'string' }, | |
97 | release => { type => 'string' }, | |
98 | repoid => { type => 'string' }, | |
99 | }, | |
100 | }, | |
101 | code => sub { | |
94d7d5ac TL |
102 | my ($param) = @_; |
103 | ||
b2eec1b6 | 104 | my $res = {}; |
2d802f8c | 105 | |
b2eec1b6 TL |
106 | my $datacenter_confg = eval { PVE::Cluster::cfs_read_file('datacenter.cfg') } // {}; |
107 | for my $k (qw(console)) { | |
108 | $res->{$k} = $datacenter_confg->{$k} if exists $datacenter_confg->{$k}; | |
2d802f8c | 109 | } |
94d7d5ac | 110 | |
b2eec1b6 TL |
111 | my $version_info = PVE::pvecfg::version_info(); |
112 | # force set all version keys independent of their definedness | |
113 | $res->{$_} = $version_info->{$_} for qw(version release repoid); | |
114 | ||
2d802f8c | 115 | return $res; |
8747a9ec | 116 | }}); |
3ed61033 | 117 | |
aff192e6 | 118 | 1; |