VMware

This Question is Answered

2 "helpful" answers available (6 pts)
7 Replies Last post: Oct 20, 2009 7:53 AM by wurzelwaldi  

Change network link on virtual nic posted: Oct 12, 2009 12:53 AM

Click to view wurzelwaldi's profile Novice 8 posts since
Sep 15, 2009
Hallo,

since a few days i try to get a script working in orchestrator.

here my script:

System.log("Start SetNics");

// virtualDeviceConfigSpec1 = new VcVirtualDeviceConfigSpec();
virtualDeviceConfigSpec1 = System.getModule("com.vmware.library.vc.vm.spec.config").getVirtualDeviceConfigSpec(nic1,null,VcVirtualDeviceConfigSpecOperation.edit)
// virtualDeviceConfigSpec1.device = nic1;
Server.log("Set NIC2 ("virtualDeviceConfigSpec1.device.deviceInfo.label") to ConfigSprec");
virtualDeviceConfigSpec1.device.backing = new VcVirtualEthernetCardNetworkBackingInfo();
virtualDeviceConfigSpec1.device.backing.network = network1.reference;
Server.log("Set Network1 to backing");
// virtualDeviceConfigSpec1.operation = VcVirtualDeviceConfigSpecOperation.edit;

var virtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
virtualMachineConfigSpec.deviceChange = new Array();
virtualMachineConfigSpec.deviceChange.push(virtualDeviceConfigSpec1);

tempVm.reconfigVM_Task(virtualMachineConfigSpec);


the script should change the network a nic is connected to.

the variables are:

tempVm = VirtualMachine
network1 = Network
nic1 = VcVirtualPCNet32

i hope someone could help :-)


with kind regards

malte

Re: Change network link on virtual nic

1. Oct 12, 2009 1:15 PM in response to: wurzelwaldi
Click to view Cédric's profile Hot Shot 75 posts since
Jun 27, 2008
Juste two things I see:
- virtualDeviceConfigSpec1.device.backing.network = network1.reference; If I remember correctly, the backing network could only be set using the networkLabel (string) property, not by the reference.
- try replacing virtualMachineConfigSpec.deviceChange.push(virtualDeviceConfigSpec1); by virtualMachineConfigSpec.deviceChange[0] = virtualDeviceConfigSpec1; (I don't remember which one is working always and which one is having some problems sometimes.

Do you have any error message? What happened to the task?

Re: Change network link on virtual nic

3. Oct 13, 2009 5:03 AM in response to: wurzelwaldi
Click to view Cédric's profile Hot Shot 75 posts since
Jun 27, 2008
Look at action com.vmware.library.vc.vm.spec.config.device.backing.device.getVirtualEthernetCardNetworkBackingInfo..

with network as a VC:Network

var backing = new VcVirtualEthernetCardNetworkBackingInfo();
backing.deviceName = network.name;
...

Re: Change network link on virtual nic

5. Oct 13, 2009 6:49 AM in response to: wurzelwaldi
Click to view Cédric's profile Hot Shot 75 posts since
Jun 27, 2008
Maybe you should try to revert back to virtualMachineConfigSpec.deviceChange.push(virtualDeviceConfigSpec1);

You must specifiy the VirtualDeviceConfigSpec.operation to be able to update something.

The following code is extraced from on of the Clone Workflows:

var deviceChange = new Array();
var change = new VcVirtualDeviceConfigSpec();
change.device = virtualEthernetCard;
change.operation = VcVirtualDeviceConfigSpecOperation.edit;
deviceChange.push(change);

Re: Change network link on virtual nic

6. Oct 14, 2009 10:56 PM in response to: wurzelwaldi
Click to view AngelaS's profile Enthusiast 43 posts since
Sep 28, 2009

When you get the VirtualDeviceConfigSpec object, from the getVirtualDeviceConfigSpec() method, the method returns the blank template for the VirtualDeviceConfigSpec. To use this spec in your case, you also need to specify which virtual device to change i.e. you need to set the virtualDeviceConfigSpec1.device property in order to change the network link for a the network device of a virtual machine. For doing the same, please refer the following steps:

  • 1. Retreive all the available virtual devices of the virtual machine using the vm.config.hardware.device property
  • 2. Fetch the appropriate network device for which the network link needs to be changed
  • 3. Assign this fetched device to the device property of VirtualDeviceConfigSpec. Here you can either use getvirtualdevicespec() method or create a new virtualdeviceconfigspec object.


Kindly refer to the below code snippet to change the network for a VM.

Here, we need to provide three input parameters, namely the virtual machine whose network needs to be changed, the name of the existing network and the name of the new network.

// existNetwork string variable holds the name of the existing network

// newNetwork string variable holds the name of the new network

var vmspec = new VcVirtualMachineConfigSpec();

var device = new VcVirtualPCNet32();

var devicearr = new Array();

var nic = new VcVirtualEthernetCardNetworkBackingInfo();

nic.deviceName = newNetwork;

var devicespec = new VcVirtualDeviceConfigSpec();

var devices = vm.config.hardware.device;

for( var i in devices)

{

if(devices instanceof VcVirtualPCNet32)

{

if (devices.deviceInfo.summary == existNetwork)

{

devicespec.device = devices;

devicespec.operation = VcVirtualDeviceConfigSpecOperation.edit;

devicespec.device.backing = nic;

devicearr[0] = devicespec;

}

}

}

vmspec.deviceChange = devicearr;

task = vm.reconfigVM_Task(vmspec);

I hope this helps.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities