diff --git a/xCAT-server/lib/xcat/plugins/rhevm.pm b/xCAT-server/lib/xcat/plugins/rhevm.pm
index dd3d642b5..fedc0dd41 100644
--- a/xCAT-server/lib/xcat/plugins/rhevm.pm
+++ b/xCAT-server/lib/xcat/plugins/rhevm.pm
@@ -1119,7 +1119,7 @@ sub lsve {
displaysrc($callback, $ref_rhevm, $response, "networks", " ", "name=$obj");
}
} elsif ($type eq "tpl") {
- my ($rc, $id, $stat, $response) = search_src($ref_rhevm, "templates", "$obj");
+ my ($rc, $id, $stat, $response) = search_src($ref_rhevm, "templates", "name%3D$obj");
unless ($rc) {
displaysrc($callback, $ref_rhevm, $response, "templates", "");
}
@@ -2003,7 +2003,7 @@ sub mkvm {
my $disele;
if ($myvment->{vidproto}) {
$disele = "$myvment->{vidproto}";
- } elsif (!$hastpl) {
+ } else {
$disele = "vnc";
}
@@ -2029,7 +2029,10 @@ sub mkvm {
$hostele = "{host}}\"/>";
}
- my $placement_policy = "$hostele$affinity";
+ my $placement_policy;
+ if ($affinity || $hostele) {
+ $placement_policy= "$hostele$affinity";
+ }
# set the cluster for the vm
my $clusterele;
@@ -2177,10 +2180,43 @@ sub mkvm {
next;
}
}
+
+ # if no installnic is specified, set the firstmac to mac.mac
+ my $firstmac;
+
+ # Search the nic
+ my %oldmac;
+ ($rc, undef, $stat, $response) = search_src($ref_rhevm, "vms:nics", "/$vmid/nics");
+ unless ($rc) {
+ my $parser = XML::LibXML->new();
+ my $doc = $parser->parse_string($response);
+ my @nicnodes = $doc->findnodes("/nics/nic");
+ foreach my $nic (@nicnodes) {
+ if (defined($nic->findnodes("name"))) {
+ my $ethname = getAttr($nic, "name");
+ my $mac = getAttr($nic, "mac", "address");
+ $oldmac{$ethname} = $mac;
+ unless($firstmac) {
+ $firstmac = $mac;
+ }
+ }
+ }
+ }
+
foreach my $nic (@nics) {
- $success = 0;
# format of nic: [networkname:ifname:installnic]
my ($nwname, $ifname, $instnic) = split(':', $nic);
+
+ if (defined($oldmac{$ifname})) {
+ # The nic has been defined, mostly by clone
+ if ($instnic) {
+ $upmac->{$node}->{mac} = $oldmac{$ifname};
+ }
+ next;
+ }
+
+ # start the configuring
+ $success = 0;
my $nwid;
($rc, $nwid, $stat) = search_src($ref_rhevm, "networks", "$nwname");
@@ -2190,6 +2226,7 @@ sub mkvm {
xCAT::MsgUtils->message("E", $rsp, $callback);
next;
}
+
$api = "/api/vms/$vmid/nics";
$method = "POST";
@@ -2226,7 +2263,10 @@ sub mkvm {
my $doc = $parser->parse_string($response);
if (defined($doc->findnodes("/nic/mac")->[0])) {
my $realmac = $doc->findnodes("/nic/mac")->[0]->getAttribute("address");
- if (! $orgmac && $instnic) {
+ unless($firstmac) {
+ $firstmac = $realmac;
+ }
+ if ($instnic) {
$upmac->{$node}->{mac} = $realmac;
}
@@ -2246,6 +2286,10 @@ sub mkvm {
}
}
+ if (!$upmac->{$node}->{mac} && $firstmac) {
+ $upmac->{$node}->{mac} = $firstmac;
+ }
+
if ($success) {
my $rsp;
push @{$rsp->{data}}, "$node: Succeeded";