def make_pg(self, vswitch, pg_name, vlan, uplink="lag1"): """ Create a new Port Group on a vSwitch. Arguments: :param vswitch: the vSwitch on which to make the port group (see `get_vdswitch`) :param pg_name: the name for the new distributed port group :param vlan: the VLAN ID for the new distributed port group :param uplink: the name of the uplink to use """ spec = vim.DVPortgroupConfigSpec() spec.name = pg_name spec.numPorts = 32 spec.type = vim.DistributedVirtualPortgroupPortgroupType.earlyBinding cfg = vim.VMwareDVSPortSetting() cfg.vlan = vim.VmwareDistributedVirtualSwitchVlanIdSpec() cfg.vlan.vlanId = vlan cfg.vlan.inherited = False policy = vim.VmwareUplinkPortTeamingPolicy() policy.uplinkPortOrder = vim.VMwareUplinkPortOrderPolicy() policy.uplinkPortOrder.activeUplinkPort = [uplink] policy.uplinkPortOrder.standbyUplinkPort = [] cfg.uplinkTeamingPolicy = policy cfg.securityPolicy = vim.DVSSecurityPolicy() cfg.securityPolicy.allowPromiscuous = vim.BoolPolicy(value=True) cfg.securityPolicy.forgedTransmits = vim.BoolPolicy(value=True) cfg.securityPolicy.macChanges = vim.BoolPolicy(value=False) cfg.securityPolicy.inherited = False spec.defaultPortConfig = cfg self.wait_for_tasks([vswitch.AddDVPortgroup_Task([spec])])
def create_port_group(self): config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec() config.name = self.portgroup_name config.numPorts = self.num_ports # vim.VMwareDVSPortSetting() does not exist in the pyvmomi documentation # but this is the correct managed object type. # config.defaultPortConfig = vim.VMwareDVSPortSetting() config.defaultPortConfig = vim.dvs.VmwareDistributedVirtualSwitch.VmwarePortConfigPolicy( ) config.defaultPortConfig.securityPolicy = vim.dvs.VmwareDistributedVirtualSwitch.SecurityPolicy( ) config.defaultPortConfig.securityPolicy.allowPromiscuous = vim.BoolPolicy( value=self.promiscuous_mode) config.defaultPortConfig.securityPolicy.forgedTransmits = vim.BoolPolicy( value=self.forged_transmits) config.defaultPortConfig.securityPolicy.macChanges = vim.BoolPolicy( value=self.mac_changes) # vim.VmwareDistributedVirtualSwitchVlanIdSpec() does not exist in the # pyvmomi documentation but this is the correct managed object type config.defaultPortConfig.vlan = vim.VmwareDistributedVirtualSwitchVlanIdSpec( ) config.defaultPortConfig.vlan.inherited = False config.defaultPortConfig.vlan.vlanId = self.vlan_id config.type = self.portgroup_type spec = [config] task = self.dv_switch.AddDVPortgroup_Task(spec) changed, result = wait_for_task(task) return changed, result
def create_port_group(self): config = vim.dvs.DistributedVirtualPortgroup.ConfigSpec() config.name = self.portgroup_name config.numPorts = self.num_ports # vim.VMwareDVSPortSetting() does not exist in the pyvmomi documentation # but this is the correct managed object type. config.defaultPortConfig = vim.VMwareDVSPortSetting() # vim.VmwareDistributedVirtualSwitchVlanIdSpec() does not exist in the # pyvmomi documentation but this is the correct managed object type config.defaultPortConfig.vlan = vim.VmwareDistributedVirtualSwitchVlanIdSpec() config.defaultPortConfig.vlan.inherited = False config.defaultPortConfig.vlan.vlanId = self.vlan_id config.type = self.portgroup_type spec = [config] task = self.dv_switch.AddDVPortgroup_Task(spec) changed, result = wait_for_task(task) return changed, result
def vlan(vlan_tag): spec = vim.VmwareDistributedVirtualSwitchVlanIdSpec() spec.inherited = False spec.vlanId = vlan_tag return spec