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