From 4c28315be6511d3ab49c2519f7a45824921139e7 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sun, 1 May 2011 12:53:16 +0000 Subject: [PATCH] Fix clones to have distinct mac addresses in vmware git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9445 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/esx.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index cf695b551..436d1c565 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -2145,22 +2145,40 @@ sub clone_task_callback { my $conn = $parms->{conn}; my $intent = $parms->{successtext}; if ($state eq 'success') { - xCAT::SvrUtils::sendmsg($intent, $output_handler,$node); + #xCAT::SvrUtils::sendmsg($intent, $output_handler,$node); my $nodetype=xCAT::Table->new('nodetype',-create=>1); my $vm=xCAT::Table->new('vm',-create=>1); $vm->setAttribs({node=>$node},$parms->{vment}); $nodetype->setAttribs({node=>$node},$parms->{nodetypeent}); - foreach (keys %{$parms->{vment}) { + foreach (keys %{$parms->{vment}}) { $tablecfg->{vm}->{$node}->[0]->{$_}=$parms->{vment}->{$_}; } + my @networks = split /,/,$tablecfg{vm}->{$node}->[0]->{nics}; my @macs = xCAT::VMCommon::getMacAddresses(\%tablecfg,$node,scalar @networks); #now with macs, change all macs in the vm to match our generated macs my $regex = qr/^$node(\z|\.)/; #have to do an expensive pull of the vm view, since it is brand new my $nodeviews = $conn->find_entity_views(view_type => 'VirtualMachine',filter=>{'config.name'=>$regex}); unless (scalar @$nodeviews == 1) { die "this should be impossible"; } - + my $ndev; + my @devstochange; + foreach $ndev ($nodeviews->[0]->config->hardware->device) { + unless ($ndev->macAddress) { next; } #not an ndev + $ndev->macAddress=shift @macs; + push @devstochange, VirtualDeviceConfigSpec->new( + device => $ndev, + operation => VirtualDeviceConfigSpecOperation->new('edit')); + } + if (@devstochange) { + my $reconfigspec = VirtualMachineConfigSpec->new(deviceChange=>\@devstochange); + my $task = $vmview->ReconfigVM_Task(spec=>$reconfigspec); + $running_tasks{$task}->{task} = $task; + $running_tasks{$task}->{callback} = \&generic_task_callback; + $running_tasks{$task}->{hyp} = $hyp; + $running_tasks{$task}->{data} = { node => $node, successtext => $intent,cpus=>$cpuCount,mem=>$memory }; + } + } elsif ($state eq 'error') { relay_vmware_err($task,"",$node);