]>
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 | ||
17 | __PACKAGE__->register_method({ | |
18 | name => 'nfsscan', | |
19 | path => 'nfs', | |
20 | method => 'GET', | |
21 | description => "Scan remote NFS server.", | |
22 | protected => 1, | |
23 | proxyto => "node", | |
24 | permissions => { | |
25 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
26 | }, | |
27 | parameters => { | |
28 | additionalProperties => 0, | |
29 | properties => { | |
30 | node => get_standard_option('pve-node'), | |
31 | server => { | |
32 | description => "The server address (name or IP).", | |
33 | type => 'string', format => 'pve-storage-server', | |
34 | }, | |
35 | }, | |
36 | }, | |
37 | returns => { | |
38 | type => 'array', | |
39 | items => { | |
40 | type => "object", | |
41 | properties => { | |
42 | path => { | |
43 | description => "The exported path.", | |
44 | type => 'string', | |
45 | }, | |
46 | options => { | |
47 | description => "NFS export options.", | |
48 | type => 'string', | |
49 | }, | |
50 | }, | |
51 | }, | |
52 | }, | |
53 | code => sub { | |
54 | my ($param) = @_; | |
55 | ||
56 | my $server = $param->{server}; | |
57 | my $res = PVE::Storage::scan_nfs($server); | |
58 | ||
59 | my $data = []; | |
60 | foreach my $k (sort keys %$res) { | |
61 | push @$data, { path => $k, options => $res->{$k} }; | |
62 | } | |
63 | return $data; | |
64 | }}); | |
65 | ||
66 | __PACKAGE__->register_method({ | |
67 | name => 'cifsscan', | |
68 | path => 'cifs', | |
69 | method => 'GET', | |
70 | description => "Scan remote CIFS server.", | |
71 | protected => 1, | |
72 | proxyto => "node", | |
73 | permissions => { | |
74 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
75 | }, | |
76 | parameters => { | |
77 | additionalProperties => 0, | |
78 | properties => { | |
79 | node => get_standard_option('pve-node'), | |
80 | server => { | |
81 | description => "The server address (name or IP).", | |
82 | type => 'string', format => 'pve-storage-server', | |
83 | }, | |
84 | username => { | |
85 | description => "User name.", | |
86 | type => 'string', | |
87 | optional => 1, | |
88 | }, | |
89 | password => { | |
90 | description => "User password.", | |
91 | type => 'string', | |
92 | optional => 1, | |
93 | }, | |
94 | domain => { | |
95 | description => "SMB domain (Workgroup).", | |
96 | type => 'string', | |
97 | optional => 1, | |
98 | }, | |
99 | }, | |
100 | }, | |
101 | returns => { | |
102 | type => 'array', | |
103 | items => { | |
104 | type => "object", | |
105 | properties => { | |
106 | share => { | |
107 | description => "The cifs share name.", | |
108 | type => 'string', | |
109 | }, | |
110 | description => { | |
111 | description => "Descriptive text from server.", | |
112 | type => 'string', | |
113 | }, | |
114 | }, | |
115 | }, | |
116 | }, | |
117 | code => sub { | |
118 | my ($param) = @_; | |
119 | ||
120 | my $server = $param->{server}; | |
121 | ||
122 | my $username = $param->{username}; | |
123 | my $password = $param->{password}; | |
124 | my $domain = $param->{domain}; | |
125 | ||
126 | my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain); | |
127 | ||
128 | my $data = []; | |
129 | foreach my $k (sort keys %$res) { | |
e65abdb4 | 130 | next if $k =~ m/NT_STATUS_/; |
2892b673 TL |
131 | push @$data, { share => $k, description => $res->{$k} }; |
132 | } | |
133 | ||
134 | return $data; | |
135 | }}); | |
136 | ||
137 | # Note: GlusterFS currently does not have an equivalent of showmount. | |
138 | # As workaround, we simply use nfs showmount. | |
139 | # see http://www.gluster.org/category/volumes/ | |
140 | __PACKAGE__->register_method({ | |
141 | name => 'glusterfsscan', | |
142 | path => 'glusterfs', | |
143 | method => 'GET', | |
144 | description => "Scan remote GlusterFS server.", | |
145 | protected => 1, | |
146 | proxyto => "node", | |
147 | permissions => { | |
148 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
149 | }, | |
150 | parameters => { | |
151 | additionalProperties => 0, | |
152 | properties => { | |
153 | node => get_standard_option('pve-node'), | |
154 | server => { | |
155 | description => "The server address (name or IP).", | |
156 | type => 'string', format => 'pve-storage-server', | |
157 | }, | |
158 | }, | |
159 | }, | |
160 | returns => { | |
161 | type => 'array', | |
162 | items => { | |
163 | type => "object", | |
164 | properties => { | |
165 | volname => { | |
166 | description => "The volume name.", | |
167 | type => 'string', | |
168 | }, | |
169 | }, | |
170 | }, | |
171 | }, | |
172 | code => sub { | |
173 | my ($param) = @_; | |
174 | ||
175 | my $server = $param->{server}; | |
176 | my $res = PVE::Storage::scan_nfs($server); | |
177 | ||
178 | my $data = []; | |
179 | foreach my $path (sort keys %$res) { | |
180 | if ($path =~ m!^/([^\s/]+)$!) { | |
181 | push @$data, { volname => $1 }; | |
182 | } | |
183 | } | |
184 | return $data; | |
185 | }}); | |
186 | ||
187 | __PACKAGE__->register_method({ | |
188 | name => 'iscsiscan', | |
189 | path => 'iscsi', | |
190 | method => 'GET', | |
191 | description => "Scan remote iSCSI server.", | |
192 | protected => 1, | |
193 | proxyto => "node", | |
194 | permissions => { | |
195 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
196 | }, | |
197 | parameters => { | |
198 | additionalProperties => 0, | |
199 | properties => { | |
200 | node => get_standard_option('pve-node'), | |
201 | portal => { | |
202 | description => "The iSCSI portal (IP or DNS name with optional port).", | |
203 | type => 'string', format => 'pve-storage-portal-dns', | |
204 | }, | |
205 | }, | |
206 | }, | |
207 | returns => { | |
208 | type => 'array', | |
209 | items => { | |
210 | type => "object", | |
211 | properties => { | |
212 | target => { | |
213 | description => "The iSCSI target name.", | |
214 | type => 'string', | |
215 | }, | |
216 | portal => { | |
217 | description => "The iSCSI portal name.", | |
218 | type => 'string', | |
219 | }, | |
220 | }, | |
221 | }, | |
222 | }, | |
223 | code => sub { | |
224 | my ($param) = @_; | |
225 | ||
226 | my $res = PVE::Storage::scan_iscsi($param->{portal}); | |
227 | ||
228 | my $data = []; | |
229 | foreach my $k (sort keys %$res) { | |
230 | push @$data, { target => $k, portal => join(',', @{$res->{$k}}) }; | |
231 | } | |
232 | ||
233 | return $data; | |
234 | }}); | |
235 | ||
236 | __PACKAGE__->register_method({ | |
237 | name => 'lvmscan', | |
238 | path => 'lvm', | |
239 | method => 'GET', | |
240 | description => "List local LVM volume groups.", | |
241 | protected => 1, | |
242 | proxyto => "node", | |
243 | permissions => { | |
244 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
245 | }, | |
246 | parameters => { | |
247 | additionalProperties => 0, | |
248 | properties => { | |
249 | node => get_standard_option('pve-node'), | |
250 | }, | |
251 | }, | |
252 | returns => { | |
253 | type => 'array', | |
254 | items => { | |
255 | type => "object", | |
256 | properties => { | |
257 | vg => { | |
258 | description => "The LVM logical volume group name.", | |
259 | type => 'string', | |
260 | }, | |
261 | }, | |
262 | }, | |
263 | }, | |
264 | code => sub { | |
265 | my ($param) = @_; | |
266 | ||
267 | my $res = PVE::Storage::LVMPlugin::lvm_vgs(); | |
268 | return PVE::RESTHandler::hash_to_array($res, 'vg'); | |
269 | }}); | |
270 | ||
271 | __PACKAGE__->register_method({ | |
272 | name => 'lvmthinscan', | |
273 | path => 'lvmthin', | |
274 | method => 'GET', | |
275 | description => "List local LVM Thin Pools.", | |
276 | protected => 1, | |
277 | proxyto => "node", | |
278 | permissions => { | |
279 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
280 | }, | |
281 | parameters => { | |
282 | additionalProperties => 0, | |
283 | properties => { | |
284 | node => get_standard_option('pve-node'), | |
285 | vg => { | |
286 | type => 'string', | |
287 | pattern => '[a-zA-Z0-9\.\+\_][a-zA-Z0-9\.\+\_\-]+', # see lvm(8) manpage | |
288 | maxLength => 100, | |
289 | }, | |
290 | }, | |
291 | }, | |
292 | returns => { | |
293 | type => 'array', | |
294 | items => { | |
295 | type => "object", | |
296 | properties => { | |
297 | lv => { | |
298 | description => "The LVM Thin Pool name (LVM logical volume).", | |
299 | type => 'string', | |
300 | }, | |
301 | }, | |
302 | }, | |
303 | }, | |
304 | code => sub { | |
305 | my ($param) = @_; | |
306 | ||
307 | return PVE::Storage::LvmThinPlugin::list_thinpools($param->{vg}); | |
308 | }}); | |
309 | ||
310 | __PACKAGE__->register_method({ | |
311 | name => 'zfsscan', | |
312 | path => 'zfs', | |
313 | method => 'GET', | |
314 | description => "Scan zfs pool list on local node.", | |
315 | protected => 1, | |
316 | proxyto => "node", | |
317 | permissions => { | |
318 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
319 | }, | |
320 | parameters => { | |
321 | additionalProperties => 0, | |
322 | properties => { | |
323 | node => get_standard_option('pve-node'), | |
324 | }, | |
325 | }, | |
326 | returns => { | |
327 | type => 'array', | |
328 | items => { | |
329 | type => "object", | |
330 | properties => { | |
331 | pool => { | |
332 | description => "ZFS pool name.", | |
333 | type => 'string', | |
334 | }, | |
335 | }, | |
336 | }, | |
337 | }, | |
338 | code => sub { | |
339 | my ($param) = @_; | |
340 | ||
341 | return PVE::Storage::scan_zfs(); | |
342 | }}); |