[pve-devel] [PATCH 4/4] add function destroy to pveam

Wolfgang Link w.link at proxmox.com
Wed Feb 24 12:11:08 CET 2016


now it is possible to erase templates with pveam
---
 PVE/CLI/pveam.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/PVE/CLI/pveam.pm b/PVE/CLI/pveam.pm
index b6adfc4..0f907cf 100644
--- a/PVE/CLI/pveam.pm
+++ b/PVE/CLI/pveam.pm
@@ -14,6 +14,7 @@ use PVE::RPCEnvironment;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::CLIHandler;
 use PVE::API2::Nodes;
+use PVE::Storage;
 
 use base qw(PVE::CLIHandler);
 
@@ -98,6 +99,49 @@ __PACKAGE__->register_method ({
 	return $res;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'destroy',
+    path => 'destroy',
+    method => 'DELETE',
+    description => "Destroy a template",
+    permissions => {
+	description => "Only user how can create templates can delete them",
+	check => ['perm', '/storage/{storage}', ['Datastore.AllocateTemplate']],
+    },
+    proxyto => 'node',
+    protected => 1,
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    template_path => { type => 'string',
+			  description => "The template which will destroyed",
+			  maxLength => 255,
+	    },
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $authuser = $rpcenv->get_user();
+
+	my $template = $param->{template_path};
+
+	my $cfg = PVE::Cluster::cfs_read_file("storage.cfg");
+
+	$rpcenv->check_volume_access($authuser, $cfg, undef, $template);
+
+	my $abs_path = PVE::Storage::abs_filesystem_path($cfg, $template);
+
+	unlink $abs_path;
+
+	return undef;
+    }});
+
+
 my $print_list = sub {
     my ($list) = @_;
 
@@ -113,6 +157,7 @@ our $cmddef = {
     update => [ __PACKAGE__, 'update', []],
     download => [ 'PVE::API2::Nodes::Nodeinfo', 'apl_download', [ 'storage', 'template'], { node => $nodename } ],
     list => [  __PACKAGE__, 'index', [ 'storage' ], { node => $nodename }, $print_list ],
+    destroy => [  __PACKAGE__, 'destroy', [ 'template_path' ], { node => $nodename }]
 };
 
 1;
-- 
2.1.4





More information about the pve-devel mailing list