Adding a Standard Virtual Switch

You call the HostNetworkSystem.AddVirtualSwitch method to add one or more virtual switches. Pass in the name of the virtual switch and a HostVirtualSwitchSpec data object as parameters.

Inside HostVirtualSwitchSpec you can specify the MTU, number of ports, network policy, and bridge specification. The bridge specifies how the virtual switch connects to the physical adapter. The currently supported bond bridge provides network adapter (NIC) teaming capabilities through the use of a list of physical devices and, optionally, a beacon probe to test connectivity with physical adapters.

After you have created the virtual switch, you can connect it to a pnic for connection to the outside, and to a VMkernel port or a port group.

To add a virtual switch, use the following steps.

Procedure

  1. Obtain information about the current networking configuration.

    You can use a property collector to retrieve the HostNetworkSystem managed object and several of its properties, such as networkInfo.

  2. Define a HostVirtualSwitchSpec that specifies the attributes of the virtual switch. You can specify the number of ports (56 to 4088 on ESXi systems) and the HostNetworkPolicy. See “Defining the Host Network Policies” on page 122.
  3. Call HostNetworkSystem.AddVirtualSwitch to add a virtual switch. Specify a unique name and a HostVirtualSwitchSpec that defines the switch attributes.

    The following fragment from AddVirtualSwitch.java illustrates this.

Example: Adding a Virtual Switch

vswitchId = vSwitch42;
...
ManagedObjectReference nwSystem = configMgr.getNetworkSystem();
HostVirtualSwitchSpec spec = new HostVirtualSwitchSpec();
spec.setNumPorts(8);
service.addVirtualSwitch(nwSystem, vswitchId, spec);
System.out.println( " : Successful creating : " + vswitchId);