def create_port_group(session, pg_name, vswitch_name, vlan_id=0): """ Creates a port group on the host system with the vlan tags supplied. VLAN id 0 means no vlan id association. """ client_factory = session._get_vim().client.factory add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( client_factory, vswitch_name, pg_name, vlan_id) host_mor = session._call_method(vim_util, "get_objects", "HostSystem")[0].obj network_system_mor = session._call_method(vim_util, "get_dynamic_property", host_mor, "HostSystem", "configManager.networkSystem") LOG.debug(_("Creating Port Group with name %s on " "the ESX host") % pg_name) try: session._call_method(session._get_vim(), "AddPortGroup", network_system_mor, portgrp=add_prt_grp_spec) except error_util.VimFaultException, exc: # There can be a race condition when two instances try # adding port groups at the same time. One succeeds, then # the other one will get an exception. Since we are # concerned with the port group being created, which is done # by the other call, we can ignore the exception. if error_util.FAULT_ALREADY_EXISTS not in exc.fault_list: raise exception.Error(exc)
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None): """ Creates a port group on the host system with the vlan tags supplied. VLAN id 0 means no vlan id association. """ client_factory = session._get_vim().client.factory add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( client_factory, vswitch_name, pg_name, vlan_id) host_mor = vm_util.get_host_ref(session, cluster) network_system_mor = session._call_method(vim_util, "get_dynamic_property", host_mor, "HostSystem", "configManager.networkSystem") LOG.debug( _("Creating Port Group with name %s on " "the ESX host") % pg_name) try: session._call_method(session._get_vim(), "AddPortGroup", network_system_mor, portgrp=add_prt_grp_spec) except error_util.AlreadyExistsException: # There can be a race condition when two instances try # adding port groups at the same time. One succeeds, then # the other one will get an exception. Since we are # concerned with the port group being created, which is done # by the other call, we can ignore the exception. LOG.debug(_("Port Group %s already exists."), pg_name) LOG.debug( _("Created Port Group with name %s on " "the ESX host") % pg_name)
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None): """Creates a port group on the host system with the vlan tags supplied. VLAN id 0 means no vlan id association. """ client_factory = session.vim.client.factory add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( client_factory, vswitch_name, pg_name, vlan_id) host_mor = vm_util.get_host_ref(session, cluster) network_system_mor = session._call_method(vim_util, "get_dynamic_property", host_mor, "HostSystem", "configManager.networkSystem") LOG.debug("Creating Port Group with name %s on " "the ESX host", pg_name) try: session._call_method(session.vim, "AddPortGroup", network_system_mor, portgrp=add_prt_grp_spec) except vexc.AlreadyExistsException: # There can be a race condition when two instances try # adding port groups at the same time. One succeeds, then # the other one will get an exception. Since we are # concerned with the port group being created, which is done # by the other call, we can ignore the exception. LOG.debug("Port Group %s already exists.", pg_name) LOG.debug("Created Port Group with name %s on " "the ESX host", pg_name)