VMware {code} Community
herrdr
Contributor
Contributor

Moving vNIC on existing VM to new DVS portgroup

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:

  1. [Line 126] Create a new connection to the portgroup with DistributedVirtualSwitchPortConnection->new
  2. [Line 130] Create new vNIC backing info using that connection with VirtualEthernetCardDistributedVirtualPortBackingInfo->new
  3. [Line 131] Update the vNIC's "backing" property to the new backing info, preserving any other config it may have **
  4. [Line 147] Create a new device config spec with the updated vNIC using VirtualDeviceConfigSpec->new
  5. [Line 168] Creating a new VM config spec using the new device config spec using VirtualMachineConfigSpec->new
  6. [Line 178] Calling ReconfigVM( ) on the VM, passing in the new VM config spec

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)

Tags (3)
0 Kudos
2 Replies
MR-Z
VMware Employee
VMware Employee

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);

0 Kudos
herrdr
Contributor
Contributor

Thanks so much MR-Z.  I was missing:

operation => VirtualDeviceConfigSpecOperation->new('edit')

0 Kudos