From 3c36626195c3e69d70517621edb1d52a37d768bb Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 21 Jul 2010 20:33:50 +0000 Subject: [PATCH] -Add chvm -p support to kvm (can't do scsi here..) git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6821 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/kvm.pm | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 5848de6f3..ed8c4a911 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -897,7 +897,57 @@ sub chvm { $dom->attach_device($xml); } } + } elsif (@purge) { + my $dom = $hypconn->get_domain_by_name($node); + my $vmxml=$dom->get_xml_description(); + my $currstate=getpowstate($dom); + foreach (get_disks_by_userspecs(\@purge,$vmxml)) { + my $devxml=$_->[0]; + my $file=$_->[1]; + $file =~ m!/([^/]*)/($node\..*)\z!; + my $pooluuid=$1; + my $volname=$2; + #first, detach the device. + eval { + if ($currstate eq 'on') { $dom->detach_device($devxml); } + }; + if ($@) { + sendmsg([1,"Unable to remove device"],$node); + } else { + #if that worked, remove the disk.. + my $pool = $hypconn->get_storage_pool_by_uuid($pooluuid); + if ($pool) { + my $vol = $pool->get_volume_by_name($volname); + if ($vol) { + $vol->delete(); + } + } + + } + + } } + +} +sub get_disks_by_userspecs { + my $specs = shift; + my $xml = shift; + my $struct = XMLin($xml); + my @returnxmls; + foreach my $spec (@$specs) { + foreach (@{$struct->{devices}->{disk}}) { + if ($spec =~ /^.d./) { #vda, hdb, sdc, etc, match be equality to target->{dev} + if ($_->{target}->{dev} eq $spec) { + push @returnxmls,[XMLout($_,RootName=>'disk'),$_->{source}->{file}]; + } + } elsif ($spec =~ /^d(.*)/) { #delete by scsi unit number.. + if ($_->{address}->{unit} == $1) { + push @returnxmls,[XMLout($_,RootName=>"disk"),$_->{source}->{file}]; + } + } #other formats TBD + } + } + return @returnxmls; } sub mkvm {