2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

fix(kvm): resolve the default machine type before converting a UUID

The UUID conversion of mkvm, clonevm, rinv and rscan used the machine
type that the domain XML names. A domain that names none, or names an
alias such as pc, gets the default machine type of the hypervisor:
pc-i440fx-2.1 on QEMU 2.1 and pc-i440fx-rhel7.1.0 on the qemu-kvm of
RHEL 7.1. Its guest then reported a swapped UUID that the plugin did
not expect.

The plugin now asks libvirt for the machine type through the domain
capabilities of the hypervisor, as it already does for the video
model, and converts the UUID for that machine type. The domain XML
keeps the machine type it names. When libvirt cannot answer, the
plugin uses the machine type of the XML, as before.

(cherry picked from commit f3b47fcca98ca75c123615433df38d3642d2c5d4)
This commit is contained in:
Vinícius Ferrão
2026-10-24 04:00:49 -03:00
committed by Daniel Hilst
parent 24a799abed
commit 1e830adaa9
+21 -4
View File
@@ -526,6 +526,18 @@ sub getNodeUUID {
}
# The machine type that libvirt gives a domain whose XML names none, or names an alias such as pc.
sub domain_machine_type {
my ($machine, $arch, $domtype) = @_;
return $machine unless $hypconn and $parser;
my $resolved = eval {
my $capsxml = $hypconn->get_domain_capabilities(undef, $arch, $machine, $domtype);
my ($element) = $parser->parse_string($capsxml)->findnodes('/domainCapabilities/machine');
$element ? $element->textContent : undef;
};
return (defined($resolved) and length($resolved)) ? $resolved : $machine;
}
sub build_nicstruct {
my $rethash;
my $node = shift;
@@ -673,7 +685,8 @@ sub build_xmldesc {
hyp_cpumodel => $hypcpumodel,
bootorder => $confdata->{vm}->{$node}->[0]->{bootorder},
machine => $machine_type);
$xtree{uuid}->{content} = getNodeUUID($node, $xtree{os}->{type}->{machine});
$xtree{uuid}->{content} = getNodeUUID($node,
domain_machine_type($xtree{os}->{type}->{machine}, $profile->{arch}, $profile->{domtype}));
#prepare the xml hash for memory binding
if (defined $memnumanodes) {
@@ -1555,7 +1568,8 @@ sub rinv {
my $domain = $parser->parse_string($currxml);
my ($ostype) = $domain->findnodes('/domain/os/type');
my $uuid = xCAT::KVMUtils::guest_uuid($domain->findnodes('/domain/uuid')->[0]->to_literal,
$ostype ? $ostype->getAttribute('machine') : undef);
domain_machine_type($ostype ? $ostype->getAttribute('machine') : undef,
$ostype ? $ostype->getAttribute('arch') : undef, $domain->findnodes('/domain')->[0]->getAttribute('type')));
xCAT::SvrUtils::sendmsg("UUID/GUID: $uuid", $callback, $node);
my $cpus = $domain->findnodes('/domain/vcpu')->[0]->to_literal;
xCAT::SvrUtils::sendmsg("CPUs: $cpus", $callback, $node);
@@ -2867,7 +2881,8 @@ sub clone_vm_from_master {
my $newnodexml = $parser->parse_string($kvmmasteref->{xml});
$newnodexml->findnodes("/domain/name/text()")->[0]->setData($node); #set name correctly
my ($clonetype) = $newnodexml->findnodes('/domain/os/type');
my $uuid = getNodeUUID($node, $clonetype ? $clonetype->getAttribute('machine') : undef);
my $uuid = getNodeUUID($node, domain_machine_type($clonetype ? $clonetype->getAttribute('machine') : undef,
$clonetype ? $clonetype->getAttribute('arch') : undef, $newnodexml->findnodes('/domain')->[0]->getAttribute('type')));
$newnodexml->findnodes("/domain/uuid/text()")->[0]->setData($uuid); #put in correct uuid
#set up mac addresses and such right...
fixup_clone_network(mastername => $mastername, mastertableentry => $masteref, kvmmastertableentry => $kvmmasteref, xmlinprogress => $newnodexml);
@@ -3262,7 +3277,9 @@ sub rscan {
my @uuidobj = $domain->findnodes("/domain/uuid");
if (@uuidobj) {
my ($ostype) = $domain->findnodes('/domain/os/type');
$uuid = xCAT::KVMUtils::guest_uuid($uuidobj[0]->to_literal, $ostype ? $ostype->getAttribute('machine') : undef);
$uuid = xCAT::KVMUtils::guest_uuid($uuidobj[0]->to_literal,
domain_machine_type($ostype ? $ostype->getAttribute('machine') : undef,
$ostype ? $ostype->getAttribute('arch') : undef, $domain->findnodes('/domain')->[0]->getAttribute('type')));
}
my $type = $domain->findnodes("/domain")->[0]->getAttribute("type");
if (length($type) > $maxlength[0]) {