I try to set true or false to connected and Connected at StartUp for Network Card.
I write this code, but I'v problem with it. the configuration in my Network Card doesn't change .
========================================
Begin here
var spec = new VcVirtualMachineConfigSpec(); // Initialize a Virtual Machine Config Spec first
var myDeviceChanges = new Array() ; // Create an array to hold all of your changes
var devices = vm.config.hardware.device;
var nicChangeSpec = new VcVirtualDeviceConfigSpec(); //This is the specification for the Network adapter we are going to change
nicChangeSpec.operation = VcVirtualDeviceConfigSpecOperation.edit; //Use edit as we are going to be modifying a NIC
myVirtualDeviceConnectInfo = new VcVirtualDeviceConnectInfo() ;
myVirtualDeviceConnectInfo.startConnected = SetIsConnectedAtStartup;
myVirtualDeviceConnectInfo.connected = SetIsConnected;
myNewDevice = new VcVirtualVmxnet3() ;
myNewDevice.backing = myVirtualEthernetCardDistributedVirtualPortBackingInfo;
for (i in devices)
{
if (devices[i].DeviceInfo.Label.indexOf('Network adapter') >= 0)
{
var infoFlat = devices[i].DeviceInfo.label;
if (infoFlat == NetworksCards )
{
var connectedNetwork = devices[i].connectable.connected;
IsConnected = connectedNetwork;
System.log("LA carte " + NetworksCards + " est-il connecté :" + IsConnected );
myVirtualDeviceConnectInfo.startConnected = SetIsConnectedAtStartup;
myVirtualDeviceConnectInfo.connected = SetIsConnected;
myNewDevice.connectable = myVirtualDeviceConnectInfo;
break;
}
}
}
nicChangeSpec.device = myNewDevice;
myDeviceChanges.push(nicChangeSpec);
spec.deviceChange = myDeviceChanges;
System.log("DeviceChange Spec is: " + spec.deviceChange);
vm.reconfigVM_Task(spec);
Hi,
Check my post in the following thread for scripting code showing how to do so - https://communities.vmware.com/thread/537178
Hi Ilian,
I'tested your code and It's working very good.
This is my portion of my code, that I want to share.
Thanks a lot for your help
//https://communities.vmware.com/thread/537178
var devices = vm.config.hardware.device;
//My in variable :
// vm : as vcVirtualMachine
//NetworksCard : as string. That contain the name of my Network card : exp : Network Adapter 1
//SetIsConnected : Contain the boolen value that I want to set to my Network Card
SetIsConnectedAtStartup : Contain the boolean value that I want to set to my Network Card
for (i in devices)
{
if (devices[i].DeviceInfo.Label.indexOf('Network adapter') >= 0)
{
var infoFlat = devices[i].DeviceInfo.label;
if (infoFlat == NetworksCards )
{
var IsConnected = devices[i].connectable.connected;
var IsConnectedStartup = devices[i].connectable.startConnected;
System.log("The network card " + NetworksCards + " is connected : " + IsConnected );
System.log("The network card " + NetworksCards + " is connected at startup :" + IsConnectedStartup );
var confSpec = new VcVirtualDeviceConfigSpec();
confSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
confSpec.device = devices[i];
confSpec.device.connectable.startConnected = SetIsConnectedAtStartup;
confSpec.device.connectable.connected = SetIsConnected;
var spec = new VcVirtualMachineConfigSpec();
spec.deviceChange = [confSpec];
vm.reconfigVM_Task(spec);
var IsConnected = devices[i].connectable.connected;
var IsConnectedStartup = devices[i].connectable.startConnected;
System.log("The network card " + NetworksCards + " is connected : " + IsConnected );
System.log("The network card " + NetworksCards + " is connected at startup :" + IsConnectedStartup );
break;
}
}
}