2008-07-28 13:48:15 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::xen;
|
2008-09-25 03:04:56 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use xCAT::GlobalDef;
|
2008-11-09 03:30:54 +00:00
|
|
|
use xCAT::NodeRange;
|
2008-09-25 03:04:56 +00:00
|
|
|
use xCAT_monitoring::monitorctrl;
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
use xCAT::Table;
|
|
|
|
use XML::Simple qw(XMLout);
|
|
|
|
use Thread qw(yield);
|
|
|
|
use IO::Socket;
|
2008-07-30 18:19:57 +00:00
|
|
|
use IO::Select;
|
2008-07-28 13:48:15 +00:00
|
|
|
use strict;
|
|
|
|
#use warnings;
|
|
|
|
my %vm_comm_pids;
|
2008-11-09 03:30:54 +00:00
|
|
|
my @destblacklist;
|
2008-07-30 18:19:57 +00:00
|
|
|
my $vmhash;
|
2008-07-31 17:32:39 +00:00
|
|
|
my $hmhash;
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
use XML::Simple;
|
2009-07-30 19:42:29 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
2008-07-28 13:48:15 +00:00
|
|
|
use Data::Dumper;
|
|
|
|
use POSIX "WNOHANG";
|
|
|
|
use Storable qw(freeze thaw);
|
|
|
|
use IO::Select;
|
|
|
|
use IO::Handle;
|
|
|
|
use Time::HiRes qw(gettimeofday sleep);
|
|
|
|
use xCAT::DBobjUtils;
|
|
|
|
use Getopt::Long;
|
2009-03-20 21:36:49 +00:00
|
|
|
use xCAT::SvrUtils;
|
2008-07-28 13:48:15 +00:00
|
|
|
|
2008-07-30 00:00:36 +00:00
|
|
|
my %runningstates;
|
2008-11-09 03:30:54 +00:00
|
|
|
my $vmmaxp=64;
|
2008-07-28 21:45:59 +00:00
|
|
|
my $mactab;
|
2008-07-29 23:32:00 +00:00
|
|
|
my $nrtab;
|
2008-07-28 21:45:59 +00:00
|
|
|
my $machash;
|
2008-10-03 19:05:59 +00:00
|
|
|
my $status_noop="XXXno-opXXX";
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
sub handled_commands {
|
2008-11-09 03:30:54 +00:00
|
|
|
#unless ($libvirtsupport) {
|
|
|
|
# return {};
|
|
|
|
#}
|
2008-07-28 13:48:15 +00:00
|
|
|
return {
|
|
|
|
rpower => 'nodehm:power,mgt',
|
2009-02-21 12:55:57 +00:00
|
|
|
mkvm => 'nodehm:power,mgt',
|
2008-07-30 18:19:57 +00:00
|
|
|
rmigrate => 'nodehm:mgt',
|
2008-08-12 17:15:48 +00:00
|
|
|
getxencons => 'nodehm:mgt',
|
2008-07-28 13:48:15 +00:00
|
|
|
#rvitals => 'nodehm:mgt',
|
|
|
|
#rinv => 'nodehm:mgt',
|
2008-12-11 19:37:14 +00:00
|
|
|
getrvidparms => 'nodehm:mgt',
|
2008-07-28 13:48:15 +00:00
|
|
|
rbeacon => 'nodehm:mgt',
|
2009-10-19 18:16:07 +00:00
|
|
|
revacuate => 'hypervisor:type',
|
2008-07-28 13:48:15 +00:00
|
|
|
#rspreset => 'nodehm:mgt',
|
|
|
|
#rspconfig => 'nodehm:mgt',
|
|
|
|
#rbootseq => 'nodehm:mgt',
|
|
|
|
#reventlog => 'nodehm:mgt',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
my $virsh;
|
|
|
|
my $vmhash;
|
|
|
|
my $hypconn;
|
|
|
|
my $hyp;
|
|
|
|
my $doreq;
|
|
|
|
my %hyphash;
|
|
|
|
my $node;
|
2008-07-31 17:32:39 +00:00
|
|
|
my $hmtab;
|
2008-07-30 03:10:08 +00:00
|
|
|
my $vmtab;
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
sub waitforack {
|
|
|
|
my $sock = shift;
|
|
|
|
my $select = new IO::Select;
|
|
|
|
$select->add($sock);
|
|
|
|
my $str;
|
2009-04-03 19:12:56 +00:00
|
|
|
if ($select->can_read(60)) { # Continue after 10 seconds, even if not acked...
|
2008-07-28 13:48:15 +00:00
|
|
|
if ($str = <$sock>) {
|
|
|
|
} else {
|
|
|
|
$select->remove($sock); #Block until parent acks data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub build_oshash {
|
|
|
|
my %rethash;
|
|
|
|
$rethash{type}->{content}='hvm';
|
|
|
|
$rethash{loader}->{content}='/usr/lib/xen/boot/hvmloader';
|
2008-12-08 14:51:52 +00:00
|
|
|
if (defined $vmhash->{$node}->[0]->{bootorder}) {
|
|
|
|
my $bootorder = $vmhash->{$node}->[0]->{bootorder};
|
2009-03-18 18:59:41 +00:00
|
|
|
my @bootdevs = split(/[:,]/,$bootorder);
|
2008-12-08 14:51:52 +00:00
|
|
|
my $bootnum = 0;
|
|
|
|
foreach (@bootdevs) {
|
|
|
|
$rethash{boot}->[$bootnum]->{dev}=$_;
|
|
|
|
$bootnum++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$rethash{boot}->[0]->{dev}='network';
|
|
|
|
$rethash{boot}->[1]->{dev}='hd';
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
return \%rethash;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub build_diskstruct {
|
2008-08-20 16:48:23 +00:00
|
|
|
my @returns=();
|
|
|
|
my $currdev;
|
|
|
|
my @suffixes=('a'..'z');
|
|
|
|
my $suffidx=0;
|
|
|
|
if (defined $vmhash->{$node}->[0]->{storage}) {
|
|
|
|
my $disklocs=$vmhash->{$node}->[0]->{storage};
|
|
|
|
my @locations=split /\|/,$disklocs;
|
2008-12-09 15:43:40 +00:00
|
|
|
foreach my $disk (@locations) {
|
2008-12-08 14:51:52 +00:00
|
|
|
#Setting default values of a virtual disk backed by a file at hd*.
|
2009-01-19 13:48:12 +00:00
|
|
|
my $diskhash;
|
2008-12-08 14:51:52 +00:00
|
|
|
$diskhash->{type} = 'file';
|
|
|
|
$diskhash->{device} = 'disk';
|
2008-12-09 15:43:40 +00:00
|
|
|
$diskhash->{target}->{dev} = 'hd'.$suffixes[$suffidx];
|
2008-12-08 14:51:52 +00:00
|
|
|
|
|
|
|
my @disk_parts = split(/,/, $disk);
|
|
|
|
#Find host file and determine if it is a file or a block device.
|
|
|
|
if (substr($disk_parts[0], 0, 4) eq 'phy:') {
|
2008-11-04 22:06:53 +00:00
|
|
|
$diskhash->{type}='block';
|
2008-12-08 14:51:52 +00:00
|
|
|
$diskhash->{source}->{dev} = substr($disk_parts[0], 4);
|
2008-10-31 13:30:00 +00:00
|
|
|
} else {
|
2008-12-09 15:43:40 +00:00
|
|
|
$diskhash->{source}->{file} = $disk_parts[0];
|
2008-10-31 13:30:00 +00:00
|
|
|
}
|
2008-12-08 14:51:52 +00:00
|
|
|
|
|
|
|
#See if there are any other options. If not, increment suffidx because the already determined device node was used.
|
|
|
|
if (@disk_parts gt 1) {
|
|
|
|
my @disk_opts = split(/:/, $disk_parts[1]);
|
|
|
|
if ($disk_opts[0] ne '') {
|
|
|
|
$diskhash->{target}->{dev} = $disk_opts[0];
|
|
|
|
} else {
|
|
|
|
$suffidx++;
|
|
|
|
}
|
|
|
|
if ($disk_opts[1] eq 'cdrom') {
|
|
|
|
$diskhash->{device}='cdrom';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$suffidx++;
|
|
|
|
}
|
|
|
|
|
2008-08-20 16:48:23 +00:00
|
|
|
push @returns,$diskhash;
|
|
|
|
}
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
return \@returns;
|
|
|
|
}
|
|
|
|
sub getNodeUUID {
|
|
|
|
my $node = shift;
|
|
|
|
return xCAT::Utils::genUUID();
|
|
|
|
}
|
|
|
|
sub build_nicstruct {
|
|
|
|
my $rethash;
|
2008-07-28 21:45:59 +00:00
|
|
|
my $node = shift;
|
|
|
|
my @macs=();
|
2008-07-29 23:32:00 +00:00
|
|
|
if ($machash->{$node}->[0]->{mac}) {
|
|
|
|
my $macdata=$machash->{$node}->[0]->{mac};
|
|
|
|
foreach my $macaddr (split /\|/,$macdata) {
|
|
|
|
$macaddr =~ s/\!.*//;
|
2008-07-28 21:45:59 +00:00
|
|
|
push @macs,$macaddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless (scalar(@macs)) {
|
|
|
|
my $allbutmult = 65279; # & mask for bitwise clearing of the multicast bit of mac
|
|
|
|
my $localad=512; # | to set the bit for locally admnistered mac address
|
|
|
|
my $leading=int(rand(65535));
|
|
|
|
$leading=$leading|512;
|
|
|
|
$leading=$leading&65279;
|
|
|
|
my $n=inet_aton($node);
|
|
|
|
my $tail;
|
|
|
|
if ($n) {
|
|
|
|
$tail=unpack("N",$n);
|
|
|
|
}
|
|
|
|
unless ($tail) {
|
|
|
|
$tail=int(rand(4294967295));
|
|
|
|
}
|
|
|
|
my $macstr = sprintf("%04x%08x",$leading,$tail);
|
|
|
|
$macstr =~ s/(..)(..)(..)(..)(..)(..)/$1:$2:$3:$4:$5:$6/;
|
2008-07-29 23:32:00 +00:00
|
|
|
$mactab->setNodeAttribs($node,{mac=>$macstr});
|
|
|
|
$nrtab->setNodeAttribs($node,{netboot=>'pxe'});
|
|
|
|
$doreq->({command=>['makedhcp'],node=>[$node]});
|
2008-07-28 21:45:59 +00:00
|
|
|
push @macs,$macstr;
|
|
|
|
}
|
|
|
|
my @rethashes;
|
|
|
|
foreach (@macs) {
|
|
|
|
my $rethash;
|
|
|
|
$rethash->{type}='bridge';
|
|
|
|
$rethash->{mac}->{address}=$_;
|
2009-02-21 12:55:57 +00:00
|
|
|
$rethash->{source}->{bridge}='xenbr0';
|
2008-07-28 21:45:59 +00:00
|
|
|
push @rethashes,$rethash;
|
|
|
|
}
|
|
|
|
return \@rethashes;
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
2008-08-19 17:40:24 +00:00
|
|
|
sub getUnits {
|
|
|
|
my $amount = shift;
|
|
|
|
my $defunit = shift;
|
|
|
|
my $divisor=shift;
|
|
|
|
unless ($divisor) {
|
|
|
|
$divisor = 1;
|
|
|
|
}
|
|
|
|
if ($amount =~ /(\D)$/) { #If unitless, add unit
|
|
|
|
$defunit=$1;
|
|
|
|
chop $amount;
|
|
|
|
}
|
|
|
|
if ($defunit =~ /k/i) {
|
|
|
|
return $amount*1024/$divisor;
|
|
|
|
} elsif ($defunit =~ /m/i) {
|
|
|
|
return $amount*1048576/$divisor;
|
|
|
|
} elsif ($defunit =~ /g/i) {
|
|
|
|
return $amount*1073741824/$divisor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
sub build_xmldesc {
|
|
|
|
my $node = shift;
|
|
|
|
my %xtree=();
|
|
|
|
$xtree{type}='xen';
|
|
|
|
$xtree{name}->{content}=$node;
|
|
|
|
$xtree{uuid}->{content}=getNodeUUID($node);
|
|
|
|
$xtree{os} = build_oshash();
|
2008-08-19 17:40:24 +00:00
|
|
|
if (defined $vmhash->{$node}->[0]->{memory}) {
|
|
|
|
$xtree{memory}->{content}=getUnits($vmhash->{$node}->[0]->{memory},"M",1024);
|
|
|
|
} else {
|
|
|
|
$xtree{memory}->{content}=524288;
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
$xtree{vcpu}->{content}=1;
|
|
|
|
$xtree{features}->{pae}={};
|
|
|
|
$xtree{features}->{acpi}={};
|
|
|
|
$xtree{features}->{apic}={};
|
|
|
|
$xtree{features}->{content}="\n";
|
|
|
|
$xtree{devices}->{emulator}->{content}='/usr/lib64/xen/bin/qemu-dm';
|
|
|
|
$xtree{devices}->{disk}=build_diskstruct();
|
2008-07-28 21:45:59 +00:00
|
|
|
$xtree{devices}->{interface}=build_nicstruct($node);
|
2008-07-28 13:48:15 +00:00
|
|
|
$xtree{devices}->{graphics}->{type}='vnc';
|
2008-07-28 21:45:59 +00:00
|
|
|
$xtree{devices}->{console}->{type}='pty';
|
|
|
|
$xtree{devices}->{console}->{target}->{port}='1';
|
2008-07-29 23:32:00 +00:00
|
|
|
return XMLout(\%xtree,RootName=>"domain");
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 03:10:08 +00:00
|
|
|
sub refresh_vm {
|
|
|
|
my $dom = shift;
|
|
|
|
|
|
|
|
my $newxml=XMLin($dom->get_xml_description());
|
|
|
|
my $vncport=$newxml->{devices}->{graphics}->{port};
|
|
|
|
my $stty=$newxml->{devices}->{console}->{tty};
|
|
|
|
$vmtab->setNodeAttribs($node,{vncport=>$vncport,textconsole=>$stty});
|
2008-07-30 18:46:11 +00:00
|
|
|
return {vncport=>$vncport,textconsole=>$stty};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getvmcons {
|
|
|
|
my $node = shift();
|
|
|
|
my $type = shift();
|
|
|
|
my $dom;
|
|
|
|
eval {
|
|
|
|
$dom = $hypconn->get_domain_by_name($node);
|
|
|
|
};
|
|
|
|
unless ($dom) {
|
|
|
|
return 1,"Unable to query running VM";
|
|
|
|
}
|
|
|
|
my $consdata=refresh_vm($dom);
|
|
|
|
my $hyper=$vmhash->{$node}->[0]->{host};
|
2008-07-31 17:32:39 +00:00
|
|
|
|
2008-07-30 18:46:11 +00:00
|
|
|
if ($type eq "text") {
|
2008-07-31 17:32:39 +00:00
|
|
|
my $serialspeed;
|
|
|
|
if ($hmhash) {
|
|
|
|
$serialspeed=$hmhash->{$node}->[0]->{serialspeed};
|
|
|
|
}
|
2008-08-12 17:15:48 +00:00
|
|
|
my $sconsparms = {node=>[{name=>[$node]}]};
|
|
|
|
$sconsparms->{node}->[0]->{sshhost}=[$hyper];
|
|
|
|
$sconsparms->{node}->[0]->{psuedotty}=[$consdata->{textconsole}];
|
|
|
|
$sconsparms->{node}->[0]->{baudrate}=[$serialspeed];
|
|
|
|
return (0,$sconsparms);
|
2008-07-30 18:46:11 +00:00
|
|
|
} elsif ($type eq "vnc") {
|
2008-12-11 19:37:14 +00:00
|
|
|
my $domdata=`ssh $hyper xm list $node -l`;
|
|
|
|
my @domlines = split /\n/,$domdata;
|
|
|
|
my $foundvfb=0;
|
|
|
|
my $vnclocation;
|
|
|
|
foreach (@domlines) {
|
|
|
|
if (/\(vfb/) {
|
|
|
|
$foundvfb=1;
|
|
|
|
}
|
|
|
|
if ($foundvfb and /location\s+([^\)]+)/) {
|
|
|
|
$vnclocation=$1;
|
|
|
|
$foundvfb=0;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0,'ssh+vnc@'.$hyper.": ".$vnclocation); #$consdata->{vncport});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sub getrvidparms {
|
|
|
|
my $node=shift;
|
|
|
|
my $location = getvmcons($node,"vnc");
|
|
|
|
if ($location =~ /ssh\+vnc@([^:]*):([^:]*):(\d+)/) {
|
|
|
|
my @output = (
|
|
|
|
"method: xen",
|
|
|
|
"server: $1",
|
|
|
|
"vncdisplay: $2:$3",
|
|
|
|
);
|
|
|
|
return 0,@output;
|
|
|
|
} else {
|
|
|
|
return (1,"Error: Unable to determine rvid destination for $node");
|
2008-07-30 18:46:11 +00:00
|
|
|
}
|
2008-07-30 03:10:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-09 03:30:54 +00:00
|
|
|
sub pick_target {
|
|
|
|
my $node = shift;
|
|
|
|
my $target;
|
|
|
|
my $leastusedmemory=undef;
|
|
|
|
my $currentusedmemory;
|
|
|
|
my $candidates= $vmhash->{$node}->[0]->{migrationdest};
|
|
|
|
my $currhyp=$vmhash->{$node}->[0]->{host};
|
|
|
|
unless ($candidates) {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
print "$node with $candidates\n";
|
|
|
|
foreach (noderange($candidates)) {
|
|
|
|
my $targconn;
|
|
|
|
my $cand=$_;
|
|
|
|
$currentusedmemory=0;
|
|
|
|
if ($_ eq $currhyp) { next; } #skip current node
|
|
|
|
if (grep { "$_" eq $cand } @destblacklist) { print "$_ was blacklisted\n"; next; } #skip blacklisted destinations
|
|
|
|
print "maybe $_\n";
|
2009-01-31 23:51:31 +00:00
|
|
|
eval { #Sys::Virt has bugs that cause it to die out in weird ways some times, contain it here
|
2009-02-11 14:14:18 +00:00
|
|
|
$targconn = Sys::Virt->new(uri=>"xen+ssh://".$_."?no_tty=1&netcat=nc");
|
2009-01-31 23:51:31 +00:00
|
|
|
};
|
2009-02-11 14:14:18 +00:00
|
|
|
unless ($targconn) {
|
|
|
|
eval { #Sys::Virt has bugs that cause it to die out in weird ways some times, contain it here
|
|
|
|
$targconn = Sys::Virt->new(uri=>"xen+ssh://".$_."?no_tty=1");
|
|
|
|
};
|
|
|
|
}
|
2008-11-09 03:30:54 +00:00
|
|
|
unless ($targconn) { next; } #skip unreachable destinations
|
|
|
|
foreach ($targconn->list_domains()) {
|
|
|
|
if ($_->get_name() eq 'Domain-0') { next; } #Dom0 memory usage is elastic, we are interested in HVM DomU memory, which is inelastic
|
|
|
|
|
|
|
|
$currentusedmemory += $_->get_info()->{memory};
|
|
|
|
}
|
|
|
|
if (not defined ($leastusedmemory)) {
|
|
|
|
$leastusedmemory=$currentusedmemory;
|
|
|
|
$target=$_;
|
|
|
|
} elsif ($currentusedmemory < $leastusedmemory) {
|
|
|
|
$leastusedmemory=$currentusedmemory;
|
|
|
|
$target=$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 18:19:57 +00:00
|
|
|
sub migrate {
|
|
|
|
my $node = shift();
|
|
|
|
my $targ = shift();
|
2008-11-09 03:30:54 +00:00
|
|
|
unless ($targ) {
|
|
|
|
$targ = pick_target($node);
|
|
|
|
}
|
2009-02-01 00:23:52 +00:00
|
|
|
unless ($targ) {
|
|
|
|
return (1,"Unable to identify a suitable target host for guest $node");
|
|
|
|
}
|
2008-07-30 18:19:57 +00:00
|
|
|
my $prevhyp;
|
2009-01-31 19:51:04 +00:00
|
|
|
my $target = "xen+ssh://".$targ."?no_tty=1";
|
2008-07-30 18:19:57 +00:00
|
|
|
my $currhyp="xen+ssh://";
|
|
|
|
if ($vmhash->{$node}->[0]->{host}) {
|
|
|
|
$prevhyp=$vmhash->{$node}->[0]->{host};
|
|
|
|
$currhyp.=$prevhyp;
|
|
|
|
} else {
|
2008-08-19 17:40:24 +00:00
|
|
|
return (1,"Unable to find current location of $node");
|
2008-07-30 18:19:57 +00:00
|
|
|
}
|
2009-01-31 19:51:04 +00:00
|
|
|
$currhyp.="?no_tty=1";
|
2009-01-29 23:07:32 +00:00
|
|
|
if ($currhyp eq $target) {
|
|
|
|
return (0,"Guest is already on host $targ");
|
|
|
|
}
|
2009-02-01 00:23:52 +00:00
|
|
|
my $testhypconn;
|
2009-02-11 14:14:18 +00:00
|
|
|
my $srcnetcatadd="&netcat=nc";
|
2009-02-01 00:23:52 +00:00
|
|
|
eval {#Contain Sys::Virt bugs
|
2009-02-11 14:14:18 +00:00
|
|
|
$testhypconn= Sys::Virt->new(uri=>"xen+ssh://".$prevhyp."?no_tty=1$srcnetcatadd");
|
2009-02-01 00:23:52 +00:00
|
|
|
};
|
2009-02-11 14:14:18 +00:00
|
|
|
unless ($testhypconn) {
|
|
|
|
$srcnetcatadd="";
|
|
|
|
eval {#Contain Sys::Virt bugs
|
|
|
|
$testhypconn= Sys::Virt->new(uri=>"xen+ssh://".$prevhyp."?no_tty=1");
|
|
|
|
};
|
|
|
|
}
|
2009-02-01 00:23:52 +00:00
|
|
|
unless ($testhypconn) {
|
|
|
|
return (1,"Unable to reach $prevhyp to perform operation of $node, use nodech to change vm.host if certain of no split-brain possibility exists");
|
|
|
|
}
|
2009-02-17 21:07:20 +00:00
|
|
|
undef $testhypconn;
|
2009-02-21 12:55:57 +00:00
|
|
|
my $destnetcatadd="&netcat=nc";
|
2009-02-11 14:14:18 +00:00
|
|
|
eval {#Contain Sys::Virt bugs
|
|
|
|
$testhypconn= Sys::Virt->new(uri=>$target.$destnetcatadd);
|
|
|
|
};
|
|
|
|
unless ($testhypconn) {
|
|
|
|
$destnetcatadd="";
|
|
|
|
eval {#Contain Sys::Virt bugs
|
|
|
|
$testhypconn= Sys::Virt->new(uri=>$target);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
unless ($testhypconn) {
|
|
|
|
return (1,"Unable to reach $targ to perform operation of $node, destination unusable.");
|
|
|
|
}
|
2008-07-30 18:19:57 +00:00
|
|
|
my $sock = IO::Socket::INET->new(Proto=>'udp');
|
|
|
|
my $ipa=inet_aton($node);
|
|
|
|
my $pa=sockaddr_in(7,$ipa); #UDP echo service, not needed to be actually
|
2009-01-31 23:51:31 +00:00
|
|
|
#serviced, we just want to trigger MAC move in the switch forwarding dbs
|
2009-02-17 21:07:20 +00:00
|
|
|
my $rc=system("virsh -c '$currhyp".$srcnetcatadd."' migrate --live $node '$target"."$destnetcatadd'");
|
2008-07-30 18:19:57 +00:00
|
|
|
system("arp -d $node"); #Make ethernet fabric take note of change
|
2009-01-31 23:51:31 +00:00
|
|
|
send($sock,"dummy",0,$pa); #UDP packet to force forwarding table update in switches, ideally a garp happened, but just in case...
|
2008-07-30 18:19:57 +00:00
|
|
|
if ($rc) {
|
|
|
|
return (1,"Failed migration from $prevhyp to $targ");
|
|
|
|
} else {
|
2008-11-07 14:11:05 +00:00
|
|
|
$vmtab->setNodeAttribs($node,{host=>$targ});
|
2009-02-01 00:23:52 +00:00
|
|
|
my $newhypconn;
|
|
|
|
eval {#Contain Sys::Virt bugs
|
2009-02-11 14:14:18 +00:00
|
|
|
$newhypconn= Sys::Virt->new(uri=>"xen+ssh://".$targ."?no_tty=1&netcat=nc");
|
2009-02-01 00:23:52 +00:00
|
|
|
};
|
2009-02-11 14:14:18 +00:00
|
|
|
unless ($newhypconn) {
|
|
|
|
eval {#Contain Sys::Virt bugs
|
|
|
|
$newhypconn= Sys::Virt->new(uri=>"xen+ssh://".$targ."?no_tty=1");
|
|
|
|
};
|
|
|
|
}
|
2009-02-01 00:23:52 +00:00
|
|
|
if ($newhypconn) {
|
|
|
|
my $dom;
|
|
|
|
eval {
|
|
|
|
$dom = $newhypconn->get_domain_by_name($node);
|
|
|
|
};
|
|
|
|
if ($dom) {
|
|
|
|
refresh_vm($dom);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (0,"migrated to $targ");
|
|
|
|
}
|
2008-07-30 18:19:57 +00:00
|
|
|
return (0,"migrated to $targ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 03:10:08 +00:00
|
|
|
sub getpowstate {
|
|
|
|
my $dom = shift;
|
|
|
|
my $vmstat;
|
|
|
|
if ($dom) {
|
|
|
|
$vmstat = $dom->get_info;
|
|
|
|
}
|
|
|
|
if ($vmstat and $runningstates{$vmstat->{state}}) {
|
|
|
|
return "on";
|
|
|
|
} else {
|
|
|
|
return "off";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 14:04:56 +00:00
|
|
|
sub makedom {
|
|
|
|
my $node=shift;
|
|
|
|
my $dom;
|
|
|
|
my $xml=build_xmldesc($node);
|
|
|
|
my $errstr;
|
|
|
|
eval { $dom=$hypconn->create_domain($xml); };
|
|
|
|
if ($@) { $errstr = $@; }
|
|
|
|
if (ref $errstr) {
|
|
|
|
$errstr = ":".$errstr->{message};
|
|
|
|
}
|
|
|
|
if ($errstr) { return (undef,$errstr); }
|
|
|
|
if ($dom) {
|
|
|
|
refresh_vm($dom);
|
|
|
|
}
|
2009-01-16 21:13:15 +00:00
|
|
|
return $dom,undef;
|
2009-01-16 14:04:56 +00:00
|
|
|
}
|
2008-12-11 19:37:14 +00:00
|
|
|
|
|
|
|
|
2009-02-21 12:55:57 +00:00
|
|
|
sub mkvm {
|
|
|
|
build_xmldesc($node);
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
sub power {
|
|
|
|
my $subcommand = shift;
|
2008-07-30 03:10:08 +00:00
|
|
|
my $retstring;
|
2008-07-30 00:00:36 +00:00
|
|
|
my $dom;
|
2008-07-30 03:10:08 +00:00
|
|
|
eval {
|
|
|
|
$dom = $hypconn->get_domain_by_name($node);
|
|
|
|
};
|
|
|
|
if ($subcommand eq "boot") {
|
|
|
|
my $currstate=getpowstate($dom);
|
|
|
|
$retstring=$currstate." ";
|
|
|
|
if ($currstate eq "off") {
|
|
|
|
$subcommand="on";
|
|
|
|
} elsif ($currstate eq "on") {
|
|
|
|
$subcommand="reset";
|
|
|
|
}
|
|
|
|
}
|
2009-01-16 14:04:56 +00:00
|
|
|
my $errstr;
|
2008-07-28 13:48:15 +00:00
|
|
|
if ($subcommand eq 'on') {
|
2008-07-30 03:10:08 +00:00
|
|
|
unless ($dom) {
|
2009-01-19 13:48:12 +00:00
|
|
|
($dom,$errstr) = makedom($node);
|
2008-07-30 15:24:29 +00:00
|
|
|
if ($errstr) { return (1,$errstr); }
|
2008-10-03 19:05:59 +00:00
|
|
|
} else {
|
|
|
|
$retstring .= " $status_noop";
|
2008-07-30 03:10:08 +00:00
|
|
|
}
|
2008-07-30 00:00:36 +00:00
|
|
|
} elsif ($subcommand eq 'off') {
|
|
|
|
if ($dom) {
|
|
|
|
$dom->destroy();
|
2008-10-03 19:05:59 +00:00
|
|
|
} else { $retstring .= " $status_noop"; }
|
2008-07-30 03:10:08 +00:00
|
|
|
} elsif ($subcommand eq 'softoff') {
|
|
|
|
if ($dom) {
|
|
|
|
$dom->shutdown();
|
2008-10-03 19:05:59 +00:00
|
|
|
} else { $retstring .= " $status_noop"; }
|
2008-08-28 13:20:25 +00:00
|
|
|
} elsif ($subcommand eq 'reset') {
|
|
|
|
if ($dom) {
|
2009-01-16 14:04:56 +00:00
|
|
|
$dom->destroy();
|
2009-01-19 13:48:12 +00:00
|
|
|
($dom,$errstr) = makedom($node);
|
2009-01-16 14:04:56 +00:00
|
|
|
if ($errstr) { return (1,$errstr); }
|
2008-08-28 13:20:25 +00:00
|
|
|
$retstring.="reset";
|
2008-10-03 19:05:59 +00:00
|
|
|
} else { $retstring .= " $status_noop"; }
|
2008-07-30 03:10:08 +00:00
|
|
|
} else {
|
|
|
|
unless ($subcommand =~ /^stat/) {
|
|
|
|
return (1,"Unsupported power directive '$subcommand'");
|
|
|
|
}
|
2008-07-30 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2008-08-28 13:20:25 +00:00
|
|
|
unless ($retstring =~ /reset/) {
|
2008-11-04 22:06:53 +00:00
|
|
|
$retstring=getpowstate($dom).$retstring;
|
2008-08-28 13:20:25 +00:00
|
|
|
}
|
2008-07-30 03:10:08 +00:00
|
|
|
return (0,$retstring);
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub guestcmd {
|
|
|
|
$hyp = shift;
|
|
|
|
$node = shift;
|
|
|
|
my $command = shift;
|
|
|
|
my @args = @_;
|
|
|
|
my $error;
|
|
|
|
if ($command eq "rpower") {
|
|
|
|
return power(@args);
|
2009-02-21 12:55:57 +00:00
|
|
|
} elsif ($command eq "mkvm") {
|
|
|
|
return mkvm();
|
2008-07-30 18:19:57 +00:00
|
|
|
} elsif ($command eq "rmigrate") {
|
|
|
|
return migrate($node,@args);
|
2008-12-11 19:37:14 +00:00
|
|
|
} elsif ($command eq "getrvidparms") {
|
|
|
|
return getrvidparms($node,@args);
|
2008-08-12 17:15:48 +00:00
|
|
|
} elsif ($command eq "getxencons") {
|
2008-07-30 18:46:11 +00:00
|
|
|
return getvmcons($node,@args);
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
=cut
|
|
|
|
} elsif ($command eq "rvitals") {
|
|
|
|
return vitals(@args);
|
|
|
|
} elsif ($command =~ /r[ms]preset/) {
|
|
|
|
return resetmp(@args);
|
|
|
|
} elsif ($command eq "rspconfig") {
|
|
|
|
return mpaconfig($mpa,$user,$pass,$node,$slot,@args);
|
|
|
|
} elsif ($command eq "rbootseq") {
|
|
|
|
return bootseq(@args);
|
|
|
|
} elsif ($command eq "switchblade") {
|
|
|
|
return switchblade(@args);
|
|
|
|
} elsif ($command eq "getmacs") {
|
|
|
|
return getmacs(@args);
|
|
|
|
} elsif ($command eq "rinv") {
|
|
|
|
return inv(@args);
|
|
|
|
} elsif ($command eq "reventlog") {
|
|
|
|
return eventlog(@args);
|
|
|
|
} elsif ($command eq "rscan") {
|
|
|
|
return rscan(\@args);
|
|
|
|
}
|
|
|
|
|
|
|
|
=cut
|
|
|
|
return (1,"$command not a supported command by xen method");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub preprocess_request {
|
|
|
|
my $request = shift;
|
2009-07-15 15:53:42 +00:00
|
|
|
#if already preprocessed, go straight to request
|
|
|
|
if ($request->{_xcatpreprocessed}->[0] == 1) { return [$request]; }
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
my $callback=shift;
|
|
|
|
my @requests;
|
|
|
|
|
|
|
|
my $noderange = $request->{node}; #Should be arrayref
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $extrargs = $request->{arg};
|
|
|
|
my @exargs=($request->{arg});
|
|
|
|
if (ref($extrargs)) {
|
|
|
|
@exargs=@$extrargs;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $usage_string=xCAT::Usage->parseCommand($command, @exargs);
|
|
|
|
if ($usage_string) {
|
|
|
|
$callback->({data=>$usage_string});
|
|
|
|
$request = {};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$noderange) {
|
|
|
|
$usage_string=xCAT::Usage->getUsage($command);
|
|
|
|
$callback->({data=>$usage_string});
|
|
|
|
$request = {};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#print "noderange=@$noderange\n";
|
|
|
|
|
|
|
|
# find service nodes for requested nodes
|
|
|
|
# build an individual request for each service node
|
|
|
|
my $service = "xcat";
|
|
|
|
my $sn = xCAT::Utils->get_ServiceNode($noderange, $service, "MN");
|
|
|
|
|
|
|
|
# build each request for each service node
|
|
|
|
|
|
|
|
foreach my $snkey (keys %$sn)
|
|
|
|
{
|
|
|
|
#print "snkey=$snkey\n";
|
|
|
|
my $reqcopy = {%$request};
|
|
|
|
$reqcopy->{node} = $sn->{$snkey};
|
|
|
|
$reqcopy->{'_xcatdest'} = $snkey;
|
2009-07-15 15:53:42 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
|
|
|
return \@requests;
|
|
|
|
}
|
2008-09-25 03:04:56 +00:00
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
sub adopt {
|
|
|
|
#TODO: adopt orphans into suitable homes if possible
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-09 03:30:54 +00:00
|
|
|
sub grab_table_data{ #grab table data relevent to VM guest nodes
|
2008-07-28 13:48:15 +00:00
|
|
|
my $noderange=shift;
|
|
|
|
my $callback=shift;
|
2008-07-30 03:10:08 +00:00
|
|
|
$vmtab = xCAT::Table->new("vm");
|
2008-07-31 17:32:39 +00:00
|
|
|
$hmtab = xCAT::Table->new("nodehm");
|
|
|
|
if ($hmtab) {
|
|
|
|
$hmhash = $hmtab->getNodesAttribs($noderange,['serialspeed']);
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
unless ($vmtab) {
|
|
|
|
$callback->({data=>["Cannot open vm table"]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$vmhash = $vmtab->getNodesAttribs($noderange,['node','host','migrationdest','storage','memory','cpu','nics','bootorder','virtflags']);
|
2008-07-28 21:45:59 +00:00
|
|
|
$mactab = xCAT::Table->new("mac",-create=>1);
|
2008-07-29 23:32:00 +00:00
|
|
|
$nrtab= xCAT::Table->new("noderes",-create=>1);
|
2008-07-28 21:45:59 +00:00
|
|
|
$machash = $mactab->getNodesAttribs($noderange,['mac']);
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub process_request {
|
|
|
|
$SIG{INT} = $SIG{TERM} = sub {
|
|
|
|
foreach (keys %vm_comm_pids) {
|
|
|
|
kill 2, $_;
|
|
|
|
}
|
|
|
|
exit 0;
|
|
|
|
};
|
2009-03-14 15:45:07 +00:00
|
|
|
#makes sense to check it here anyway, this way we avoid the main process
|
|
|
|
#sucking up ram with Sys::Virt
|
|
|
|
my $libvirtsupport = eval { require Sys::Virt; };
|
2009-03-14 15:52:28 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
2009-03-14 15:45:07 +00:00
|
|
|
unless ($libvirtsupport) { #Still no Sys::Virt module
|
|
|
|
$callback->({error=>"Sys::Virt perl module missing, unable to fulfill Xen plugin requirements",errorcode=>[42]});
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
require Sys::Virt::Domain;
|
|
|
|
%runningstates = (&Sys::Virt::Domain::STATE_NOSTATE=>1,&Sys::Virt::Domain::STATE_RUNNING=>1,&Sys::Virt::Domain::STATE_BLOCKED=>1);
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
$doreq = shift;
|
|
|
|
my $level = shift;
|
|
|
|
my $noderange = $request->{node};
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my @exargs;
|
|
|
|
unless ($command) {
|
|
|
|
return; #Empty request
|
|
|
|
}
|
|
|
|
if (ref($request->{arg})) {
|
|
|
|
@exargs = @{$request->{arg}};
|
|
|
|
} else {
|
|
|
|
@exargs = ($request->{arg});
|
|
|
|
}
|
2008-11-09 03:30:54 +00:00
|
|
|
if ($command eq 'revacuate') {
|
|
|
|
my $newnoderange;
|
|
|
|
foreach (@$noderange) {
|
|
|
|
$hypconn=undef;
|
|
|
|
push @destblacklist,$_;
|
2009-01-31 23:51:31 +00:00
|
|
|
eval { #Contain bugs that won't be in $@
|
2009-02-11 14:14:18 +00:00
|
|
|
$hypconn= Sys::Virt->new(uri=>"xen+ssh://".$_."?no_tty=1&netcat=nc");
|
2009-01-31 23:51:31 +00:00
|
|
|
};
|
2009-02-11 14:14:18 +00:00
|
|
|
unless ($hypconn) { #retry for socat
|
|
|
|
eval { #Contain bugs that won't be in $@
|
|
|
|
$hypconn= Sys::Virt->new(uri=>"xen+ssh://".$_."?no_tty=1");
|
|
|
|
};
|
|
|
|
}
|
2009-01-31 23:51:31 +00:00
|
|
|
unless ($hypconn) {
|
2009-02-11 14:14:18 +00:00
|
|
|
$callback->({node=>[{name=>[$_],error=>["Cannot communicate BC via libvirt to node"]}]});
|
2009-01-31 23:51:31 +00:00
|
|
|
next;
|
|
|
|
}
|
2008-11-09 03:30:54 +00:00
|
|
|
foreach ($hypconn->list_domains()) {
|
|
|
|
my $guestname = $_->get_name();
|
|
|
|
if ($guestname eq 'Domain-0') {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
push @$newnoderange,$guestname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$hypconn=undef;
|
|
|
|
$noderange = $newnoderange;
|
|
|
|
$command = 'rmigrate';
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
grab_table_data($noderange,$callback);
|
|
|
|
|
2008-11-09 03:30:54 +00:00
|
|
|
if ($command eq 'revacuate' or $command eq 'rmigrate') {
|
|
|
|
$vmmaxp=1; #for now throttle concurrent migrations, requires more sophisticated heuristics to ensure sanity
|
|
|
|
} else {
|
|
|
|
my $sitetab = xCAT::Table->new('site');
|
|
|
|
my $tmp;
|
|
|
|
if ($sitetab) {
|
|
|
|
($tmp)=$sitetab->getAttribs({'key'=>'vmmaxp'},'value');
|
|
|
|
if (defined($tmp)) { $vmmaxp=$tmp->{value}; }
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $children = 0;
|
2009-04-07 18:42:57 +00:00
|
|
|
$SIG{CHLD} = sub { my $cpid; while (($cpid = waitpid(-1, WNOHANG)) > 0) { if ($vm_comm_pids{$cpid}) { delete $vm_comm_pids{$cpid}; $children--; } } };
|
2008-07-28 13:48:15 +00:00
|
|
|
my $inputs = new IO::Select;;
|
|
|
|
my $sub_fds = new IO::Select;
|
|
|
|
%hyphash=();
|
|
|
|
my %orphans=();
|
|
|
|
foreach (keys %{$vmhash}) {
|
|
|
|
if ($vmhash->{$_}->[0]->{host}) {
|
|
|
|
$hyphash{$vmhash->{$_}->[0]->{host}}->{nodes}->{$_}=1;
|
|
|
|
} else {
|
|
|
|
$orphans{$_}=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
} elsif ($command eq "rmigrate") {
|
|
|
|
$callback->({error=>"Can't find ".join(",",keys %orphans),errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$callback->({error=>"Can't find ".join(",",keys %orphans),errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($command eq "rbeacon") {
|
|
|
|
my %req=();
|
|
|
|
$req{command}=['rbeacon'];
|
|
|
|
$req{arg}=\@exargs;
|
|
|
|
$req{node}=[keys %hyphash];
|
|
|
|
$doreq->(\%req,$callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-25 03:04:56 +00:00
|
|
|
#get new node status
|
2009-03-25 02:56:58 +00:00
|
|
|
my %oldnodestatus=(); #saves the old node status
|
|
|
|
my @allerrornodes=();
|
2008-09-25 03:04:56 +00:00
|
|
|
my $check=0;
|
2009-03-24 03:12:03 +00:00
|
|
|
my $global_check=1;
|
|
|
|
my $sitetab = xCAT::Table->new('site');
|
|
|
|
if ($sitetab) {
|
2009-03-24 19:44:23 +00:00
|
|
|
(my $ref) = $sitetab->getAttribs({key => 'nodestatus'}, 'value');
|
2009-03-24 23:56:42 +00:00
|
|
|
if ($ref) {
|
2009-03-24 19:44:23 +00:00
|
|
|
if ($ref->{value} =~ /0|n|N/) { $global_check=0; }
|
2009-03-24 03:12:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 02:56:58 +00:00
|
|
|
|
2008-09-25 03:04:56 +00:00
|
|
|
if ($command eq 'rpower') {
|
|
|
|
my $subcommand=$exargs[0];
|
2009-03-24 03:12:03 +00:00
|
|
|
if (($global_check) && ($subcommand ne 'stat') && ($subcommand ne 'status')) {
|
2008-09-25 03:04:56 +00:00
|
|
|
$check=1;
|
|
|
|
my @allnodes=@$noderange;
|
|
|
|
|
2009-03-25 02:56:58 +00:00
|
|
|
#save the old status
|
|
|
|
my $nodelisttab = xCAT::Table->new('nodelist');
|
|
|
|
if ($nodelisttab) {
|
|
|
|
my $tabdata = $nodelisttab->getNodesAttribs(\@allnodes, ['node', 'status']);
|
|
|
|
foreach my $node (@allnodes)
|
|
|
|
{
|
|
|
|
my $tmp1 = $tabdata->{$node}->[0];
|
|
|
|
if ($tmp1) {
|
|
|
|
if ($tmp1->{status}) { $oldnodestatus{$node}=$tmp1->{status}; }
|
|
|
|
else { $oldnodestatus{$node}=""; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#print "oldstatus:" . Dumper(\%oldnodestatus);
|
|
|
|
|
|
|
|
#set the new status to the nodelist.status
|
|
|
|
my %newnodestatus=();
|
|
|
|
my $newstat;
|
|
|
|
if (($subcommand eq 'off') || ($subcommand eq 'softoff')) {
|
|
|
|
my $newstat=$::STATUS_POWERING_OFF;
|
|
|
|
$newnodestatus{$newstat}=\@allnodes;
|
|
|
|
} else {
|
2008-09-25 03:04:56 +00:00
|
|
|
#get the current nodeset stat
|
|
|
|
if (@allnodes>0) {
|
2008-09-26 23:07:45 +00:00
|
|
|
my $nsh={};
|
2009-03-20 21:36:49 +00:00
|
|
|
my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh);
|
2008-09-26 23:07:45 +00:00
|
|
|
if (!$ret) {
|
|
|
|
foreach (keys %$nsh) {
|
2009-03-25 02:56:58 +00:00
|
|
|
my $newstat=xCAT_monitoring::monitorctrl->getNodeStatusFromNodesetState($_, "rpower");
|
|
|
|
$newnodestatus{$newstat}=$nsh->{$_};
|
2008-09-25 03:04:56 +00:00
|
|
|
}
|
2009-03-25 02:56:58 +00:00
|
|
|
} else {
|
|
|
|
$callback->({data=>$msg});
|
2008-09-25 03:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-25 02:56:58 +00:00
|
|
|
#print "newstatus" . Dumper(\%newnodestatus);
|
|
|
|
xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%newnodestatus, 1);
|
2008-09-25 03:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
foreach $hyp (sort (keys %hyphash)) {
|
2008-10-21 03:08:55 +00:00
|
|
|
while ($children > $vmmaxp) {
|
2009-03-25 02:56:58 +00:00
|
|
|
my $handlednodes={};
|
|
|
|
forward_data($callback,$sub_fds,$handlednodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
#update the node status to the nodelist.status table
|
|
|
|
if ($check) {
|
2009-03-25 02:56:58 +00:00
|
|
|
updateNodeStatus($handlednodes, \@allerrornodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
$children++;
|
|
|
|
my $cfd;
|
|
|
|
my $pfd;
|
|
|
|
socketpair($pfd, $cfd,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "socketpair: $!";
|
|
|
|
$cfd->autoflush(1);
|
|
|
|
$pfd->autoflush(1);
|
|
|
|
my $cpid = xCAT::Utils->xfork;
|
|
|
|
unless (defined($cpid)) { die "Fork error"; }
|
|
|
|
unless ($cpid) {
|
|
|
|
close($cfd);
|
|
|
|
dohyp($pfd,$hyp,$command,-args=>\@exargs);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
$vm_comm_pids{$cpid} = 1;
|
|
|
|
close ($pfd);
|
|
|
|
$sub_fds->add($cfd);
|
|
|
|
}
|
|
|
|
while ($sub_fds->count > 0 or $children > 0) {
|
2009-03-25 02:56:58 +00:00
|
|
|
my $handlednodes={};
|
|
|
|
forward_data($callback,$sub_fds,$handlednodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
#update the node status to the nodelist.status table
|
|
|
|
if ($check) {
|
2009-03-25 02:56:58 +00:00
|
|
|
updateNodeStatus($handlednodes, \@allerrornodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
2008-09-25 03:04:56 +00:00
|
|
|
|
2008-10-21 03:08:55 +00:00
|
|
|
#Make sure they get drained, this probably is overkill but shouldn't hurt
|
|
|
|
my $rc=1;
|
|
|
|
while ( $rc>0 ) {
|
2009-03-25 02:56:58 +00:00
|
|
|
my $handlednodes={};
|
|
|
|
$rc=forward_data($callback,$sub_fds,$handlednodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
#update the node status to the nodelist.status table
|
|
|
|
if ($check) {
|
2009-03-25 02:56:58 +00:00
|
|
|
updateNodeStatus($handlednodes, \@allerrornodes);
|
2008-10-21 03:08:55 +00:00
|
|
|
}
|
2009-03-25 02:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($check) {
|
|
|
|
#print "allerrornodes=@allerrornodes\n";
|
|
|
|
#revert the status back for there is no-op for the nodes
|
|
|
|
my %old=();
|
|
|
|
foreach my $node (@allerrornodes) {
|
|
|
|
my $stat=$oldnodestatus{$node};
|
|
|
|
if (exists($old{$stat})) {
|
|
|
|
my $pa=$old{$stat};
|
|
|
|
push(@$pa, $node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$old{$stat}=[$node];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%old, 1);
|
|
|
|
}
|
2008-10-21 03:08:55 +00:00
|
|
|
}
|
2008-09-25 03:04:56 +00:00
|
|
|
|
2008-10-21 03:08:55 +00:00
|
|
|
sub updateNodeStatus {
|
2009-03-25 02:56:58 +00:00
|
|
|
my $handlednodes=shift;
|
|
|
|
my $allerrornodes=shift;
|
|
|
|
foreach my $node (keys(%$handlednodes)) {
|
|
|
|
if ($handlednodes->{$node} == -1) { push(@$allerrornodes, $node); }
|
2008-09-25 03:04:56 +00:00
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-10-21 03:08:55 +00:00
|
|
|
|
2008-07-28 13:48:15 +00:00
|
|
|
sub forward_data {
|
|
|
|
my $callback = shift;
|
|
|
|
my $fds = shift;
|
2008-09-25 03:04:56 +00:00
|
|
|
my $errornodes=shift;
|
2008-07-28 13:48:15 +00:00
|
|
|
my @ready_fds = $fds->can_read(1);
|
|
|
|
my $rfh;
|
|
|
|
my $rc = @ready_fds;
|
|
|
|
foreach $rfh (@ready_fds) {
|
|
|
|
my $data;
|
|
|
|
if ($data = <$rfh>) {
|
|
|
|
while ($data !~ /ENDOFFREEZE6sK4ci/) {
|
|
|
|
$data .= <$rfh>;
|
|
|
|
}
|
2009-04-03 19:12:56 +00:00
|
|
|
eval { print $rfh "ACK\n"; };
|
2008-07-28 13:48:15 +00:00
|
|
|
my $responses=thaw($data);
|
|
|
|
foreach (@$responses) {
|
2008-10-03 19:05:59 +00:00
|
|
|
#save the nodes that has errors and the ones that has no-op for use by the node status monitoring
|
|
|
|
my $no_op=0;
|
2008-11-04 22:06:53 +00:00
|
|
|
if ($_->{node}->[0]->{errorcode}) { $no_op=1; }
|
2008-10-03 19:05:59 +00:00
|
|
|
else {
|
|
|
|
my $text=$_->{node}->[0]->{data}->[0]->{contents}->[0];
|
|
|
|
#print "data:$text\n";
|
|
|
|
if (($text) && ($text =~ /$status_noop/)) {
|
|
|
|
$no_op=1;
|
|
|
|
#remove the symbols that meant for use by node status
|
|
|
|
$_->{node}->[0]->{data}->[0]->{contents}->[0] =~ s/ $status_noop//;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#print "data:". $_->{node}->[0]->{data}->[0]->{contents}->[0] . "\n";
|
|
|
|
if ($no_op) {
|
2008-10-21 03:08:55 +00:00
|
|
|
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=-1; }
|
|
|
|
} else {
|
2008-10-03 19:05:59 +00:00
|
|
|
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=1; }
|
2008-10-21 03:08:55 +00:00
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
$callback->($_);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$fds->remove($rfh);
|
|
|
|
close($rfh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield(); #Try to avoid useless iterations as much as possible
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub dohyp {
|
|
|
|
my $out = shift;
|
|
|
|
$hyp = shift;
|
|
|
|
my $command=shift;
|
|
|
|
my %namedargs=@_;
|
|
|
|
my @exargs=@{$namedargs{-args}};
|
|
|
|
my $node;
|
|
|
|
my $args = \@exargs;
|
2008-11-10 21:38:28 +00:00
|
|
|
$vmtab = xCAT::Table->new("vm");
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
|
2009-01-31 23:51:31 +00:00
|
|
|
eval { #Contain Sys::Virt bugs that make $@ useless
|
2009-02-11 14:14:18 +00:00
|
|
|
$hypconn= Sys::Virt->new(uri=>"xen+ssh://".$hyp."?no_tty=1&netcat=nc");
|
2009-01-31 23:51:31 +00:00
|
|
|
};
|
2009-02-11 14:14:18 +00:00
|
|
|
unless ($hypconn) {
|
|
|
|
eval { #Contain Sys::Virt bugs that make $@ useless
|
|
|
|
$hypconn= Sys::Virt->new(uri=>"xen+ssh://".$hyp."?no_tty=1");
|
|
|
|
};
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
unless ($hypconn) {
|
|
|
|
my %err=(node=>[]);
|
|
|
|
foreach (keys %{$hyphash{$hyp}->{nodes}}) {
|
2009-02-21 12:58:41 +00:00
|
|
|
push (@{$err{node}},{name=>[$_],error=>["Cannot communicate via libvirt to $hyp"],errorcode=>[1]});
|
2008-07-28 13:48:15 +00:00
|
|
|
}
|
|
|
|
print $out freeze([\%err]);
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
yield();
|
|
|
|
waitforack($out);
|
|
|
|
return 1,"General error establishing libvirt communication";
|
|
|
|
}
|
|
|
|
foreach $node (sort (keys %{$hyphash{$hyp}->{nodes}})) {
|
|
|
|
my ($rc,@output) = guestcmd($hyp,$node,$command,@$args);
|
|
|
|
|
|
|
|
foreach(@output) {
|
|
|
|
my %output;
|
2008-08-12 17:15:48 +00:00
|
|
|
if (ref($_)) {
|
|
|
|
print $out freeze([$_]);
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
yield();
|
|
|
|
waitforack($out);
|
|
|
|
next;
|
|
|
|
}
|
2008-07-28 13:48:15 +00:00
|
|
|
|
|
|
|
(my $desc,my $text) = split (/:/,$_,2);
|
|
|
|
unless ($text) {
|
|
|
|
$text=$desc;
|
|
|
|
} else {
|
|
|
|
$desc =~ s/^\s+//;
|
|
|
|
$desc =~ s/\s+$//;
|
|
|
|
if ($desc) {
|
|
|
|
$output{node}->[0]->{data}->[0]->{desc}->[0]=$desc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$text =~ s/^\s+//;
|
|
|
|
$text =~ s/\s+$//;
|
|
|
|
$output{node}->[0]->{errorcode} = $rc;
|
|
|
|
$output{node}->[0]->{name}->[0]=$node;
|
|
|
|
$output{node}->[0]->{data}->[0]->{contents}->[0]=$text;
|
|
|
|
print $out freeze([\%output]);
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
yield();
|
|
|
|
waitforack($out);
|
|
|
|
}
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
#my $msgtoparent=freeze(\@outhashes); # = XMLout(\%output,RootName => 'xcatresponse');
|
|
|
|
#print $out $msgtoparent; #$node.": $_\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|