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