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.
- Obtain information about the current networking configuration.You can use a property collector to retrieve theHostNetworkSystemmanaged object and several of its properties, such asnetworkInfo.
- Define aHostVirtualSwitchSpecthat specifies the attributes of the virtual switch. You can specify the number of ports (56 to 4088 on ESXi systems) and theHostNetworkPolicy. See “Defining the Host Network Policies” on page 122.
- CallHostNetworkSystem.AddVirtualSwitchto add a virtual switch. Specify a unique name and aHostVirtualSwitchSpecthat defines the switch attributes.The following fragment fromAddVirtualSwitch.javaillustrates this.
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);