VMware Cloud Community
esstokes1
Enthusiast
Enthusiast

reconfigVM_Task

I have the following in my workflow (vm, vmNetwork, macAddr, customTagNames, and customTagValues are inputs to the script).

var spec = new VcVirtualMachineConfigSpec();

spec.deviceChange = new Array();

var deviceChange = new VcVirtualDeviceConfigSpec();

deviceChange.operation = VcVirtualDeviceConfigSpecOperation.add;

deviceChange.device = new VcVirtualVmxnet3();

deviceChange.device.key = -100;

deviceChange.device.backing = new VcVirtualEthernetCardNetworkBackingInfo();

deviceChange.device.backing.deviceName = vmNetwork;

deviceChange.device.connectable = new VcVirtualDeviceConnectInfo();

deviceChange.device.connectable.startConnected = true;

deviceChange.device.connectable.allowGuestControl = true;

deviceChange.device.connectable.connected = true;

deviceChange.device.controllerKey = 100;

deviceChange.device.addressType = "Manual";

deviceChange.device.macAddress = macAddr;

deviceChange.device.wakeOnLanEnabled = true;

spec.deviceChange[0] = deviceChange;  // i've also tried doing spec.deviceChange.push(deviceChange)

// custom tags are vApp properties

if (customTagNames.length > 0) {

  spec.vAppConfig = new VcVmConfigSpec();

  spec.vAppConfig.property = new Array();

  for (var i=0 ; i<customTagNames.length ; i++) {

    System.log("adding vApp Property "+ customTagNames[i] +" with value "+ customTagValues[i]);

    var vAppProperty = new VcVAppPropertySpec();

    vAppProperty.operation = VcArrayUpdateOperation.add;

    vAppProperty.info =  new VcVAppPropertyInfo();

    vAppProperty.info.key = i;

    vAppProperty.info.classId = "";

    vAppProperty.info.instanceId = "";

    vAppProperty.info.id = customTagNames[i];

    vAppProperty.info.category = "";

    vAppProperty.info.label = customTagNames[i];

    vAppProperty.info.type = "string";

    vAppProperty.info.userConfigurable = true;

    vAppProperty.info.defaultValue = customTagValues[i];

    vAppProperty.info.value = "";

    vAppProperty.info.description = "";

    spec.vAppConfig.property[i] = vAppProperty;  // i've also tried spec.vAppConfig.property.push(vAppProperty)

  }

}

reconfigTask = vm.reconfigVM_Task(spec);  // VirtualMachine

When I run the workflow I can see the VM get reconfigured inside vCenter but no changes are made.  Is there something incorrect in the script that I'm missing?  I have something very similar in PowerCLI that works fine - I'm just trying to convert it from PowerCLI.

Reply
0 Kudos
1 Reply
esstokes1
Enthusiast
Enthusiast

Wanted to post this in case anyone else is struggling with this:

// config spec

var configSpec = new VcVirtualMachineConfigSpec();

// add the NIC

var deviceChangeSpecs = new Array();

var deviceChange;

var ii = 0;

deviceChange = System.getModule("com.vmware.library.vc.vm.spec.config.device").createVirtualEthernetCardNetworkConfigSpec(network,macAddr,"vmxnet3");

deviceChangeSpecs[ii++] = deviceChange;

configSpec.deviceChange = deviceChangeSpecs;

// add any customTag

if (customTags != null) {

  var vAppConfig = new VcVmConfigSpec();

  var vAppConfigProperty = new Array();

  var ii = 0;

  for each (var key in customTags.keys) {

System.log("adding a custom tag");

    var vAppProperty = new VcVAppPropertySpec();

    vAppProperty.operation = VcArrayUpdateOperation.add;

    vAppProperty.info =  new VcVAppPropertyInfo();

    vAppProperty.info.key = ii;

    vAppProperty.info.classId = "";

    vAppProperty.info.instanceId = "";

    vAppProperty.info.id = key;

    vAppProperty.info.category = "";

    vAppProperty.info.label = key;

    vAppProperty.info.type = "string";

    vAppProperty.info.userConfigurable = true;

    vAppProperty.info.defaultValue = customTags.get(key).toString();

    vAppProperty.info.value = "";

    vAppProperty.info.description = "";

    vAppConfigProperty[ii++] = vAppProperty;

  }

  vAppConfig.property = vAppConfigProperty;

  configSpec.vAppConfig = vAppConfig;

}

reconfigTask = vm.reconfigVM_Task(configSpec);

Reply
0 Kudos