]>
Commit | Line | Data |
---|---|---|
2892b673 TL |
1 | package PVE::API2::Storage::Scan; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | # NOTE: This API endpoints are mounted by pve-manager's API2::Node module and pvesm CLI | |
7 | ||
8 | use PVE::JSONSchema qw(get_standard_option); | |
9 | use PVE::RESTHandler; | |
10 | use PVE::SafeSyslog; | |
11 | use PVE::Storage::LVMPlugin; | |
12 | use PVE::Storage; | |
13 | use PVE::SysFSTools; | |
14 | ||
15 | use base qw(PVE::RESTHandler); | |
16 | ||
b1ccf4f3 TL |
17 | __PACKAGE__->register_method({ |
18 | name => 'index', | |
19 | path => '', | |
20 | method => 'GET', | |
21 | description => "Index of available scan methods", | |
22 | permissions => { | |
23 | user => 'all', | |
24 | }, | |
25 | parameters => { | |
26 | additionalProperties => 0, | |
27 | properties => { | |
28 | node => get_standard_option('pve-node'), | |
29 | }, | |
30 | }, | |
31 | returns => { | |
32 | type => 'array', | |
33 | items => { | |
34 | type => "object", | |
35 | properties => { | |
36 | method => { type => 'string'}, | |
37 | }, | |
38 | }, | |
39 | links => [ { rel => 'child', href => "{method}" } ], | |
40 | }, | |
41 | code => sub { | |
42 | my ($param) = @_; | |
43 | ||
44 | my $res = [ | |
45 | { method => 'cifs' }, | |
46 | { method => 'glusterfs' }, | |
47 | { method => 'iscsi' }, | |
48 | { method => 'lvm' }, | |
49 | { method => 'nfs' }, | |
39fc0c77 | 50 | { method => 'pbs' }, |
b1ccf4f3 TL |
51 | { method => 'zfs' }, |
52 | ]; | |
53 | ||
54 | return $res; | |
55 | }}); | |
56 | ||
2892b673 TL |
57 | __PACKAGE__->register_method({ |
58 | name => 'nfsscan', | |
59 | path => 'nfs', | |
60 | method => 'GET', | |
61 | description => "Scan remote NFS server.", | |
62 | protected => 1, | |
63 | proxyto => "node", | |
64 | permissions => { | |
65 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
66 | }, | |
67 | parameters => { | |
68 | additionalProperties => 0, | |
69 | properties => { | |
70 | node => get_standard_option('pve-node'), | |
71 | server => { | |
72 | description => "The server address (name or IP).", | |
73 | type => 'string', format => 'pve-storage-server', | |
74 | }, | |
75 | }, | |
76 | }, | |
77 | returns => { | |
78 | type => 'array', | |
79 | items => { | |
80 | type => "object", | |
81 | properties => { | |
82 | path => { | |
83 | description => "The exported path.", | |
84 | type => 'string', | |
85 | }, | |
86 | options => { | |
87 | description => "NFS export options.", | |
88 | type => 'string', | |
89 | }, | |
90 | }, | |
91 | }, | |
92 | }, | |
93 | code => sub { | |
94 | my ($param) = @_; | |
95 | ||
96 | my $server = $param->{server}; | |
97 | my $res = PVE::Storage::scan_nfs($server); | |
98 | ||
99 | my $data = []; | |
100 | foreach my $k (sort keys %$res) { | |
101 | push @$data, { path => $k, options => $res->{$k} }; | |
102 | } | |
103 | return $data; | |
104 | }}); | |
105 | ||
106 | __PACKAGE__->register_method({ | |
107 | name => 'cifsscan', | |
108 | path => 'cifs', | |
109 | method => 'GET', | |
110 | description => "Scan remote CIFS server.", | |
111 | protected => 1, | |
112 | proxyto => "node", | |
113 | permissions => { | |
114 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
115 | }, | |
116 | parameters => { | |
117 | additionalProperties => 0, | |
118 | properties => { | |
119 | node => get_standard_option('pve-node'), | |
120 | server => { | |
121 | description => "The server address (name or IP).", | |
122 | type => 'string', format => 'pve-storage-server', | |
123 | }, | |
124 | username => { | |
125 | description => "User name.", | |
126 | type => 'string', | |
127 | optional => 1, | |
128 | }, | |
129 | password => { | |
130 | description => "User password.", | |
131 | type => 'string', | |
132 | optional => 1, | |
133 | }, | |
134 | domain => { | |
135 | description => "SMB domain (Workgroup).", | |
136 | type => 'string', | |
137 | optional => 1, | |
138 | }, | |
139 | }, | |
140 | }, | |
141 | returns => { | |
142 | type => 'array', | |
143 | items => { | |
144 | type => "object", | |
145 | properties => { | |
146 | share => { | |
147 | description => "The cifs share name.", | |
148 | type => 'string', | |
149 | }, | |
150 | description => { | |
151 | description => "Descriptive text from server.", | |
152 | type => 'string', | |
153 | }, | |
154 | }, | |
155 | }, | |
156 | }, | |
157 | code => sub { | |
158 | my ($param) = @_; | |
159 | ||
160 | my $server = $param->{server}; | |
161 | ||
162 | my $username = $param->{username}; | |
163 | my $password = $param->{password}; | |
164 | my $domain = $param->{domain}; | |
165 | ||
166 | my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain); | |
167 | ||
168 | my $data = []; | |
169 | foreach my $k (sort keys %$res) { | |
e65abdb4 | 170 | next if $k =~ m/NT_STATUS_/; |
2892b673 TL |
171 | push @$data, { share => $k, description => $res->{$k} }; |
172 | } | |
173 | ||
174 | return $data; | |
175 | }}); | |
176 | ||
39fc0c77 TL |
177 | __PACKAGE__->register_method({ |
178 | name => 'pbsscan', | |
179 | path => 'pbs', | |
180 | method => 'GET', | |
181 | description => "Scan remote Proxmox Backup Server.", | |
182 | protected => 1, | |
183 | proxyto => "node", | |
184 | permissions => { | |
185 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
186 | }, | |
187 | parameters => { | |
188 | additionalProperties => 0, | |
189 | properties => { | |
190 | node => get_standard_option('pve-node'), | |
191 | server => { | |
192 | description => "The server address (name or IP).", | |
193 | type => 'string', format => 'pve-storage-server', | |
194 | }, | |
195 | username => { | |
196 | description => "User-name or API token-ID.", | |
197 | type => 'string', | |
198 | }, | |
199 | password => { | |
200 | description => "User password or API token secret.", | |
201 | type => 'string', | |
202 | }, | |
203 | fingerprint => get_standard_option('fingerprint-sha256', { | |
204 | optional => 1, | |
205 | }), | |
206 | port => { | |
207 | description => "Optional port.", | |
208 | type => 'integer', | |
209 | minimum => 1, | |
210 | maximum => 65535, | |
211 | default => 8007, | |
212 | optional => 1, | |
213 | }, | |
214 | }, | |
215 | }, | |
216 | returns => { | |
217 | type => 'array', | |
218 | items => { | |
219 | type => "object", | |
220 | properties => { | |
221 | store => { | |
222 | description => "The datastore name.", | |
223 | type => 'string', | |
224 | }, | |
225 | comment => { | |
226 | description => "Comment from server.", | |
227 | type => 'string', | |
228 | optional => 1, | |
229 | }, | |
230 | }, | |
231 | }, | |
232 | }, | |
233 | code => sub { | |
234 | my ($param) = @_; | |
235 | ||
236 | my $password = delete $param->{password}; | |
237 | ||
238 | return PVE::Storage::PBSPlugin::scan_datastores($param, $password); | |
239 | } | |
240 | }); | |
241 | ||
2892b673 TL |
242 | # Note: GlusterFS currently does not have an equivalent of showmount. |
243 | # As workaround, we simply use nfs showmount. | |
244 | # see http://www.gluster.org/category/volumes/ | |
245 | __PACKAGE__->register_method({ | |
246 | name => 'glusterfsscan', | |
247 | path => 'glusterfs', | |
248 | method => 'GET', | |
249 | description => "Scan remote GlusterFS server.", | |
250 | protected => 1, | |
251 | proxyto => "node", | |
252 | permissions => { | |
253 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
254 | }, | |
255 | parameters => { | |
256 | additionalProperties => 0, | |
257 | properties => { | |
258 | node => get_standard_option('pve-node'), | |
259 | server => { | |
260 | description => "The server address (name or IP).", | |
261 | type => 'string', format => 'pve-storage-server', | |
262 | }, | |
263 | }, | |
264 | }, | |
265 | returns => { | |
266 | type => 'array', | |
267 | items => { | |
268 | type => "object", | |
269 | properties => { | |
270 | volname => { | |
271 | description => "The volume name.", | |
272 | type => 'string', | |
273 | }, | |
274 | }, | |
275 | }, | |
276 | }, | |
277 | code => sub { | |
278 | my ($param) = @_; | |
279 | ||
280 | my $server = $param->{server}; | |
281 | my $res = PVE::Storage::scan_nfs($server); | |
282 | ||
283 | my $data = []; | |
284 | foreach my $path (sort keys %$res) { | |
285 | if ($path =~ m!^/([^\s/]+)$!) { | |
286 | push @$data, { volname => $1 }; | |
287 | } | |
288 | } | |
289 | return $data; | |
290 | }}); | |
291 | ||
292 | __PACKAGE__->register_method({ | |
293 | name => 'iscsiscan', | |
294 | path => 'iscsi', | |
295 | method => 'GET', | |
296 | description => "Scan remote iSCSI server.", | |
297 | protected => 1, | |
298 | proxyto => "node", | |
299 | permissions => { | |
300 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
301 | }, | |
302 | parameters => { | |
303 | additionalProperties => 0, | |
304 | properties => { | |
305 | node => get_standard_option('pve-node'), | |
306 | portal => { | |
307 | description => "The iSCSI portal (IP or DNS name with optional port).", | |
308 | type => 'string', format => 'pve-storage-portal-dns', | |
309 | }, | |
310 | }, | |
311 | }, | |
312 | returns => { | |
313 | type => 'array', | |
314 | items => { | |
315 | type => "object", | |
316 | properties => { | |
317 | target => { | |
318 | description => "The iSCSI target name.", | |
319 | type => 'string', | |
320 | }, | |
321 | portal => { | |
322 | description => "The iSCSI portal name.", | |
323 | type => 'string', | |
324 | }, | |
325 | }, | |
326 | }, | |
327 | }, | |
328 | code => sub { | |
329 | my ($param) = @_; | |
330 | ||
331 | my $res = PVE::Storage::scan_iscsi($param->{portal}); | |
332 | ||
333 | my $data = []; | |
334 | foreach my $k (sort keys %$res) { | |
335 | push @$data, { target => $k, portal => join(',', @{$res->{$k}}) }; | |
336 | } | |
337 | ||
338 | return $data; | |
339 | }}); | |
340 | ||
341 | __PACKAGE__->register_method({ | |
342 | name => 'lvmscan', | |
343 | path => 'lvm', | |
344 | method => 'GET', | |
345 | description => "List local LVM volume groups.", | |
346 | protected => 1, | |
347 | proxyto => "node", | |
348 | permissions => { | |
349 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
350 | }, | |
351 | parameters => { | |
352 | additionalProperties => 0, | |
353 | properties => { | |
354 | node => get_standard_option('pve-node'), | |
355 | }, | |
356 | }, | |
357 | returns => { | |
358 | type => 'array', | |
359 | items => { | |
360 | type => "object", | |
361 | properties => { | |
362 | vg => { | |
363 | description => "The LVM logical volume group name.", | |
364 | type => 'string', | |
365 | }, | |
366 | }, | |
367 | }, | |
368 | }, | |
369 | code => sub { | |
370 | my ($param) = @_; | |
371 | ||
372 | my $res = PVE::Storage::LVMPlugin::lvm_vgs(); | |
373 | return PVE::RESTHandler::hash_to_array($res, 'vg'); | |
374 | }}); | |
375 | ||
376 | __PACKAGE__->register_method({ | |
377 | name => 'lvmthinscan', | |
378 | path => 'lvmthin', | |
379 | method => 'GET', | |
380 | description => "List local LVM Thin Pools.", | |
381 | protected => 1, | |
382 | proxyto => "node", | |
383 | permissions => { | |
384 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
385 | }, | |
386 | parameters => { | |
387 | additionalProperties => 0, | |
388 | properties => { | |
389 | node => get_standard_option('pve-node'), | |
390 | vg => { | |
391 | type => 'string', | |
392 | pattern => '[a-zA-Z0-9\.\+\_][a-zA-Z0-9\.\+\_\-]+', # see lvm(8) manpage | |
393 | maxLength => 100, | |
394 | }, | |
395 | }, | |
396 | }, | |
397 | returns => { | |
398 | type => 'array', | |
399 | items => { | |
400 | type => "object", | |
401 | properties => { | |
402 | lv => { | |
403 | description => "The LVM Thin Pool name (LVM logical volume).", | |
404 | type => 'string', | |
405 | }, | |
406 | }, | |
407 | }, | |
408 | }, | |
409 | code => sub { | |
410 | my ($param) = @_; | |
411 | ||
412 | return PVE::Storage::LvmThinPlugin::list_thinpools($param->{vg}); | |
413 | }}); | |
414 | ||
415 | __PACKAGE__->register_method({ | |
416 | name => 'zfsscan', | |
417 | path => 'zfs', | |
418 | method => 'GET', | |
419 | description => "Scan zfs pool list on local node.", | |
420 | protected => 1, | |
421 | proxyto => "node", | |
422 | permissions => { | |
423 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
424 | }, | |
425 | parameters => { | |
426 | additionalProperties => 0, | |
427 | properties => { | |
428 | node => get_standard_option('pve-node'), | |
429 | }, | |
430 | }, | |
431 | returns => { | |
432 | type => 'array', | |
433 | items => { | |
434 | type => "object", | |
435 | properties => { | |
436 | pool => { | |
437 | description => "ZFS pool name.", | |
438 | type => 'string', | |
439 | }, | |
440 | }, | |
441 | }, | |
442 | }, | |
443 | code => sub { | |
444 | my ($param) = @_; | |
445 | ||
446 | return PVE::Storage::scan_zfs(); | |
447 | }}); | |
b1ccf4f3 | 448 | |
b1ccf4f3 | 449 | 1; |