diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 6ac2c70a2..70ce1bd15 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -15,7 +15,7 @@ package xCAT::Schema; #New format, not sql statements, but info enough to describe xcat tables %tabspec = ( vm => { - cols => [qw(node host migrationdest storage memory cpus nics bootorder virtflags beacon comments disable)], + cols => [qw(node host migrationdest storage memory cpus nics bootorder virtflags vncport textconsole beacon comments disable)], keys => [qw(node)], table_desc => 'Virtualization parameters', descriptions => { @@ -28,6 +28,8 @@ vm => { 'nics' => 'Network configuration parameters', 'bootorder' => 'Boot sequence (i.e. net,hd)', 'virtflags' => 'General flags used by the virtualization method. For example, in Xen it could, among other things, specify paravirtualized setup, or direct kernel boot', + 'vncport' => 'Tracks the current VNC display port (currently not meant to be set', + 'textconsole' => 'Tracks the Psuedo-TTY that maps to the serial port or console of a VM', 'beacon' => "This flag is used by xCAT to track the state of the identify LED with respect to the VM." } }, diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 834b059a3..94f071258 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -1018,7 +1018,7 @@ sub getNodeAttribs foreach $attrib (@attribs) { - if ($datum->{$attrib} =~ /^\/.*\/.*\//) + if ($datum->{$attrib} =~ /^\/.*\/.*\/$/) { my $exp = substr($datum->{$attrib}, 1); chop $exp; diff --git a/xCAT-server/lib/xcat/plugins/xen.pm b/xCAT-server/lib/xcat/plugins/xen.pm index ce9c4c35f..0c7bbe8a3 100644 --- a/xCAT-server/lib/xcat/plugins/xen.pm +++ b/xCAT-server/lib/xcat/plugins/xen.pm @@ -57,6 +57,7 @@ my $hyp; my $doreq; my %hyphash; my $node; +my $vmtab; sub waitforack { my $sock = shift; @@ -156,32 +157,70 @@ sub build_xmldesc { return XMLout(\%xtree,RootName=>"domain"); } -sub power { - my $subcommand = shift; - my $dom; - if ($subcommand eq 'on') { - my $xml=build_xmldesc($node); - eval { $dom=$hypconn->create_domain($xml); }; - } elsif ($subcommand eq 'off') { - eval { $dom = $hypconn->get_domain_by_name($node); }; - if ($dom) { - $dom->destroy(); - } - } elsif ($subcommand eq 'stat') { - eval { - $dom = $hypconn->get_domain_by_name($node); - }; - } +sub refresh_vm { + my $dom = shift; + + my $newxml=XMLin($dom->get_xml_description()); + print Dumper($newxml); + my $vncport=$newxml->{devices}->{graphics}->{port}; + my $stty=$newxml->{devices}->{console}->{tty}; + $vmtab->setNodeAttribs($node,{vncport=>$vncport,textconsole=>$stty}); + print Dumper({vncport=>$vncport,textconsole=>$stty}); +} + +sub getpowstate { + my $dom = shift; my $vmstat; if ($dom) { $vmstat = $dom->get_info; } if ($vmstat and $runningstates{$vmstat->{state}}) { - return (0,"on"); + return "on"; } else { - return (0,"off"); + return "off"; + } +} + +sub power { + my $subcommand = shift; + my $retstring; + my $dom; + 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"; + } + } + if ($subcommand eq 'on') { + unless ($dom) { + my $xml=build_xmldesc($node); + eval { $dom=$hypconn->create_domain($xml); }; + if ($dom) { + refresh_vm($dom); + } + } + } elsif ($subcommand eq 'off') { + if ($dom) { + $dom->destroy(); + } + } elsif ($subcommand eq 'softoff') { + if ($dom) { + $dom->shutdown(); + } + } else { + unless ($subcommand =~ /^stat/) { + return (1,"Unsupported power directive '$subcommand'"); + } } + $retstring.=getpowstate($dom); + return (0,$retstring); } @@ -285,7 +324,7 @@ sub adopt { sub grab_table_data{ my $noderange=shift; my $callback=shift; - my $vmtab = xCAT::Table->new("vm"); + $vmtab = xCAT::Table->new("vm"); unless ($vmtab) { $callback->({data=>["Cannot open vm table"]}); return;