From 0fe24d95bd80baf45badcda0b62e4e71ad785c17 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Mon, 27 Sep 2010 17:56:50 +0000 Subject: [PATCH] -Port 2.5 fixes for kvm plugin forward git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7671 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/kvm.pm | 40 +++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index b56994287..18772c54d 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -98,6 +98,16 @@ my $vmtab; my $kvmdatatab; +sub get_path_for_pool { + my $poolobj =shift; + my $poolxml = $poolobj->get_xml_description(); + my $pooldom = $parser->parse_string($poolxml); + my @paths = $pooldom->findnodes("/pool/target/path/text()"); + if (scalar @paths != 1) { + return undef; + } + return $paths[0]->data; +} sub build_pool_xml { my $url = shift; my $mounthost = shift; @@ -165,11 +175,13 @@ sub get_storage_pool_by_url { $poolobj->build(); $poolobj->create(); } + $poolobj->refresh(); return $poolobj; } $poolobj = $virtconn->define_storage_pool(build_pool_xml($url,$mounthost)); $poolobj->build(); $poolobj->create(); + $poolobj->refresh(); return $poolobj; } @@ -301,7 +313,9 @@ sub fixbootorder { unless ($currdev and $currdev->getAttribute("dev") eq $_) { $needfixin=1; } - push @oldbootdevs,$currdev; + if ($currdev) { + push @oldbootdevs,$currdev; + } } if (scalar(@bootdevs)) { $needfixin=1; @@ -1150,6 +1164,7 @@ sub invstorage { if ($info{allocation} and $info{capacity}) { $size = $info{allocation}; $size = $size/1048576; #convert to MB + $size = sprintf("%.3f",$size); $size .= "/".($info{capacity}/1048576); } } @@ -1508,8 +1523,15 @@ sub promote_vm_to_master { my $target=$args{target}; my $force=$args{force}; my $detach=$args{detach}; + if ($target !~ m!://!) { #if not a url, use same place as source + my $sourcedir = $confdata->{vm}->{$node}->[0]->{storage}; + $sourcedir =~ s/=.*//; + $sourcedir =~ s/,.*//; + $sourcedir =~ s!/\z!!; + $target = $sourcedir."/".$target; + } unless ($target =~ /^nfs:\/\//) { - xCAT::SvrUtils::sendmsg([1,"KVM plugin only has nfs://// support at this moment"], $callback,$node); + xCAT::SvrUtils::sendmsg([1,"KVM plugin only has nfs://// support for cloning at this moment"], $callback,$node); return; } my $dom; @@ -1532,12 +1554,12 @@ sub promote_vm_to_master { return; } my $parsedxml = $parser->parse_string($xml); - my ($tmpnod) = $parsedxml->findnodes('/domain/uuid/text()'); + my($tmpnod) = $parsedxml->findnodes('/domain/uuid/text()'); if ($tmpnod) { $tmpnod->setData("none"); #get rid of the VM specific uuid } - $target =~ /^(.*)\/([^\/]*)\z/; + $target =~ m!^(.*)/([^/]*)\z!; my $directory=$1; my $mastername=$2; @@ -1580,7 +1602,9 @@ sub promote_vm_to_master { return; } $volclonemap{$filename}=[$sourcevol,$volname]; - $filename =~ s/(.*\/)$node\./$1$mastername\./; + $filename = get_path_for_pool($poolobj); + $filename =~ s!/\z!!; + $filename .= '/'.$volname; $_->setAttribute(file=>$filename); } foreach (keys %volclonemap) { @@ -1695,6 +1719,12 @@ sub clone_vm_from_master { fixup_clone_network(mastername=>$mastername,mastertableentry=>$masteref,kvmmastertableentry=>$kvmmasteref,xmlinprogress=>$newnodexml); #ok, now the fun part, storage... my $disk; + if ($masteref->{storage}) { + foreach (split /,/,$masteref->{storage}) { + s/=.*//; + get_storage_pool_by_url($_); + } + } my $url; if ($confdata->{vm}->{$node}->[0]->{storage}) { unless ($confdata->{vm}->{$node}->[0]->{storage} =~ /^nfs:/) {