]> git.proxmox.com Git - pve-storage.git/blob - PVE/CLI/pvesm.pm
add missing completion hooks
[pve-storage.git] / PVE / CLI / pvesm.pm
1 package PVE::CLI::pvesm;
2
3 use strict;
4 use warnings;
5
6 use Fcntl ':flock';
7 use File::Path;
8
9 use PVE::SafeSyslog;
10 use PVE::Cluster;
11 use PVE::INotify;
12 use PVE::RPCEnvironment;
13 use PVE::Storage;
14 use PVE::API2::Storage::Config;
15 use PVE::API2::Storage::Content;
16 use PVE::API2::Storage::Status;
17 use PVE::API2::Storage::Scan;
18 use PVE::JSONSchema qw(get_standard_option);
19
20 use PVE::CLIHandler;
21
22 use base qw(PVE::CLIHandler);
23
24 my $nodename = PVE::INotify::nodename();
25
26 __PACKAGE__->register_method ({
27 name => 'path',
28 path => 'path',
29 method => 'GET',
30 description => "Get filesystem path for specified volume",
31 parameters => {
32 additionalProperties => 0,
33 properties => {
34 volume => {
35 description => "Volume identifier",
36 type => 'string', format => 'pve-volume-id',
37 completion => \&PVE::Storage::complete_volume,
38 },
39 },
40 },
41 returns => { type => 'null' },
42
43 code => sub {
44 my ($param) = @_;
45
46 my $cfg = PVE::Storage::config();
47
48 my $path = PVE::Storage::path ($cfg, $param->{volume});
49
50 print "$path\n";
51
52 return undef;
53
54 }});
55
56 my $print_content = sub {
57 my ($list) = @_;
58
59 my $maxlenname = 0;
60 foreach my $info (@$list) {
61
62 my $volid = $info->{volid};
63 my $sidlen = length ($volid);
64 $maxlenname = $sidlen if $sidlen > $maxlenname;
65 }
66
67 foreach my $info (@$list) {
68 next if !$info->{vmid};
69 my $volid = $info->{volid};
70
71 printf "%-${maxlenname}s %5s %10d %d\n", $volid,
72 $info->{format}, $info->{size}, $info->{vmid};
73 }
74
75 foreach my $info (sort { $a->{format} cmp $b->{format} } @$list) {
76 next if $info->{vmid};
77 my $volid = $info->{volid};
78
79 printf "%-${maxlenname}s %5s %10d\n", $volid,
80 $info->{format}, $info->{size};
81 }
82 };
83
84 my $print_status = sub {
85 my $res = shift;
86
87 my $maxlen = 0;
88 foreach my $res (@$res) {
89 my $storeid = $res->{storage};
90 $maxlen = length ($storeid) if length ($storeid) > $maxlen;
91 }
92 $maxlen+=1;
93
94 foreach my $res (sort { $a->{storage} cmp $b->{storage} } @$res) {
95 my $storeid = $res->{storage};
96
97 my $sum = $res->{used} + $res->{avail};
98 my $per = $sum ? (0.5 + ($res->{used}*100)/$sum) : 100;
99
100 printf "%-${maxlen}s %5s %1d %15d %15d %15d %.2f%%\n", $storeid,
101 $res->{type}, $res->{active},
102 $res->{total}/1024, $res->{used}/1024, $res->{avail}/1024, $per;
103 }
104 };
105
106 our $cmddef = {
107 add => [ "PVE::API2::Storage::Config", 'create', ['type', 'storage'] ],
108 set => [ "PVE::API2::Storage::Config", 'update', ['storage'] ],
109 remove => [ "PVE::API2::Storage::Config", 'delete', ['storage'] ],
110 status => [ "PVE::API2::Storage::Status", 'index', [],
111 { node => $nodename }, $print_status ],
112 list => [ "PVE::API2::Storage::Content", 'index', ['storage'],
113 { node => $nodename }, $print_content ],
114 alloc => [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'],
115 { node => $nodename }, sub {
116 my $volid = shift;
117 print "sucessfuly created '$volid'\n";
118 }],
119 free => [ "PVE::API2::Storage::Content", 'delete', ['volume'],
120 { node => $nodename } ],
121 nfsscan => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'],
122 { node => $nodename }, sub {
123 my $res = shift;
124
125 my $maxlen = 0;
126 foreach my $rec (@$res) {
127 my $len = length ($rec->{path});
128 $maxlen = $len if $len > $maxlen;
129 }
130 foreach my $rec (@$res) {
131 printf "%-${maxlen}s %s\n", $rec->{path}, $rec->{options};
132 }
133 }],
134 glusterfsscan => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'],
135 { node => $nodename }, sub {
136 my $res = shift;
137
138 foreach my $rec (@$res) {
139 printf "%s\n", $rec->{volname};
140 }
141 }],
142 iscsiscan => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['server'],
143 { node => $nodename }, sub {
144 my $res = shift;
145
146 my $maxlen = 0;
147 foreach my $rec (@$res) {
148 my $len = length ($rec->{target});
149 $maxlen = $len if $len > $maxlen;
150 }
151 foreach my $rec (@$res) {
152 printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal};
153 }
154 }],
155 lvmscan => [ "PVE::API2::Storage::Scan", 'lvmscan', [],
156 { node => $nodename }, sub {
157 my $res = shift;
158 foreach my $rec (@$res) {
159 printf "$rec->{vg}\n";
160 }
161 }],
162 zfsscan => [ "PVE::API2::Storage::Scan", 'zfsscan', [],
163 { node => $nodename }, sub {
164 my $res = shift;
165
166 foreach my $rec (@$res) {
167 printf "$rec->{pool}\n";
168 }
169 }],
170 path => [ __PACKAGE__, 'path', ['volume']],
171 };
172
173 1;
174
175 __END__
176
177 =head1 NAME
178
179 pvesm - PVE Storage Manager
180
181 =head1 SYNOPSIS
182
183 =include synopsis
184
185 =head1 DESCRIPTION
186
187 =head2 Storage pools
188
189 Each storage pool is uniquely identified by its <STORAGE_ID>.
190
191 =head3 Storage content
192
193 A storage can support several content types, for example virtual disk
194 images, cdrom iso images, openvz templates or openvz root directories
195 (C<images>, C<iso>, C<vztmpl>, C<rootdir>).
196
197 =head2 Volumes
198
199 A volume is identified by the <STORAGE_ID>, followed by a storage type
200 dependent volume name, separated by colon. A valid <VOLUME_ID> looks like:
201
202 local:230/example-image.raw
203
204 local:iso/debian-501-amd64-netinst.iso
205
206 local:vztmpl/debian-5.0-joomla_1.5.9-1_i386.tar.gz
207
208 iscsi-storage:0.0.2.scsi-14f504e46494c4500494b5042546d2d646744372d31616d61
209
210 To get the filesystem path for a <VOLUME_ID> use:
211
212 pvesm path <VOLUME_ID>
213
214
215 =head1 EXAMPLES
216
217 # scan iscsi host for available targets
218 pvesm iscsiscan -portal <HOST[:PORT]>
219
220 # scan nfs server for available exports
221 pvesm nfsscan <HOST>
222
223 # add storage pools
224 pvesm add <TYPE> <STORAGE_ID> <OPTIONS>
225 pvesm add dir <STORAGE_ID> --path <PATH>
226 pvesm add nfs <STORAGE_ID> --path <PATH> --server <SERVER> --export <EXPORT>
227 pvesm add lvm <STORAGE_ID> --vgname <VGNAME>
228 pvesm add iscsi <STORAGE_ID> --portal <HOST[:PORT]> --target <TARGET>
229
230 # disable storage pools
231 pvesm set <STORAGE_ID> --disable 1
232
233 # enable storage pools
234 pvesm set <STORAGE_ID> --disable 0
235
236 # change/set storage options
237 pvesm set <STORAGE_ID> <OPTIONS>
238 pvesm set <STORAGE_ID> --shared 1
239 pvesm set local --format qcow2
240 pvesm set <STORAGE_ID> --content iso
241
242 # remove storage pools - does not delete any data
243 pvesm remove <STORAGE_ID>
244
245 # alloc volumes
246 pvesm alloc <STORAGE_ID> <VMID> <name> <size> [--format <raw|qcow2>]
247
248 # alloc 4G volume in local storage - use auto generated name
249 pvesm alloc local <VMID> '' 4G
250
251 # free volumes (warning: destroy/deletes all volume data)
252 pvesm free <VOLUME_ID>
253
254 # list storage status
255 pvesm status
256
257 # list storage contents
258 pvesm list <STORAGE_ID> [--vmid <VMID>]
259
260 # list volumes allocated by VMID
261 pvesm list <STORAGE_ID> --vmid <VMID>
262
263 # list iso images
264 pvesm list <STORAGE_ID> --iso
265
266 # list openvz templates
267 pvesm list <STORAGE_ID> --vztmpl
268
269 # show filesystem path for a volume
270 pvesm path <VOLUME_ID>
271
272 =include pve_copyright