]>
Commit | Line | Data |
---|---|---|
1 | package PVE::API2::Storage::Status; | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::Cluster qw(cfs_read_file); | |
7 | use PVE::Storage; | |
8 | use PVE::API2::Storage::Content; | |
9 | use PVE::RESTHandler; | |
10 | use PVE::RPCEnvironment; | |
11 | use PVE::JSONSchema qw(get_standard_option); | |
12 | use PVE::Exception qw(raise_param_exc); | |
13 | ||
14 | use base qw(PVE::RESTHandler); | |
15 | ||
16 | ||
17 | __PACKAGE__->register_method ({ | |
18 | subclass => "PVE::API2::Storage::Content", | |
19 | # set fragment delimiter (no subdirs) - we need that, because volume | |
20 | # IDs may contain a slash '/' | |
21 | fragmentDelimiter => '', | |
22 | path => '{storage}/content', | |
23 | }); | |
24 | ||
25 | __PACKAGE__->register_method ({ | |
26 | name => 'index', | |
27 | path => '', | |
28 | method => 'GET', | |
29 | description => "Get status for all datastores.", | |
30 | protected => 1, | |
31 | proxyto => 'node', | |
32 | parameters => { | |
33 | additionalProperties => 0, | |
34 | properties => { | |
35 | node => get_standard_option('pve-node'), | |
36 | storage => get_standard_option | |
37 | ('pve-storage-id', { | |
38 | description => "Only list status for specified storage", | |
39 | optional => 1, | |
40 | }), | |
41 | content => { | |
42 | description => "Only list stores which support this content type.", | |
43 | type => 'string', format => 'pve-storage-content', | |
44 | optional => 1, | |
45 | }, | |
46 | }, | |
47 | }, | |
48 | returns => { | |
49 | type => 'array', | |
50 | items => { | |
51 | type => "object", | |
52 | properties => { storage => { type => 'string' } }, | |
53 | }, | |
54 | links => [ { rel => 'child', href => "{storage}" } ], | |
55 | }, | |
56 | code => sub { | |
57 | my ($param) = @_; | |
58 | ||
59 | my $cfg = cfs_read_file("storage.cfg"); | |
60 | ||
61 | my $info = PVE::Storage::storage_info($cfg, $param->{content}); | |
62 | ||
63 | if ($param->{storage}) { | |
64 | my $data = $info->{$param->{storage}}; | |
65 | ||
66 | raise_param_exc({ storage => "No such storage." }) | |
67 | if !defined($data); | |
68 | ||
69 | $data->{storage} = $param->{storage}; | |
70 | ||
71 | return [ $data ]; | |
72 | } | |
73 | return PVE::RESTHandler::hash_to_array($info, 'storage'); | |
74 | }}); | |
75 | ||
76 | __PACKAGE__->register_method ({ | |
77 | name => 'diridx', | |
78 | path => '{storage}', | |
79 | method => 'GET', | |
80 | description => "", | |
81 | parameters => { | |
82 | additionalProperties => 0, | |
83 | properties => { | |
84 | node => get_standard_option('pve-node'), | |
85 | storage => get_standard_option('pve-storage-id'), | |
86 | }, | |
87 | }, | |
88 | returns => { | |
89 | type => 'array', | |
90 | items => { | |
91 | type => "object", | |
92 | properties => { | |
93 | subdir => { type => 'string' }, | |
94 | }, | |
95 | }, | |
96 | links => [ { rel => 'child', href => "{subdir}" } ], | |
97 | }, | |
98 | code => sub { | |
99 | my ($param) = @_; | |
100 | ||
101 | my $res = [ | |
102 | { subdir => 'status' }, | |
103 | { subdir => 'content' }, | |
104 | { subdir => 'rrd' }, | |
105 | { subdir => 'rrddata' }, | |
106 | ]; | |
107 | ||
108 | return $res; | |
109 | }}); | |
110 | ||
111 | __PACKAGE__->register_method ({ | |
112 | name => 'read_status', | |
113 | path => '{storage}/status', | |
114 | method => 'GET', | |
115 | description => "Read storage status.", | |
116 | protected => 1, | |
117 | proxyto => 'node', | |
118 | parameters => { | |
119 | additionalProperties => 0, | |
120 | properties => { | |
121 | node => get_standard_option('pve-node'), | |
122 | storage => get_standard_option('pve-storage-id'), | |
123 | }, | |
124 | }, | |
125 | returns => { | |
126 | type => "object", | |
127 | properties => {}, | |
128 | }, | |
129 | code => sub { | |
130 | my ($param) = @_; | |
131 | ||
132 | my $cfg = cfs_read_file("storage.cfg"); | |
133 | ||
134 | my $info = PVE::Storage::storage_info($cfg, $param->{content}); | |
135 | ||
136 | my $data = $info->{$param->{storage}}; | |
137 | ||
138 | raise_param_exc({ storage => "No such storage." }) | |
139 | if !defined($data); | |
140 | ||
141 | return $data; | |
142 | }}); | |
143 | ||
144 | __PACKAGE__->register_method ({ | |
145 | name => 'rrd', | |
146 | path => '{storage}/rrd', | |
147 | method => 'GET', | |
148 | description => "Read storage RRD statistics (returns PNG).", | |
149 | protected => 1, | |
150 | proxyto => 'node', | |
151 | parameters => { | |
152 | additionalProperties => 0, | |
153 | properties => { | |
154 | node => get_standard_option('pve-node'), | |
155 | storage => get_standard_option('pve-storage-id'), | |
156 | timeframe => { | |
157 | description => "Specify the time frame you are interested in.", | |
158 | type => 'string', | |
159 | enum => [ 'hour', 'day', 'week', 'month', 'year' ], | |
160 | }, | |
161 | ds => { | |
162 | description => "The list of datasources you want to display.", | |
163 | type => 'string', format => 'pve-configid-list', | |
164 | }, | |
165 | cf => { | |
166 | description => "The RRD consolidation function", | |
167 | type => 'string', | |
168 | enum => [ 'AVERAGE', 'MAX' ], | |
169 | optional => 1, | |
170 | }, | |
171 | }, | |
172 | }, | |
173 | returns => { | |
174 | type => "object", | |
175 | properties => { | |
176 | filename => { type => 'string' }, | |
177 | }, | |
178 | }, | |
179 | code => sub { | |
180 | my ($param) = @_; | |
181 | ||
182 | return PVE::Cluster::create_rrd_graph( | |
183 | "pve2-storage/$param->{node}/$param->{storage}", | |
184 | $param->{timeframe}, $param->{ds}, $param->{cf}); | |
185 | ||
186 | }}); | |
187 | ||
188 | __PACKAGE__->register_method ({ | |
189 | name => 'rrddata', | |
190 | path => '{storage}/rrddata', | |
191 | method => 'GET', | |
192 | description => "Read storage RRD statistics.", | |
193 | protected => 1, | |
194 | proxyto => 'node', | |
195 | parameters => { | |
196 | additionalProperties => 0, | |
197 | properties => { | |
198 | node => get_standard_option('pve-node'), | |
199 | storage => get_standard_option('pve-storage-id'), | |
200 | timeframe => { | |
201 | description => "Specify the time frame you are interested in.", | |
202 | type => 'string', | |
203 | enum => [ 'hour', 'day', 'week', 'month', 'year' ], | |
204 | }, | |
205 | cf => { | |
206 | description => "The RRD consolidation function", | |
207 | type => 'string', | |
208 | enum => [ 'AVERAGE', 'MAX' ], | |
209 | optional => 1, | |
210 | }, | |
211 | }, | |
212 | }, | |
213 | returns => { | |
214 | type => "array", | |
215 | items => { | |
216 | type => "object", | |
217 | properties => {}, | |
218 | }, | |
219 | }, | |
220 | code => sub { | |
221 | my ($param) = @_; | |
222 | ||
223 | return PVE::Cluster::create_rrd_data( | |
224 | "pve2-storage/$param->{node}/$param->{storage}", | |
225 | $param->{timeframe}, $param->{cf}); | |
226 | }}); | |
227 | ||
228 | 1; |