From 80bcccc1ebbc3c23403741aa953da018a415b80b Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 31 Aug 2010 16:11:36 +0000 Subject: [PATCH] -Implement detach in clonevm -b for kvm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7322 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/kvm.pm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index b10009545..4b6fda72f 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -1603,13 +1603,14 @@ sub clonevm { if ($target) { #we need to take a single vm and create a master out of it return promote_vm_to_master(target=>$target,force=>$force,detach=>$detach); } elsif ($base) { - return clone_vm_from_master(base=>$base); + return clone_vm_from_master(base=>$base,detach=>$detach); } } sub clone_vm_from_master { my %args = @_; my $base=$args{base}; + my $detach=$args{detach}; my $vmmastertab=xCAT::Table->new('vmmaster',-create=>0); my $kvmmastertab = xCAT::Table->new('kvm_masterdata',-create=>0); unless ($vmmastertab and $kvmmastertab) { @@ -1653,8 +1654,19 @@ sub clone_vm_from_master { $filename =~ s/^.*$mastername/$node/; $filename =~ m!\.([^\.]*)\z!; my $format=$1; - my $newbasexml="$filename0$srcfilename"; - my $newvol = $destinationpool->create_volume($newbasexml); + my $newvol; + if ($detach) { + my $sourcevol = $hypconn->get_volume_by_path($srcfilename); + my %sourceinfo = %{$sourcevol->get_info()}; + my $targxml = "$filename".$sourceinfo{capacity}.""; + xCAT::SvrUtils::sendmsg("Cloning ".$sourcevol->get_name()." (currently is ".($sourceinfo{allocation}/1048576)." MB and has a capacity of ".($sourceinfo{capacity}/1048576)."MB)",$callback,$node); + eval { + $newvol =$destinationpool->clone_volume($targxml,$sourcevol); + }; + } else { + my $newbasexml="$filename0$srcfilename"; + $newvol = $destinationpool->create_volume($newbasexml); + } my $newfilename=$newvol->get_path(); $disk->findnodes("./source")->[0]->setAttribute("file"=>$newfilename); }