Hello.
I am having two network adapters A and B.
Currently I am on Network Adapter A and I want to switch on B through ReConfig_VM Task() API.
Can somone help me in specifying VirtualmachineConfigSpec?
This is how I am specifying the virtualmachineconfigspec but i am not able to acheive it.
VirtualMachineConfigSpec Configspec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] nicSpec = new VirtualDeviceConfigSpec[1];
VirtualEthernetCard nic = new VirtualVmxnet();
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.deviceName = "B";
Configspec.deviceChange = nicSpec;
nic.backing = nicBacking;
nicSpec[0].device = nic;
ConfigSpec.devicechange = niSpec;
Thanks,
-AsHwIN
Following code snippet might be of help illustrating adding a nic.
// Add a NIC
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
if(networkRef != null)
{
nicSpec.operation = VirtualDeviceConfigSpecOperation.add;
nicSpec.operationSpecified = true;
VirtualEthernetCard nic = new VirtualVmxnet();
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.network = networkRef;
nicBacking.deviceName = networkName;
nic.addressType = "generated";
nic.backing = nicBacking;
nic.key = 4;
nicSpec.device = nic;
}
I guess method that you have suggested will add new network adapeter.
Whether this will also work for replacing the network adpapter from the list of exisiting adapters?
-AsHwIN
Here is code snippet for which i am getting invalid configuration for device 0 when i call reconifgvm_task api.
// Here I get the list of Network adapters
ManagedObjectReference[] nwMoref = (ManagedObjectReference[])_GetPropFromMoref(PaMoref, "network");
//Suppose I want to edit the network adapter for a VM to default i.e VM Network which is 2nd in the list.
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
nicSpec.operation = VirtualDeviceConfigSpecOperation.edit; //As we want to edit the network adapter
nicSpec.operationSpecified = true;
VirtualEthernetCard nic = new VirtualVmxnet();
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.network = nwMoref[1]; //Second in the network list.
nicBacking.deviceName = "VM Network"; //I am not sure what should we give the device name?
nic.backing = nicBacking;
nicSpec.device = nic;
it throwing me message as Invalid configuration for device 0.
Whether I am doing any wrong settings?
Please let me know for the same.
-AsHwIN
The code snippet seems to be correct. You have specified the deviceName as "VM Network". Is this the name for the network that you are assigning in the following:
nicBacking.network = nwMoref[1];
Try to change the name and see if it works.
I am trying to add a new ethernet card to a VM - there are no errors from the code. However the vSphere client connected to the host shows this:
Invalid configuration for device '0'
My network configuration looks like this:
What I am trying to do is add a new ethernet card to node01 which will connect it to "MyNewPortGroup" on "MyNewSwitch" which I created programmatically earlier on.
The code I used for the reconfiguration is below (C#):
public void ChangeVEthernetCard()
{
ManagedObjectReference portGrp = new ManagedObjectReference { Value = "HaNetwork-MyNewPortGroup", type = "Network" };
VirtualEthernetCard newEthernetCard = new VirtualEthernetCard();
VirtualEthernetCardNetworkBackingInfo backingInfo = new VirtualEthernetCardNetworkBackingInfo();
backingInfo.network = portGrp;
backingInfo.deviceName = "MyNewPortGroup";newEthernetCard.addressType = "generated";
newEthernetCard.backing = backingInfo;VirtualDeviceConfigSpec deviceSpec = new VirtualDeviceConfigSpec();
deviceSpec.device = newEthernetCard;
deviceSpec.operation = VirtualDeviceConfigSpecOperation.add;
deviceSpec.operationSpecified = true;VirtualMachineConfigSpec newMachineSpec = new VirtualMachineConfigSpec();
newMachineSpec.deviceChange = new VirtualDeviceConfigSpec[] { deviceSpec };
try
{
ManagedObjectReference updateTask = _host.VimService.ReconfigVM_Task(_MOR, newMachineSpec);
Debug.WriteLine("Updated vm");
}
catch (System.Web.Services.Protocols.SoapException e)
{
ExceptionHandler.SoapExceptionHandler(e);
}
catch (Exception e)
{
ExceptionHandler.GenericExceptionHandler(e);
}}
I picked up the value of the port group MOR from my MOB. Do I have the correct value for backingInfo.deviceName?
I used this thread and this one: http://communities.vmware.com/message/1146914#1146914 as a reference while writing my code.
Any help would be appreciated.
I got it to work by using VirutalPCNet32 instead of VirutalEthernetCard.