]>
git.proxmox.com Git - pve-storage.git/blob - pvesm
11 use PVE
::RPCEnvironment
;
13 use PVE
::API2
::Storage
::Config
;
14 use PVE
::API2
::Storage
::Content
;
15 use PVE
::API2
::Storage
::Status
;
16 use PVE
::API2
::Storage
::Scan
;
17 use PVE
::JSONSchema
qw(get_standard_option);
21 use base
qw(PVE::CLIHandler);
23 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
27 die "please run as root\n" if $> != 0;
29 PVE
::INotify
::inotify_init
();
31 my $rpcenv = PVE
::RPCEnvironment-
>init('cli');
33 $rpcenv->init_request();
34 $rpcenv->set_language($ENV{LANG
});
35 $rpcenv->set_user('root@pam');
37 __PACKAGE__-
>register_method ({
41 description
=> "Get filesystem path for specified volume",
43 additionalProperties
=> 0,
46 description
=> "Volume identifier",
47 type
=> 'string', format
=> 'pve-volume-id',
51 returns
=> { type
=> 'null' },
56 my $cfg = PVE
::Storage
::config
();
58 my $path = PVE
::Storage
::path
($cfg, $param->{volume
});
66 my $print_content = sub {
70 foreach my $info (@$list) {
72 my $volid = $info->{volid
};
73 my $sidlen = length ($volid);
74 $maxlenname = $sidlen if $sidlen > $maxlenname;
77 foreach my $info (@$list) {
78 next if !$info->{vmid
};
79 my $volid = $info->{volid
};
81 printf "%-${maxlenname}s %5s %10d %d\n", $volid,
82 $info->{format
}, $info->{size
}, $info->{vmid
};
85 foreach my $info (sort { $a->{format
} cmp $b->{format
} } @$list) {
86 next if $info->{vmid
};
87 my $volid = $info->{volid
};
89 printf "%-${maxlenname}s %5s %10d\n", $volid,
90 $info->{format
}, $info->{size
};
94 my $print_status = sub {
98 foreach my $res (@$res) {
99 my $storeid = $res->{storage
};
100 $maxlen = length ($storeid) if length ($storeid) > $maxlen;
104 foreach my $res (sort { $a->{storage
} cmp $b->{storage
} } @$res) {
105 my $storeid = $res->{storage
};
107 my $sum = $res->{used
} + $res->{avail
};
108 my $per = $sum ?
(0.5 + ($res->{used
}*100)/$sum) : 100;
110 printf "%-${maxlen}s %5s %1d %15d %15d %15d %.2f%%\n", $storeid,
111 $res->{type
}, $res->{active
},
112 $res->{total
}/1024, $res->{used}/1024, $res->{avail
}/1024, $per;
116 my $nodename = PVE
::INotify
::nodename
();
119 add
=> [ "PVE::API2::Storage::Config", 'create', ['storage'] ],
120 set
=> [ "PVE::API2::Storage::Config", 'update', ['storage'] ],
121 remove
=> [ "PVE::API2::Storage::Config", 'delete', ['storage'] ],
122 status
=> [ "PVE::API2::Storage::Status", 'index', [],
123 { node
=> $nodename }, $print_status ],
124 list
=> [ "PVE::API2::Storage::Content", 'index', ['storage'],
125 { node
=> $nodename }, $print_content ],
126 alloc
=> [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'],
127 { node
=> $nodename }, sub {
129 print "sucessfuly created '$volid'\n";
131 free
=> [ "PVE::API2::Storage::Content", 'delete', ['volume'],
132 { node
=> $nodename } ],
133 nfsscan
=> [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'],
134 { node
=> $nodename }, sub {
138 foreach my $rec (@$res) {
139 my $len = length ($rec->{path
});
140 $maxlen = $len if $len > $maxlen;
142 foreach my $rec (@$res) {
143 printf "%-${maxlen}s %s\n", $rec->{path
}, $rec->{options
};
146 iscsiscan
=> [ "PVE::API2::Storage::Scan", 'iscsiscan', ['server'],
147 { node
=> $nodename }, sub {
151 foreach my $rec (@$res) {
152 my $len = length ($rec->{target
});
153 $maxlen = $len if $len > $maxlen;
155 foreach my $rec (@$res) {
156 printf "%-${maxlen}s %s\n", $rec->{target
}, $rec->{portal
};
159 lvmscan
=> [ "PVE::API2::Storage::Scan", 'lvmscan', [],
160 { node
=> $nodename }, sub {
162 foreach my $rec (@$res) {
163 printf "$rec->{vg}\n";
166 path
=> [ __PACKAGE__
, 'path', ['volume']],
171 PVE
::CLIHandler
::handle_cmd
($cmddef, "pvesm", $cmd, \
@ARGV, undef, $0);
179 pvesm - PVE Storage Manager
189 Each storage pool is uniquely identified by its <STORAGE_ID>.
191 =head3 Storage content
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>).
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:
202 local:230/example-image.raw
204 local:iso/debian-501-amd64-netinst.iso
206 local:vztmpl/debian-5.0-joomla_1.5.9-1_i386.tar.gz
208 iscsi-storage:0.0.2.scsi-14f504e46494c4500494b5042546d2d646744372d31616d61
210 To get the filesystem path for a <VOLUME_ID> use:
212 pvesm path <VOLUME_ID>
217 # scan iscsi host for available targets
218 pvesm scan iscsi <HOST[:PORT]>
220 # scan nfs server for available exports
221 pvesm scan nfs <HOST>
224 pvesm add <STORAGE_ID> <TYPE> <OPTIONS>
225 pvesm add <STORAGE_ID> dir --path <PATH>
226 pvesm add <STORAGE_ID> nfs --path <PATH> --server <SERVER> --export <EXPORT>
227 pvesm add <STORAGE_ID> lvm --vgname <VGNAME>
228 pvesm add <STORAGE_ID> iscsi --portal <HOST[:PORT]> --target <TARGET>
230 # disable storage pools
231 pvesm set <STORAGE_ID> --disable 1
233 # enable storage pools
234 pvesm set <STORAGE_ID> --disable 0
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
242 # remove storage pools - does not delete any data
243 pvesm remove <STORAGE_ID>
246 pvesm alloc <STORAGE_ID> <VMID> <name> <size> [--format <raw|qcow2>]
248 # alloc 4G volume in local storage - use auto generated name
249 pvesm alloc local <VMID> '' 4G
251 # free volumes (warning: destroy/deletes all volume data)
252 pvesm free <VOLUME_ID>
254 # list storage status
257 # list storage contents
258 pvesm list <STORAGE_ID> [--vmid <VMID>]
260 # list volumes allocated by VMID
261 pvesm list <STORAGE_ID> --vmid <VMID>
264 pvesm list <STORAGE_ID> --iso
266 # list openvz templates
267 pvesm list <STORAGE_ID> --vztmpl
269 # show filesystem path for a volume
270 pvesm path <VOLUME_ID>
272 =include pve_copyright