We have a number of private networks which may be assigned to VMs, depending on certain requirements.
I can extract the network name from the vm_view->network array, but I cannot find a corresponding method to update the value.
Any help/pointers would be very much appreciated.
Cheers .
Hi,
remember to set the first 2 variables:
my $vSwitchName = ""; my $vmname=""; my $vm_ref = Vim::find_entity_view((view_type => 'VirtualMachine'), filter => { name => '^'.$vmname.'$' } ); my $net_name="Network Adapter 1"; my $new_net_name=$vSwitchName; my $net_device=""; $config_spec_operation = VirtualDeviceConfigSpecOperation->new('edit'); my $devices = $vm_ref->config->hardware->device; foreach my $device (@$devices) { if ($device->deviceInfo->label eq $net_name){ $net_device=$device; } } if($net_device){ $net_device->deviceInfo->summary( $new_net_name ) ; $net_device->backing->deviceName( $new_net_name ) ; } my $vm_dev_spec = VirtualDeviceConfigSpec->new( device => $net_device, operation => $config_spec_operation ); my $vmSwitchspec = VirtualMachineConfigSpec->new(deviceChange => [ $vm_dev_spec ] ); eval{ $vm_ref->ReconfigVM(spec => $vmSwitchspec); };
Hi,
remember to set the first 2 variables:
my $vSwitchName = ""; my $vmname=""; my $vm_ref = Vim::find_entity_view((view_type => 'VirtualMachine'), filter => { name => '^'.$vmname.'$' } ); my $net_name="Network Adapter 1"; my $new_net_name=$vSwitchName; my $net_device=""; $config_spec_operation = VirtualDeviceConfigSpecOperation->new('edit'); my $devices = $vm_ref->config->hardware->device; foreach my $device (@$devices) { if ($device->deviceInfo->label eq $net_name){ $net_device=$device; } } if($net_device){ $net_device->deviceInfo->summary( $new_net_name ) ; $net_device->backing->deviceName( $new_net_name ) ; } my $vm_dev_spec = VirtualDeviceConfigSpec->new( device => $net_device, operation => $config_spec_operation ); my $vmSwitchspec = VirtualMachineConfigSpec->new(deviceChange => [ $vm_dev_spec ] ); eval{ $vm_ref->ReconfigVM(spec => $vmSwitchspec); };
Hi,
This looks great!
Many thanks for the fast response.
Cheers.
Hi,
I think something's not quite correct.
The script runs just fine, but it actually puts the vSwitch name into the network setting, rather than the network name.
Should I be using a different property?
Many thanks for all of your help.
Cheers.
Hi,
I think I have it ... the vSwitchName variable is the network name, not vSwitch0, 1 etc.
Looks to be working fine now.
Cheers.