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