VMware Cloud Community
avarcher
Commander
Commander
Jump to solution

Add a pNic to a Standard vSwitch

I hope there is an easy answer here. I have created the vSwitch, "vSwitch1", and all I need to do now is add vmnic1 to it. I cant find any existing workflows or actions so I resort to Onyx;

// ------- UpdateVirtualSwitch -------

var spec = new VcHostVirtualSwitchSpec();

spec.numPorts = 128;

spec.bridge = new VcHostVirtualSwitchBondBridge();

spec.bridge.nicDevice = System.getModule("com.vmware.onyx").array(String, 1);

spec.bridge.nicDevice[0] = "vmnic1";

spec.policy = new VcHostNetworkPolicy();

spec.policy.security = new VcHostNetworkSecurityPolicy();

spec.policy.security.allowPromiscuous = false;

spec.policy.security.macChanges = true;

spec.policy.security.forgedTransmits = true;

spec.policy.nicTeaming = new VcHostNicTeamingPolicy();

spec.policy.nicTeaming.policy = "loadbalance_srcid";

spec.policy.nicTeaming.reversePolicy = true;

spec.policy.nicTeaming.notifySwitches = true;

spec.policy.nicTeaming.rollingOrder = false;

spec.policy.nicTeaming.failureCriteria = new VcHostNicFailureCriteria();

spec.policy.nicTeaming.failureCriteria.checkSpeed = "minimum";

spec.policy.nicTeaming.failureCriteria.speed = 10;

spec.policy.nicTeaming.failureCriteria.checkDuplex = false;

spec.policy.nicTeaming.failureCriteria.fullDuplex = false;

spec.policy.nicTeaming.failureCriteria.checkErrorPercent = false;

spec.policy.nicTeaming.failureCriteria.percentage = 0;

spec.policy.nicTeaming.failureCriteria.checkBeacon = false;

spec.policy.nicTeaming.nicOrder = new VcHostNicOrderPolicy();

spec.policy.nicTeaming.nicOrder.activeNic = System.getModule("com.vmware.onyx").array(String, 1);

spec.policy.nicTeaming.nicOrder.activeNic[0] = "vmnic1";

spec.policy.offloadPolicy = new VcHostNetOffloadCapabilities();

spec.policy.offloadPolicy.csumOffload = true;

spec.policy.offloadPolicy.tcpSegmentation = true;

spec.policy.offloadPolicy.zeroCopyXmit = true;

spec.policy.shapingPolicy = new VcHostNetworkTrafficShapingPolicy();

spec.policy.shapingPolicy.enabled = false;

managedObject.updateVirtualSwitch("vSwitch1", spec); // HostNetworkSystem

I change the last line to ;

currentHost.configManager.networkSystem.updateVirtualSwitch(nameOfSwitchForProduction, spec);

Where currentHost is the host object and nameOfSwitchForProduction is the valid string name for the created switch.

Everytime I get 'The object or item referred to could not be found' yet the switch vSwitch1 is there and vmnic1 exists.

Where am I going wrong?

Thanks, Andy.

Reply
0 Kudos
1 Solution

Accepted Solutions
tschoergez
Leadership
Leadership
Jump to solution

ok, maybe this one is not that easy: You have to create the arrays manually, and can not use the Onyx-method (might be related to a bug in vCO => see release notes somewhere under misc.. known issues):

// ------- UpdateVirtualSwitch -------

var spec = new VcHostVirtualSwitchSpec();

spec.numPorts = 128;

spec.bridge = new VcHostVirtualSwitchBondBridge();
//spec.bridge.nicDevice = System.getModule("com.vmware.onyx").array(String, 1);
//spec.bridge.nicDevice[0] = "vmnic1";

var nicArray = new Array();
var nic = new String("vmnic1");
nicArray.push(nic);
spec.bridge.nicDevice = nicArray;

System.debug("spec: " + spec);
System.debug("nicdevice: " + spec.bridge.nicDevice);

var confMgr = currentHost.configManager;
var theHostsHostNetworkSystem = confMgr.networkSystem;
theHostsHostNetworkSystem.updateVirtualSwitch("vSwitch1", spec); // HostNetworkSystem

So: Never blindly trust Onyx' output, only let it guide you to the proper path in the API Reference! (, my young Padavan Smiley Wink)

Cheers,

Joerg

View solution in original post

4 Replies
tschoergez
Leadership
Leadership
Jump to solution

Hi Andy,

that could be an easy one, and your last line already shows the answer in the comment:

The ManagedObject in the last line may not be the Host itself, but its NetworkHostSystem-object:

var theHostsHostNetworkSystem = currentHost.configManager.networkSystem;
theHostsHostNetworkSystem.updateVirtualSwitch("vSwitch1", spec); // HostNetworkSystem

So, back to school, and repeat what I tought you about the API Explorer, API Reference and Managed Object Browser :smileysilly:.

edit: Forget about this answer, I just did not read properly your code. So, note to myself: back to school, and repeat what you learned about readCarefullyBeforeOpenYourMouth :smileyblush::smileyblush::smileyblush:.

Cheers,

Joerg

tschoergez
Leadership
Leadership
Jump to solution

ok, maybe this one is not that easy: You have to create the arrays manually, and can not use the Onyx-method (might be related to a bug in vCO => see release notes somewhere under misc.. known issues):

// ------- UpdateVirtualSwitch -------

var spec = new VcHostVirtualSwitchSpec();

spec.numPorts = 128;

spec.bridge = new VcHostVirtualSwitchBondBridge();
//spec.bridge.nicDevice = System.getModule("com.vmware.onyx").array(String, 1);
//spec.bridge.nicDevice[0] = "vmnic1";

var nicArray = new Array();
var nic = new String("vmnic1");
nicArray.push(nic);
spec.bridge.nicDevice = nicArray;

System.debug("spec: " + spec);
System.debug("nicdevice: " + spec.bridge.nicDevice);

var confMgr = currentHost.configManager;
var theHostsHostNetworkSystem = confMgr.networkSystem;
theHostsHostNetworkSystem.updateVirtualSwitch("vSwitch1", spec); // HostNetworkSystem

So: Never blindly trust Onyx' output, only let it guide you to the proper path in the API Reference! (, my young Padavan Smiley Wink)

Cheers,

Joerg

avarcher
Commander
Commander
Jump to solution

Hi Joerg

I'm glad to have presented you with a challenge :smileydevil: and I'm happy to report 100% success :smileylaugh:.

sw.jpg

You are correct on all levels with this, I think you did tell me that the network api organisation was probably one of the more complex and that is how I am experienceing it so maybe not the best one to make a start with.

So, use Onyx as a guide and use the API documentation.

Where I am struggling a bit is taking what I'm reading in the API and applying it to workflows. However, I think I'll take your working answer and study it beside the API till I get it.

Thanks again oh master Smiley Wink

Cheers, Andy

Reply
0 Kudos
MaxB
Enthusiast
Enthusiast
Jump to solution

Hi everybody

it tried the code snippet and it failed Smiley Sad

After some testing I replaces this region:

var nicArray = new Array();

var nic = new String("vmnic1");

nicArray.push(nic);

spec.bridge.nicDevice = nicArray;

with this one:

var nicArray = new Array();

nicArray.push("vmnic1");

spec.bridge.nicDevice = nicArray;

after that it worked fine for me. But I don´t have a clue where the difference in these code snippets is.

I hope it helps anyone out there. And if it´s me who can´t remember why it didn´t work and finding this post.

Reply
0 Kudos