This code: http://pastebin.com/GRsniSVe will run to completion with no errors, but doesn't actually move the vNIC to the designated portgroup. It successfully finds the portgroup by its VLAN id [Line 79], finds the VM by its name [Line 96], and finds the first vNIC on the VM [Line 121]... after that I'm attempting to:
Printing out these objects at various points appears to show all the correct properties. Even after the error-free ReconfigVM( ) call, printing out the VM data model at the end of the script [Line 207] shows the updated portgroup connection. But the vNIC never actually moves. I'd really appreciate any guidance on what I've done wrong here.
** I have a hunch it has something to do with updating the vNIC vs. creating a new empty one, but I don't want to change the vNIC's MAC or any other properties. I'm thinking if make an empty vNIC with nothing but this new backing info, how will ReconfigVM know which vNIC to update?
Thanks!
Message was edited by: herrdr (adding line numbers)
Assuming new portgroup on the same vDS, this works for me. (let me know if this assumption is incorrect so I can look further into this...):
First identify your network adapter as $adpater and your new port group is $pg...Afterward:
my $dvsUUID = $adapter->backing->port->{'switchUuid'};
my $network = Vim::find_entity_views(view_type => "Network", properties => ['name'], );
foreach(@$network) { $pgKey = $_->{'mo_ref'}->{'value'} if ($pg eq $_->name);}
my $port = new DistributedVirtualSwitchPortConnection( portgroupKey=>$pgKey, switchUuid=>$dvsUUID,);
my $backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo(port => $port);
$adapter->backing($backing);
my $devspec = VirtualDeviceConfigSpec->new(device => $adapter,operation => VirtualDeviceConfigSpecOperation->new('edit'));
my $pgChangespec = VirtualMachineConfigSpec->new(deviceChange => [ $devspec ] );
$vm_view->ReconfigVM(spec => $pgChangespec);
Thanks so much MR-Z. I was missing:
operation => VirtualDeviceConfigSpecOperation->new('edit')