]>
git.proxmox.com Git - pve-storage.git/blob - pvesm
12 use PVE
::RPCEnvironment
;
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);
22 use base
qw(PVE::CLIHandler);
24 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
28 die "please run as root\n" if $> != 0;
30 PVE
::INotify
::inotify_init
();
32 my $rpcenv = PVE
::RPCEnvironment-
>init('cli');
34 $rpcenv->init_request();
35 $rpcenv->set_language($ENV{LANG
});
36 $rpcenv->set_user('root@pam');
38 __PACKAGE__-
>register_method ({
42 description
=> "Get filesystem path for specified volume",
44 additionalProperties
=> 0,
47 description
=> "Volume identifier",
48 type
=> 'string', format
=> 'pve-volume-id',
52 returns
=> { type
=> 'null' },
57 my $cfg = PVE
::Storage
::config
();
59 my $path = PVE
::Storage
::path
($cfg, $param->{volume
});
67 my $print_content = sub {
71 foreach my $info (@$list) {
73 my $volid = $info->{volid
};
74 my $sidlen = length ($volid);
75 $maxlenname = $sidlen if $sidlen > $maxlenname;
78 foreach my $info (@$list) {
79 next if !$info->{vmid
};
80 my $volid = $info->{volid
};
82 printf "%-${maxlenname}s %5s %10d %d\n", $volid,
83 $info->{format
}, $info->{size
}, $info->{vmid
};
86 foreach my $info (sort { $a->{format
} cmp $b->{format
} } @$list) {
87 next if $info->{vmid
};
88 my $volid = $info->{volid
};
90 printf "%-${maxlenname}s %5s %10d\n", $volid,
91 $info->{format
}, $info->{size
};
95 my $print_status = sub {
99 foreach my $res (@$res) {
100 my $storeid = $res->{storage
};
101 $maxlen = length ($storeid) if length ($storeid) > $maxlen;
105 foreach my $res (sort { $a->{storage
} cmp $b->{storage
} } @$res) {
106 my $storeid = $res->{storage
};
108 my $sum = $res->{used
} + $res->{avail
};
109 my $per = $sum ?
(0.5 + ($res->{used
}*100)/$sum) : 100;
111 printf "%-${maxlen}s %5s %1d %15d %15d %15d %.2f%%\n", $storeid,
112 $res->{type
}, $res->{active
},
113 $res->{total
}/1024, $res->{used}/1024, $res->{avail
}/1024, $per;
117 my $nodename = PVE
::INotify
::nodename
();
120 add
=> [ "PVE::API2::Storage::Config", 'create', ['type', 'storage'] ],
121 set
=> [ "PVE::API2::Storage::Config", 'update', ['storage'] ],
122 remove
=> [ "PVE::API2::Storage::Config", 'delete', ['storage'] ],
123 status
=> [ "PVE::API2::Storage::Status", 'index', [],
124 { node
=> $nodename }, $print_status ],
125 list
=> [ "PVE::API2::Storage::Content", 'index', ['storage'],
126 { node
=> $nodename }, $print_content ],
127 alloc
=> [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'],
128 { node
=> $nodename }, sub {
130 print "sucessfuly created '$volid'\n";
132 free
=> [ "PVE::API2::Storage::Content", 'delete', ['volume'],
133 { node
=> $nodename } ],
134 nfsscan
=> [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'],
135 { node
=> $nodename }, sub {
139 foreach my $rec (@$res) {
140 my $len = length ($rec->{path
});
141 $maxlen = $len if $len > $maxlen;
143 foreach my $rec (@$res) {
144 printf "%-${maxlen}s %s\n", $rec->{path
}, $rec->{options
};
147 glusterfsscan
=> [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'],
148 { node
=> $nodename }, sub {
151 foreach my $rec (@$res) {
152 printf "%s\n", $rec->{volname
};
155 iscsiscan
=> [ "PVE::API2::Storage::Scan", 'iscsiscan', ['server'],
156 { node
=> $nodename }, sub {
160 foreach my $rec (@$res) {
161 my $len = length ($rec->{target
});
162 $maxlen = $len if $len > $maxlen;
164 foreach my $rec (@$res) {
165 printf "%-${maxlen}s %s\n", $rec->{target
}, $rec->{portal
};
168 lvmscan
=> [ "PVE::API2::Storage::Scan", 'lvmscan', [],
169 { node
=> $nodename }, sub {
171 foreach my $rec (@$res) {
172 printf "$rec->{vg}\n";
175 zfsscan
=> [ "PVE::API2::Storage::Scan", 'zfsscan', [],
176 { node
=> $nodename }, sub {
179 foreach my $rec (@$res) {
180 printf "$rec->{pool}\n";
183 path
=> [ __PACKAGE__
, 'path', ['volume']],
188 PVE
::CLIHandler
::handle_cmd
($cmddef, "pvesm", $cmd, \
@ARGV, undef, $0);
196 pvesm - PVE Storage Manager
206 Each storage pool is uniquely identified by its <STORAGE_ID>.
208 =head3 Storage content
210 A storage can support several content types, for example virtual disk
211 images, cdrom iso images, openvz templates or openvz root directories
212 (C<images>, C<iso>, C<vztmpl>, C<rootdir>).
216 A volume is identified by the <STORAGE_ID>, followed by a storage type
217 dependent volume name, separated by colon. A valid <VOLUME_ID> looks like:
219 local:230/example-image.raw
221 local:iso/debian-501-amd64-netinst.iso
223 local:vztmpl/debian-5.0-joomla_1.5.9-1_i386.tar.gz
225 iscsi-storage:0.0.2.scsi-14f504e46494c4500494b5042546d2d646744372d31616d61
227 To get the filesystem path for a <VOLUME_ID> use:
229 pvesm path <VOLUME_ID>
234 # scan iscsi host for available targets
235 pvesm scan iscsi <HOST[:PORT]>
237 # scan nfs server for available exports
238 pvesm scan nfs <HOST>
241 pvesm add <TYPE> <STORAGE_ID> <OPTIONS>
242 pvesm add dir <STORAGE_ID> --path <PATH>
243 pvesm add nfs <STORAGE_ID> --path <PATH> --server <SERVER> --export <EXPORT>
244 pvesm add lvm <STORAGE_ID> --vgname <VGNAME>
245 pvesm add iscsi <STORAGE_ID> --portal <HOST[:PORT]> --target <TARGET>
247 # disable storage pools
248 pvesm set <STORAGE_ID> --disable 1
250 # enable storage pools
251 pvesm set <STORAGE_ID> --disable 0
253 # change/set storage options
254 pvesm set <STORAGE_ID> <OPTIONS>
255 pvesm set <STORAGE_ID> --shared 1
256 pvesm set local --format qcow2
257 pvesm set <STORAGE_ID> --content iso
259 # remove storage pools - does not delete any data
260 pvesm remove <STORAGE_ID>
263 pvesm alloc <STORAGE_ID> <VMID> <name> <size> [--format <raw|qcow2>]
265 # alloc 4G volume in local storage - use auto generated name
266 pvesm alloc local <VMID> '' 4G
268 # free volumes (warning: destroy/deletes all volume data)
269 pvesm free <VOLUME_ID>
271 # list storage status
274 # list storage contents
275 pvesm list <STORAGE_ID> [--vmid <VMID>]
277 # list volumes allocated by VMID
278 pvesm list <STORAGE_ID> --vmid <VMID>
281 pvesm list <STORAGE_ID> --iso
283 # list openvz templates
284 pvesm list <STORAGE_ID> --vztmpl
286 # show filesystem path for a volume
287 pvesm path <VOLUME_ID>
289 =include pve_copyright