]>
Commit | Line | Data |
---|---|---|
c669f42d DM |
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', | |
f3bd890d | 37 | completion => \&PVE::Storage::complete_volume, |
c669f42d DM |
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 | }], | |
668f6d9f DM |
162 | lvmthinscan => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], |
163 | { node => $nodename }, sub { | |
164 | my $res = shift; | |
165 | foreach my $rec (@$res) { | |
166 | printf "$rec->{lv}\n"; | |
167 | } | |
168 | }], | |
c669f42d DM |
169 | zfsscan => [ "PVE::API2::Storage::Scan", 'zfsscan', [], |
170 | { node => $nodename }, sub { | |
171 | my $res = shift; | |
172 | ||
173 | foreach my $rec (@$res) { | |
174 | printf "$rec->{pool}\n"; | |
175 | } | |
176 | }], | |
177 | path => [ __PACKAGE__, 'path', ['volume']], | |
178 | }; | |
179 | ||
180 | 1; | |
181 | ||
182 | __END__ | |
183 | ||
184 | =head1 NAME | |
185 | ||
186 | pvesm - PVE Storage Manager | |
187 | ||
188 | =head1 SYNOPSIS | |
189 | ||
190 | =include synopsis | |
191 | ||
192 | =head1 DESCRIPTION | |
193 | ||
194 | =head2 Storage pools | |
195 | ||
196 | Each storage pool is uniquely identified by its <STORAGE_ID>. | |
197 | ||
198 | =head3 Storage content | |
199 | ||
200 | A storage can support several content types, for example virtual disk | |
201 | images, cdrom iso images, openvz templates or openvz root directories | |
202 | (C<images>, C<iso>, C<vztmpl>, C<rootdir>). | |
203 | ||
204 | =head2 Volumes | |
205 | ||
206 | A volume is identified by the <STORAGE_ID>, followed by a storage type | |
207 | dependent volume name, separated by colon. A valid <VOLUME_ID> looks like: | |
208 | ||
209 | local:230/example-image.raw | |
210 | ||
211 | local:iso/debian-501-amd64-netinst.iso | |
212 | ||
213 | local:vztmpl/debian-5.0-joomla_1.5.9-1_i386.tar.gz | |
214 | ||
215 | iscsi-storage:0.0.2.scsi-14f504e46494c4500494b5042546d2d646744372d31616d61 | |
216 | ||
217 | To get the filesystem path for a <VOLUME_ID> use: | |
218 | ||
219 | pvesm path <VOLUME_ID> | |
220 | ||
221 | ||
222 | =head1 EXAMPLES | |
223 | ||
224 | # scan iscsi host for available targets | |
225 | pvesm iscsiscan -portal <HOST[:PORT]> | |
226 | ||
227 | # scan nfs server for available exports | |
228 | pvesm nfsscan <HOST> | |
229 | ||
230 | # add storage pools | |
231 | pvesm add <TYPE> <STORAGE_ID> <OPTIONS> | |
232 | pvesm add dir <STORAGE_ID> --path <PATH> | |
233 | pvesm add nfs <STORAGE_ID> --path <PATH> --server <SERVER> --export <EXPORT> | |
234 | pvesm add lvm <STORAGE_ID> --vgname <VGNAME> | |
235 | pvesm add iscsi <STORAGE_ID> --portal <HOST[:PORT]> --target <TARGET> | |
236 | ||
237 | # disable storage pools | |
238 | pvesm set <STORAGE_ID> --disable 1 | |
239 | ||
240 | # enable storage pools | |
241 | pvesm set <STORAGE_ID> --disable 0 | |
242 | ||
243 | # change/set storage options | |
244 | pvesm set <STORAGE_ID> <OPTIONS> | |
245 | pvesm set <STORAGE_ID> --shared 1 | |
246 | pvesm set local --format qcow2 | |
247 | pvesm set <STORAGE_ID> --content iso | |
248 | ||
249 | # remove storage pools - does not delete any data | |
250 | pvesm remove <STORAGE_ID> | |
251 | ||
252 | # alloc volumes | |
253 | pvesm alloc <STORAGE_ID> <VMID> <name> <size> [--format <raw|qcow2>] | |
254 | ||
255 | # alloc 4G volume in local storage - use auto generated name | |
256 | pvesm alloc local <VMID> '' 4G | |
257 | ||
258 | # free volumes (warning: destroy/deletes all volume data) | |
259 | pvesm free <VOLUME_ID> | |
260 | ||
261 | # list storage status | |
262 | pvesm status | |
263 | ||
264 | # list storage contents | |
265 | pvesm list <STORAGE_ID> [--vmid <VMID>] | |
266 | ||
267 | # list volumes allocated by VMID | |
268 | pvesm list <STORAGE_ID> --vmid <VMID> | |
269 | ||
270 | # list iso images | |
271 | pvesm list <STORAGE_ID> --iso | |
272 | ||
273 | # list openvz templates | |
274 | pvesm list <STORAGE_ID> --vztmpl | |
275 | ||
276 | # show filesystem path for a volume | |
277 | pvesm path <VOLUME_ID> | |
278 | ||
279 | =include pve_copyright |