def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
 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(vutil, 'get_object_property', host_mor, '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:
  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 ) : 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 ( vutil , 'get_object_property' , host_mor , '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 : LOG . debug ( 'Port Group %s already exists.' , pg_name ) LOG . debug ( 'Created Port Group with name %s on the ESX host' , pg_name )
creates a port group on the host system with the vlan tags supplied .