2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-22 19:20:24 +00:00

enhance the scan for kvm

This commit is contained in:
penguhyang
2016-04-08 03:02:53 -04:00
parent 5338644b00
commit 842d200454

View File

@@ -2870,7 +2870,7 @@ sub fixup_clone_network {
}
sub mkvm {
shift; #Throuw away first argument
shift; #Throw away first argument
@ARGV = @_;
my $disksize;
my $mastername;
@@ -2885,6 +2885,12 @@ sub mkvm {
"cpus=s" => \$cpucount,
'force|f' => \$force
);
if (defined $confdata->{vm}->{$node}->[0]->{othersettings}) {
my $nodefrom = $confdata->{vm}->{$node}->[0]->{othersettings};
if ($nodefrom =~ /^nodefromrscan/) {
return 1, "this node was defined through rscan, it does not support to use 'mkvm' to create again.";
}
}
if (defined $confdata->{vm}->{$node}->[0]->{storage}) {
my $diskname = $confdata->{vm}->{$node}->[0]->{storage};
if ($diskname =~ /^phy:/) { #in this case, mkvm should have no argumens
@@ -3136,14 +3142,23 @@ sub rscan {
}
my @vmstoragediskobjs = $domain->findnodes("/domain/devices/disk");
foreach my $vmstoragediskobj (@vmstoragediskobjs) {
my ($vmstorage_file_obj, $vmstorage_block_obj);
if (($vmstoragediskobj->getAttribute("device") eq "disk") and ($vmstoragediskobj->getAttribute("type") eq "file")) {
my @vmstorageobj = $vmstoragediskobj->findnodes("./source");
if (@vmstorageobj and defined($vmstorageobj[0])) {
$vmstorage = $vmstorageobj[0]->getAttribute("file");
last;
$vmstorage_file_obj = $vmstorageobj[0]->getAttribute("file");
}
$vmstorage .= "$vmstorage_file_obj,";
}
if (($vmstoragediskobj->getAttribute("device") eq "disk") and ($vmstoragediskobj->getAttribute("type") eq "block")) {
my @vmstorageobj = $vmstoragediskobj->findnodes("./source");
if (@vmstorageobj and defined($vmstorageobj[0])) {
$vmstorage_block_obj = $vmstorageobj[0]->getAttribute("dev");
}
$vmstorage .= "$vmstorage_block_obj,";
}
}
chop($vmstorage);
if (length($vmstorage) > $maxlength[7]) {
$maxlength[7] = length($vmstorage);
}
@@ -3154,21 +3169,31 @@ sub rscan {
my @interfaceobjs = $domain->findnodes("/domain/devices/interface");
foreach my $interfaceobj (@interfaceobjs) {
if (($interfaceobj->getAttribute("type")) eq "bridge" ) {
my ($vmnics_obj, $mac_obj, $vmnicnicmodel_obj);
my @vmnicsobj = $interfaceobj->findnodes("./source");
my @macobj = $interfaceobj->findnodes("./mac");
my @vmnicnicmodelobj = $interfaceobj->findnodes("./model");
if ((@vmnicsobj and defined($vmnicsobj[0])) and (@macobj and defined($macobj[0])) and (@vmnicnicmodelobj and defined($vmnicnicmodelobj[0]))) {
$vmnics = $vmnicsobj[0]->getAttribute("bridge");
$mac = $macobj[0]->getAttribute("address");
$vmnicnicmodel = $vmnicnicmodelobj[0]->getAttribute("type");
last;
if (@vmnicsobj and defined($vmnicsobj[0])) {
$vmnics_obj = $vmnicsobj[0]->getAttribute("bridge");
}
if (@macobj and defined($macobj[0])) {
$mac_obj = $macobj[0]->getAttribute("address");
}
if (@vmnicnicmodelobj and defined($vmnicnicmodelobj[0])) {
$vmnicnicmodel_obj = $vmnicnicmodelobj[0]->getAttribute("type");
}
$vmnics .= "$vmnics_obj,";
$mac .= "$mac_obj,";
$vmnicnicmodel .= "$vmnicnicmodel_obj,";
}
}
chop($vmnics);
chop($mac);
chop($vmnicnicmodel);
if (length($vmnics) > $maxlength[6]) {
$maxlength[6] = length($vmnics);
}
push @{$host2kvm{$uuid}}, join( ",", $type,$node,$hypervisor,$id,$vmcpus,$vmmemory,$vmnics,$vmstorage,$arch,$mac,$vmnicnicmodel );
push @{$host2kvm{$uuid}}, join( ":", $type,$node,$hypervisor,$id,$vmcpus,$vmmemory,$vmnics,$vmstorage,$arch,$mac,$vmnicnicmodel );
if ($write) {
unless (exists $hash_vm2host{$node}) {
$updatetable->{vm}->{$node}->{host} = $hypervisor;
@@ -3177,15 +3202,20 @@ sub rscan {
$updatetable->{vm}->{$node}->{cpus} = $vmcpus;
$updatetable->{vm}->{$node}->{nics} = $vmnics;
$updatetable->{vm}->{$node}->{nicmodel} = $vmnicnicmodel;
$updatetable->{vm}->{$node}->{othersettings} = "nodefromrscan";
$updatetable->{mac}->{$node}->{mac} = $mac;
$updatetable->{vpd}->{$node}->{uuid} = $uuid;
$updatetable->{nodelist}->{$node}->{groups} = "vm,all";
$updatetable->{nodetype}->{$node}->{arch} = $arch;
$updatetable->{nodehm}->{$node}->{mgt} = "kvm";
$updatetable->{nodehm}->{$node}->{serialport} = "0";
$updatetable->{nodehm}->{$node}->{serialspeed} = "115200";
$updatetable->{kvm_nodedata}->{$node}->{xml} = $currxml;
}
else {
if ($hash_vm2host{$node} eq $hypervisor) {
#mark this node to delete in 'vm' 'mac' vpd' 'nodetype' 'nodehm' tables
#mark this node to delete in 'vm' 'mac' vpd' 'nodelist' 'nodetype' 'nodehm' tables
$updatetable->{vm}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{vm}->{$node}->{host} = $hypervisor;
@@ -3194,14 +3224,21 @@ sub rscan {
$updatetable->{vm}->{$node}->{cpus} = $vmcpus;
$updatetable->{vm}->{$node}->{nics} = $vmnics;
$updatetable->{vm}->{$node}->{nicmodel} = $vmnicnicmodel;
$updatetable->{vm}->{$node}->{othersettings} = "nodefromrscan";
$updatetable->{mac}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{mac}->{$node}->{mac} = $mac;
$updatetable->{vpd}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{vpd}->{$node}->{uuid} = $uuid;
$updatetable->{nodelist}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodelist}->{$node}->{groups} = "vm,all";
$updatetable->{nodetype}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodetype}->{$node}->{arch} = $arch;
$updatetable->{nodehm}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodehm}->{$node}->{mgt} = "kvm";
$updatetable->{nodehm}->{$node}->{serialport} = "0";
$updatetable->{nodehm}->{$node}->{serialspeed} = "115200";
$updatetable->{kvm_nodedata}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{kvm_nodedata}->{$node}->{xml} = $currxml;
}
else {
$callback->({data=>"the name of KVM guest $node on $hypervisor conflicts with the existing node in xCAT table."});
@@ -3217,14 +3254,21 @@ sub rscan {
$updatetable->{vm}->{$node}->{cpus} = $vmcpus;
$updatetable->{vm}->{$node}->{nics} = $vmnics;
$updatetable->{vm}->{$node}->{nicmodel} = $vmnicnicmodel;
$updatetable->{vm}->{$node}->{othersettings} = "nodefromrscan";
$updatetable->{mac}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{mac}->{$node}->{mac} = $mac;
$updatetable->{vpd}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{vpd}->{$node}->{uuid} = $uuid;
$updatetable->{nodelist}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodelist}->{$node}->{groups} = "vm,all";
$updatetable->{nodetype}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodetype}->{$node}->{arch} = $arch;
$updatetable->{nodehm}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{nodehm}->{$node}->{mgt} = "kvm";
$updatetable->{nodehm}->{$node}->{serialport} = "0";
$updatetable->{nodehm}->{$node}->{serialspeed} = "115200";
$updatetable->{kvm_nodedata}->{'!*XCATNODESTODELETE*!'}->{$node} = $node;
$updatetable->{kvm_nodedata}->{$node}->{xml} = $currxml;
}
}
if ($create) {
@@ -3235,10 +3279,15 @@ sub rscan {
$updatetable->{vm}->{$node}->{cpus} = $vmcpus;
$updatetable->{vm}->{$node}->{nics} = $vmnics;
$updatetable->{vm}->{$node}->{nicmodel} = $vmnicnicmodel;
$updatetable->{vm}->{$node}->{othersettings} = "nodefromrscan";
$updatetable->{mac}->{$node}->{mac} = $mac;
$updatetable->{vpd}->{$node}->{uuid} = $uuid;
$updatetable->{nodelist}->{$node}->{groups} = "vm,all";
$updatetable->{nodetype}->{$node}->{arch} = $arch;
$updatetable->{nodehm}->{$node}->{mgt} = "kvm";
$updatetable->{nodehm}->{$node}->{serialport} = "0";
$updatetable->{nodehm}->{$node}->{serialspeed} = "115200";
$updatetable->{kvm_nodedata}->{$node}->{xml} = $currxml;
}
}
if ($stanza) {
@@ -3276,7 +3325,7 @@ sub rscan {
my @data;
foreach (@{$host2kvm{$host}}) {
my $info = $_;
foreach (split(',', $info)) {
foreach (split(':', $info)) {
my $attr = $_;
push @data, "$attr";
}