VMware Cloud Community
Nachete
Contributor
Contributor
Jump to solution

Add physical to standard vswitch with orchestrator

I need to create a flow to manage physical network interfaces with standard vSwitches.

I can't find any sample or code to do it with orchestrator (using vro 7.2).

How can I create a custom script to assign one physical nic to one virtual switch?

Thanks.

Best regards.

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

jarushepic​ - this won't work; the last line will not cause a vCenter API to be called.

Nachete​ - you can check the code suggested by Joerg in this old thread - https://communities.vmware.com/thread/338685 . It shows how to call the corresponding vCenter API to update the switch. You just need to find the proper switch name and nic name.

View solution in original post

10 Replies
jarushepic
Enthusiast
Enthusiast
Jump to solution

Haven't done this before, but you should be able to loop over the NICs and identify the one you want by iterating over VcHostSystem.config.network.pnic (array of VcPhysicalNic).  You'll also need to get the VcHostVirtualSwitch object, which is VcHostSystem.config.network.vswitch (array of VcHostVirtualSwitch).  Once you have those, try and add the VcPhysicalNic object to the VcHostVirtualSwitch.pnic property.

so something like:

var pnicToAdd = null;

var switchToUse = null;

for each (var pnic in host.config.network.pnic)

{

     if (pnic.device.indexOf('vmnic1') != -1)

     {

          pnicToAdd = pnic;

          break;

     }

}

if (pnicToAdd == null) {throw 'couldnt find a nic';}

for each (var switch in host.config.network.vswitch)

{

     if (switch.name == 'MyAwesomeStandardSwitch')

     {

          switchToUse = switch;

          break;

     }

}

if (switchToUse == null) {throw 'couldnt find switch';}

switchToUse.pnic.push(pnicToAdd);

iiliev
VMware Employee
VMware Employee
Jump to solution

jarushepic​ - this won't work; the last line will not cause a vCenter API to be called.

Nachete​ - you can check the code suggested by Joerg in this old thread - https://communities.vmware.com/thread/338685 . It shows how to call the corresponding vCenter API to update the switch. You just need to find the proper switch name and nic name.

Nachete
Contributor
Contributor
Jump to solution

jarushepic thanks for your help.

the code suggested by Joerg works perfect, thanks for your help!

0 Kudos
Nachete
Contributor
Contributor
Jump to solution

another question with suggested code,

  1. // ------- UpdateVirtualSwitch -------  
  2.   
  3. var spec = new VcHostVirtualSwitchSpec();  
  4.   
  5. spec.numPorts = 128;  
  6.   
  7. spec.bridge = new VcHostVirtualSwitchBondBridge();  
  8. //spec.bridge.nicDevice = System.getModule("com.vmware.onyx").array(String, 1);  
  9. //spec.bridge.nicDevice[0] = "vmnic1";  
  10.   
  11. var nicArray = new Array();  
  12. var nic = new String("vmnic1");  
  13. nicArray.push(nic);  
  14. spec.bridge.nicDevice = nicArray;  
  15.   
  16. System.debug("spec: " + spec);  
  17. System.debug("nicdevice: " + spec.bridge.nicDevice);  
  18.   
  19. var confMgr = currentHost.configManager;  
  20. var theHostsHostNetworkSystem = confMgr.networkSystem;  
  21. theHostsHostNetworkSystem.updateVirtualSwitch("vSwitch1", spec); // HostNetworkSystem  

 

i try with this and can add vmnic, also replaces the existent one vmnic, it works great, but it's possible remove vmnic? (leave vswitch without uplinks for example)

Thanks

Best regards

0 Kudos
Nachete
Contributor
Contributor
Jump to solution

Answer myself, this happens when one not read:

http://www.vroapi.com/Method/VC/6.5.0/VcHostNetworkSystem/updateVirtualSwitch

Method updateVirtualSwitch(String arg0, VcHostVirtualSwitchSpec arg1)

Updates the properties of the virtual switch.

If the bridge is NULL, the configuration will be unset.

If a network adapter is listed in the active or standby list, then changing the set of network adapters to which the physical network adapter is associated may have a side effect of changing the network adapter order policy. If a network adapter is removed from the bridge configuration, then the network adapter is removed from the network adapter teaming order.

.

spec.bridge = null; 

0 Kudos
subnet75
Contributor
Contributor
Jump to solution

Guys, im using the vRO 7.3 and i dont see the "nicDevice" under VcHostVirtualSwitchBondBridge(). but same time i can see the "nicDevice" under VcHostVirtualSwitchSimpleBondBridge().

how do i call VcHostVirtualSwitchSimpleBondBridge() to bond the physical NIC. apprecaite

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hmm, looking in API Explorer in my vRO 7.3 instance, I do see nicDevice property for VcHostVirtualSwitchBondBridge

Also, I don't see such type as VcHostVirtualSwitchSimpleBondBridge. Did you mean VcHostVirtualSwitchSimpleBridge (but it also has nicDevice property)?

0 Kudos
subnet75
Contributor
Contributor
Jump to solution

Let me explain little detail:  under the vchostvirtual switch spec , "bridge" return type is  " VcHostVirtualSwitchBridge() "  and i dont see here nicDevice.

how do i use or call nicDevice using the "vchostvirtual spec" , the bridge is calling as i said above " VcHostVirtualSwitchBridge()" here we dont see nicDevice.

var config = new VcHostNetworkConfig();

config.vswitch = [new VcHostVirtualSwitchConfig()] ;

config.vswitch[0].changeOperation = "add";

config.vswitch[0].name = storageA;

config.vswitch[0].spec = new VcHostVirtualSwitchSpec() ;

config.vswitch[0].spec.numPorts = 128;

config.vswitch[0].spec.bridge = new VcHostVirtualSwitchBondBridge();

config.vswitch[0].spec.bridge.

var hostnames = VcPlugin.convertToVimManagedObject(clusterName, clusterName.host);

for each (var hostname in hostnames){

hostname.configManager.networkSystem.updateNetworkConfig(config, "modify");

}

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

OK, in the VcHostVirtualSwitchSpec class, the property bridge is of type VcHostVirtualSwitchBridge.

In the vCenter API class hierarchy, HostVirtualSwitchBridge is a base class for other classes like HostVirtualSwitchAutoBridge, HostVirtualSwitchBondBridge, and HostVirtualSwitchSimpleBridge.

In the code

config.vswitch[0].spec.bridge = new VcHostVirtualSwitchBondBridge();

you assign a value to the bridge property to be an instance of the derived class VcHostVirtualSwitchBondBridge, not of the base class VcHostVirtualSwitchBridge . And the derived class does have a property nicDevice (of type Array of String), so you can set it via code something like:

config.vswitch[0].spec.bridge.nicDevice = [ "myNicDevice" ]

subnet75
Contributor
Contributor
Jump to solution

thank you so much -it solved me , almost killing myself last 2 days on this..... im missing the Array for NIC. Smiley Happy

0 Kudos