From 22a56bdf64a92acc5a89e39afcc4eca1daa5bbbe Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 18 Mar 2009 20:00:51 +0000 Subject: [PATCH] -Implement rpower on for KVM guests where only migrationdest is defined, pick the 'healthiest' looking one git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2937 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/kvm.pm | 53 ++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 8fad57f7c..7d22b7d85 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -343,6 +343,7 @@ sub getrvidparms { sub pick_target { my $node = shift; + my $addmemory = shift; my $target; my $leastusedmemory=undef; my $currentusedmemory; @@ -373,6 +374,9 @@ sub pick_target { $currentusedmemory += $_->get_info()->{memory}; } + if ($addmemory and $addmemory->{$_}) { + $currentusedmemory += $addmemory->{$_}; + } if (not defined ($leastusedmemory)) { $leastusedmemory=$currentusedmemory; $target=$_; @@ -718,9 +722,35 @@ sub preprocess_request { sub adopt { -#TODO: adopt orphans into suitable homes if possible - return 0; + my $orphash = shift; + my $hyphash = shift; + my %hypsethash; + my %addmemory = (); + my $node; + my $target; + foreach $node (keys %{$orphash}) { + $target=pick_target($node,\%addmemory); + unless ($target) { + next; + } + $addmemory{$target}+=getUnits($vmhash->{$node}->[0]->{memory},"M",1024); + $hyphash{$target}->{nodes}->{$node}=1; + delete $orphash->{$node}; + push @{$hypsethash{$target}},$node; + } + foreach (keys %hypsethash) { + $vmtab->setNodesAttribs($hypsethash{$_},{'host'=>$_}); + } + if (keys %{$orphash}) { + return 0; + } else { + return 1; + } } + +#TODO: adopt orphans into suitable homes if possible +# return 0; +#} sub grab_table_data{ #grab table data relevent to VM guest nodes my $noderange=shift; @@ -788,7 +818,7 @@ sub process_request { }; } unless ($hypconn) { - $callback->({node=>[{name=>[$_],error=>["Cannot communicate BC via libvirt to node"]}]}); + $callback->({node=>[{name=>[$_],error=>["Cannot communicate via libvirt to node"]}]}); next; } foreach ($hypconn->list_domains()) { @@ -831,12 +861,17 @@ sub process_request { } } if (keys %orphans) { - if ($command eq "rpower" and (grep /^on$/,@exargs or grep /^boot$/,@exargs)) { - unless (adopt(\%orphans,\%hyphash)) { - $callback->({error=>"Can't find ".join(",",keys %orphans),errorcode=>[1]}); - return 1; + if ($command eq "rpower") { + if (grep /^on$/,@exargs or grep /^boot$/,@exargs) { + unless (adopt(\%orphans,\%hyphash)) { + $callback->({error=>"Can't find ".join(",",keys %orphans),errorcode=>[1]}); + return 1; + } + } else { + foreach (keys %orphans) { + $callback->({node=>[{name=>[$_],data=>[{contents=>['off']}]}]}); + } } - } elsif ($command eq "rmigrate") { $callback->({error=>"Can't find ".join(",",keys %orphans),errorcode=>[1]}); return; @@ -1026,7 +1061,7 @@ sub dohyp { unless ($hypconn) { my %err=(node=>[]); foreach (keys %{$hyphash{$hyp}->{nodes}}) { - push (@{$err{node}},{name=>[$_],error=>["Cannot communicate AB via libvirt to $hyp"],errorcode=>[1]}); + push (@{$err{node}},{name=>[$_],error=>["Cannot communicate via libvirt to $hyp"],errorcode=>[1]}); } print $out freeze([\%err]); print $out "\nENDOFFREEZE6sK4ci\n";