[pve-devel] [PATCH 3/4] add list to pveam
Wolfgang Link
w.link at proxmox.com
Wed Feb 24 12:11:07 CET 2016
This function list all the templates off a specified storage.
It also gives the size of the template.
---
PVE/CLI/pveam.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/PVE/CLI/pveam.pm b/PVE/CLI/pveam.pm
index e90a7d7..b6adfc4 100644
--- a/PVE/CLI/pveam.pm
+++ b/PVE/CLI/pveam.pm
@@ -45,9 +45,74 @@ __PACKAGE__->register_method ({
}});
+__PACKAGE__->register_method ({
+ name => 'index',
+ path => 'index',
+ method => 'GET',
+ description => "Get list of all templates on storage",
+ permissions => {
+ description => "Show all users the template wich have permission on that storage.",
+ check => ['perm', '/storage/{storage}', ['Datastore.AllocateTemplate']],
+ },
+ proxyto => 'node',
+ protected => 1,
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ storage => get_standard_option('pve-storage-id', {
+ description => "Only list status for specified storage",
+ completion => \&PVE::Storage::complete_storage_enabled,
+ }),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {},
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $authuser = $rpcenv->get_user();
+
+ my $storeid = $param->{storage};
+
+ my $cfg = PVE::Cluster::cfs_read_file("storage.cfg");
+
+ die "Storage do not support templates!\n" if !$cfg->{ids}->{$storeid}->{content}->{vztmpl};
+
+ my $vollist = PVE::Storage::volume_list($cfg, $storeid, undef, 'vztmpl');
+
+ my $res = [];
+ foreach my $item (@$vollist) {
+ eval { $rpcenv->check_volume_access($authuser, $cfg, undef, $item->{volid}); };
+ next if $@;
+ push @$res, $item;
+ }
+
+ return $res;
+ }});
+
+my $print_list = sub {
+ my ($list) = @_;
+
+ printf "%-60s %-6s\n",
+ qw(NAME SIZE);
+
+ foreach my $rec (@$list) {
+ printf "%-60s %-4.2fMB\n", $rec->{volid}, $rec->{size}/(1024*1024);
+ }
+};
+
our $cmddef = {
update => [ __PACKAGE__, 'update', []],
download => [ 'PVE::API2::Nodes::Nodeinfo', 'apl_download', [ 'storage', 'template'], { node => $nodename } ],
+ list => [ __PACKAGE__, 'index', [ 'storage' ], { node => $nodename }, $print_list ],
};
1;
--
2.1.4
More information about the pve-devel
mailing list