[pve-devel] r5124 - in qemu-server/pve2: . PVE/API2
svn-commits at proxmox.com
svn-commits at proxmox.com
Mon Sep 13 13:00:19 CEST 2010
Author: dietmar
Date: 2010-09-13 11:00:19 +0000 (Mon, 13 Sep 2010)
New Revision: 5124
Modified:
qemu-server/pve2/ChangeLog
qemu-server/pve2/PVE/API2/QemuServer.pm
qemu-server/pve2/PVE/API2/QemuServerStatus.pm
qemu-server/pve2/QemuServer.pm
qemu-server/pve2/nqm
qemu-server/pve2/qm
Log:
* PVE/API2/QemuServer.pm: implement destroy_vm()
Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/ChangeLog 2010-09-13 11:00:19 UTC (rev 5124)
@@ -1,5 +1,7 @@
2010-09-13 Proxmox Support Team <support at proxmox.com>
+ * PVE/API2/QemuServer.pm: implement destroy_vm()
+
* PVE/API2/QemuServerStatus.pm: implement vm_command()
* nqm: implement monitor command
Modified: qemu-server/pve2/PVE/API2/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServer.pm 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/PVE/API2/QemuServer.pm 2010-09-13 11:00:19 UTC (rev 5124)
@@ -250,4 +250,37 @@
return $conf;
}});
+__PACKAGE__->register_method ({
+ name => 'destroy_vm',
+ path => '{node}/{vmid}',
+ method => 'DELETE',
+ description => "Destroy the vm (also delete all used/owned volumes).",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid'),
+ },
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $user = $rpcenv->get_user();
+
+ my $vmid = $param->{vmid};
+
+ my $skiplock = $param->{skiplock};
+ raise_param_exc({ skiplock => "Only root may use this option." })
+ if $user ne 'root';
+
+ my $storecfg = read_file('storagecfg');
+
+ PVE::QemuServer::vm_destroy ($storecfg, $vmid, $skiplock);
+
+ return undef;
+ }});
+
1;
Modified: qemu-server/pve2/PVE/API2/QemuServerStatus.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServerStatus.pm 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/PVE/API2/QemuServerStatus.pm 2010-09-13 11:00:19 UTC (rev 5124)
@@ -48,7 +48,7 @@
__PACKAGE__->register_method ({
name => 'vm_command',
path => '{node}/{vmid}',
- method => 'POST',
+ method => 'PUT',
description => "Set virtual machine status.",
parameters => {
additionalProperties => 0,
Modified: qemu-server/pve2/QemuServer.pm
===================================================================
--- qemu-server/pve2/QemuServer.pm 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/QemuServer.pm 2010-09-13 11:00:19 UTC (rev 5124)
@@ -1229,7 +1229,7 @@
}
sub destroy_vm {
- my ($self, $vmid) = @_;
+ my ($storecfg, $vmid) = @_;
my $conffile = config_file ($vmid);
@@ -1247,23 +1247,23 @@
next if !$volid;
next if $volid =~ m|^/|;
- my ($path, $owner) = PVE::Storage::path ($self->{storecfg}, $volid);
+ my ($path, $owner) = PVE::Storage::path ($storecfg, $volid);
next if !$path;
next if !$owner || ($owner != $vmid);
- PVE::Storage::vdisk_free ($self->{storecfg}, $volid);
+ PVE::Storage::vdisk_free ($storecfg, $volid);
}
system ("rm -f '$conffile'");
# also remove unused disk
eval {
- my $dl = PVE::Storage::vdisk_list ($self->{storecfg}, undef, $vmid);
+ my $dl = PVE::Storage::vdisk_list ($storecfg, undef, $vmid);
eval {
PVE::Storage::foreach_volid ($dl, sub {
my ($volid, $sid, $volname, $d) = @_;
- PVE::Storage::vdisk_free ($self->{storecfg}, $volid);
+ PVE::Storage::vdisk_free ($storecfg, $volid);
});
};
warn $@ if $@;
@@ -2474,7 +2474,7 @@
}
sub vm_destroy {
- my ($self, $vmid, $skiplock) = @_;
+ my ($storecfg, $vmid, $skiplock) = @_;
lock_config ($vmid, sub {
@@ -2486,8 +2486,8 @@
eval {
if (!check_running($vmid)) {
- fairsched_rmnod ($vmid); # try to destroy group
- $self->destroy_vm ($vmid);
+ fairsched_rmnod($vmid); # try to destroy group
+ destroy_vm($storecfg, $vmid);
} else {
die "VM is running\n";
}
Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/nqm 2010-09-13 11:00:19 UTC (rev 5124)
@@ -272,6 +272,8 @@
create => [ "PVE::API2::QemuServer", 'create_vm', ['vmid'], { node => $hostname } ],
+ destroy => [ "PVE::API2::QemuServer", 'destroy_vm', ['vmid'], { node => $hostname } ],
+
set => [ "PVE::API2::QemuServer", 'update_vm', ['vmid'], { node => $hostname } ],
config => [ "PVE::API2::QemuServer", 'vm_config', ['vmid'],
Modified: qemu-server/pve2/qm
===================================================================
--- qemu-server/pve2/qm 2010-09-13 10:39:03 UTC (rev 5123)
+++ qemu-server/pve2/qm 2010-09-13 11:00:19 UTC (rev 5124)
@@ -547,7 +547,7 @@
exit (-1);
}
- $qm->vm_destroy ($vmid, $skiplock);
+ PVE::QemuServer::vm_destroy ($qm->{storecfg}, $vmid, $skiplock);
} elsif ($cmd eq 'suspend') {
if (scalar (@ARGV) != 0) {
More information about the pve-devel
mailing list