Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

how to auto change portgroup of NIC in vSphere by API script

$
0
0

hi experts,

These days I want to write a workflow in VCO to auto change port group of NIC.(AS attachment pic shows)

For two given VM: SampleVM and DestVM. If they are in different port groups, I want to allocate DestVM to the port group of SampleVM automatically through workflow.

 

Scripts can be seen as follows:

 

var SampleDevs = SampleVM.config.Hardware.Device;

var DestDevs = DestVM.config.Hardware.Device;

var SampleNic = null;

var DestNic = null;

for (var i in  SampleDevs)

{

if( SampleDevs[i].deviceInfo.Label == "Network adapter 1" )

SampleNic =  SampleDevs[i]; //return sampleVM's network adapter

}

 

for (var i in  DestDevs)

{

if( DestDevs[i].deviceInfo.Label == "Network adapter 1" )

DestNic =  DestDevs[i];  //return DestVM's network adapter

}

var spec = new VcVirtualMachineConfigSpec();

//spec.changeVersion = DestVM.config.changeVersion;

spec.Version = DestVM.config.Version;

var nicDev = new VcVirtualDeviceConfigSpec();

nicDev.operation = "edit";

nicDev.device = DestNic;

nicDev.device.backing = SampleNic.backing;

nicDev.device.deviceInfo.summary = SampleNic.deviceInfo.sumarry;

spec.deviceChange += nivDev;

 

But it can not work. Who can tell me how to modify the script? Thanks sincerely.

 

Martin Ding from EMC

var SampleDevs = SampleVM.config.Hardware.Device;
var DestDevs = DestVM.config.Hardware.Device;
var SampleNic = null;
var DestNic = null;
for (var i in  SampleDevs)
{
if( SampleDevs[i].deviceInfo.Label == "Network adapter 1" )
SampleNic =  SampleDevs[i];
}
 
for (var i in  DestDevs)
{
if( DestDevs[i].deviceInfo.Label == "Network adapter 1" )
DestNic =  DestDevs[i];
}
 
var spec = new VcVirtualMachineConfigSpec();
//spec.changeVersion = DestVM.config.changeVersion;
spec.Version = DestVM.config.Version;
 
 
//spec.deviceChange = [new VcVirtualDeviceConfigSpec()];
////spec.deviceChange[0].operation = [new VcVirtualDeviceConfigSpecOperation()];
////spec.deviceChange[0].operation.fromString("edit");
//spec.deviceChange.operarion = "edit";
////System.log(spec.deviceChange[0].operation);
////spec.deviceChange.device = DestNic;
//System.log(SampleNic.deviceInfo.label);
//System.log(SampleNic.deviceInfo.summary);
//System.log(SampleNic);
//spec.deviceChange.device.backing = SampleNic.backing;
//spec.deviceChange.device.deviceInfo.summary = SampleNic.deviceInfo.sumarry;
//DestVM.reconfigVM_Task(spec);
 
var nicDev = new VcVirtualDeviceConfigSpec();
//System.log(nicDev);
nicDev.operation = "edit";
nicDev.device = DestNic;
nicDev.device.backing = SampleNic.backing;
nicDev.device.deviceInfo.summary = SampleNic.deviceInfo.sumarry;
spec.deviceChange += nivDev;
 

Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>