def get_attach_port_index(session, vm_ref):
 ports = _get_vm_port_indices(session, vm_ref)
 if (not ports):
  return 0
 ports.sort()
 configured_ports_len = len(ports)
 for port_index in range(configured_ports_len):
  if (port_index != ports[port_index]):
   return port_index
 return configured_ports_len

def get_attach_port_index ( session , vm_ref ) : ports = _get_vm_port_indices ( session , vm_ref ) if ( not ports ) : return 0 ports . sort ( ) configured_ports_len = len ( ports ) for port_index in range ( configured_ports_len ) : if ( port_index != ports [ port_index ] ) : return port_index return configured_ports_len
get the first free port index .