]>
Commit | Line | Data |
---|---|---|
b6cf0a66 DM |
1 | package PVE::API2::Storage::Scan; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::SafeSyslog; | |
7 | use PVE::Storage; | |
8 | use HTTP::Status qw(:constants); | |
9 | use PVE::JSONSchema qw(get_standard_option); | |
10 | ||
11 | use PVE::RESTHandler; | |
12 | ||
13 | use base qw(PVE::RESTHandler); | |
14 | ||
15 | __PACKAGE__->register_method ({ | |
16 | name => 'index', | |
17 | path => '', | |
18 | method => 'GET', | |
19 | description => "Index of available scan methods", | |
5f642f73 DM |
20 | permissions => { |
21 | user => 'all', | |
22 | }, | |
b6cf0a66 DM |
23 | parameters => { |
24 | additionalProperties => 0, | |
25 | properties => { | |
26 | node => get_standard_option('pve-node'), | |
27 | }, | |
28 | }, | |
29 | returns => { | |
30 | type => 'array', | |
31 | items => { | |
32 | type => "object", | |
33 | properties => { method => { type => 'string'} }, | |
34 | }, | |
35 | links => [ { rel => 'child', href => "{method}" } ], | |
36 | }, | |
37 | code => sub { | |
38 | my ($param) = @_; | |
39 | ||
40 | my $res = [ | |
41 | { method => 'lvm' }, | |
42 | { method => 'iscsi' }, | |
43 | { method => 'nfs' }, | |
44 | { method => 'usb' }, | |
45 | ]; | |
46 | ||
47 | return $res; | |
48 | }}); | |
49 | ||
50 | __PACKAGE__->register_method ({ | |
51 | name => 'nfsscan', | |
52 | path => 'nfs', | |
53 | method => 'GET', | |
54 | description => "Scan remote NFS server.", | |
55 | protected => 1, | |
56 | proxyto => "node", | |
5f642f73 DM |
57 | permissions => { |
58 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
59 | }, | |
b6cf0a66 DM |
60 | parameters => { |
61 | additionalProperties => 0, | |
62 | properties => { | |
63 | node => get_standard_option('pve-node'), | |
64 | server => { type => 'string', format => 'pve-storage-server' }, | |
65 | }, | |
66 | }, | |
67 | returns => { | |
68 | type => 'array', | |
69 | items => { | |
70 | type => "object", | |
71 | properties => { | |
72 | path => { type => 'string'}, | |
73 | options => { type => 'string'}, | |
74 | }, | |
75 | }, | |
76 | }, | |
77 | code => sub { | |
78 | my ($param) = @_; | |
79 | ||
80 | my $server = $param->{server}; | |
81 | my $res = PVE::Storage::scan_nfs($server); | |
82 | ||
83 | my $data = []; | |
84 | foreach my $k (keys %$res) { | |
85 | push @$data, { path => $k, options => $res->{$k} }; | |
86 | } | |
87 | return $data; | |
88 | }}); | |
89 | ||
90 | __PACKAGE__->register_method ({ | |
91 | name => 'iscsiscan', | |
92 | path => 'iscsi', | |
93 | method => 'GET', | |
94 | description => "Scan remote iSCSI server.", | |
95 | protected => 1, | |
96 | proxyto => "node", | |
5f642f73 DM |
97 | permissions => { |
98 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
99 | }, | |
b6cf0a66 DM |
100 | parameters => { |
101 | additionalProperties => 0, | |
102 | properties => { | |
103 | node => get_standard_option('pve-node'), | |
104 | portal => { type => 'string', format => 'pve-storage-portal-dns' }, | |
105 | }, | |
106 | }, | |
107 | returns => { | |
108 | type => 'array', | |
109 | items => { | |
110 | type => "object", | |
111 | properties => { | |
112 | target => { type => 'string'}, | |
113 | portal => { type => 'string'}, | |
114 | }, | |
115 | }, | |
116 | }, | |
117 | code => sub { | |
118 | my ($param) = @_; | |
119 | ||
120 | my $res = PVE::Storage::scan_iscsi($param->{portal}); | |
121 | ||
122 | my $data = []; | |
123 | foreach my $k (keys %$res) { | |
124 | push @$data, { target => $k, portal => join(',', @{$res->{$k}}) }; | |
125 | } | |
126 | ||
127 | return $data; | |
128 | }}); | |
129 | ||
130 | __PACKAGE__->register_method ({ | |
131 | name => 'lvmscan', | |
132 | path => 'lvm', | |
133 | method => 'GET', | |
134 | description => "List local LVM volume groups.", | |
135 | protected => 1, | |
136 | proxyto => "node", | |
5f642f73 DM |
137 | permissions => { |
138 | check => ['perm', '/storage', ['Datastore.Allocate']], | |
139 | }, | |
b6cf0a66 DM |
140 | parameters => { |
141 | additionalProperties => 0, | |
142 | properties => { | |
143 | node => get_standard_option('pve-node'), | |
144 | }, | |
145 | }, | |
146 | returns => { | |
147 | type => 'array', | |
148 | items => { | |
149 | type => "object", | |
150 | properties => { | |
151 | vg => { type => 'string'}, | |
152 | }, | |
153 | }, | |
154 | }, | |
155 | code => sub { | |
156 | my ($param) = @_; | |
157 | ||
158 | my $res = PVE::Storage::lvm_vgs(); | |
159 | return PVE::RESTHandler::hash_to_array($res, 'vg'); | |
160 | }}); | |
161 | ||
162 | __PACKAGE__->register_method ({ | |
163 | name => 'usbscan', | |
164 | path => 'usb', | |
165 | method => 'GET', | |
166 | description => "List local USB devices.", | |
167 | protected => 1, | |
168 | proxyto => "node", | |
5f642f73 DM |
169 | permissions => { |
170 | check => ['perm', '/', ['Sys.Modify']], | |
171 | }, | |
b6cf0a66 DM |
172 | parameters => { |
173 | additionalProperties => 0, | |
174 | properties => { | |
175 | node => get_standard_option('pve-node'), | |
176 | }, | |
177 | }, | |
178 | returns => { | |
179 | type => 'array', | |
180 | items => { | |
181 | type => "object", | |
182 | properties => { | |
183 | busnum => { type => 'integer'}, | |
184 | devnum => { type => 'integer'}, | |
185 | port => { type => 'integer'}, | |
186 | usbpath => { type => 'string', optional => 1}, | |
187 | level => { type => 'integer'}, | |
188 | class => { type => 'integer'}, | |
189 | vendid => { type => 'string'}, | |
190 | prodid => { type => 'string'}, | |
191 | speed => { type => 'string'}, | |
192 | ||
193 | product => { type => 'string', optional => 1 }, | |
194 | serial => { type => 'string', optional => 1 }, | |
195 | manufacturer => { type => 'string', optional => 1 }, | |
196 | }, | |
197 | }, | |
198 | }, | |
199 | code => sub { | |
200 | my ($param) = @_; | |
201 | ||
202 | return PVE::Storage::scan_usb(); | |
203 | }}); | |
204 | ||
205 | 1; |