def handle_get(self, request, user, *args, **kwargs): """Handles GET requests to find EnvironmentInterface. URLs: int/get-env-by-interface/<id_interface> """ self.log.info('buscando os ambientes associados a uma interface') try: # User permission if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION): self.log.error( u'User does not have permission to perform the operation.') return self.not_authorized() # Get XML data interface = kwargs.get('id_interface') int_ambiente = EnvironmentInterface.get_by_interface(int(interface)) ambiente_map = [] for ids in int_ambiente: ambiente_map.append(self.get_environment_map(ids.ambiente)) return self.response(dumps_networkapi({'ambiente': ambiente_map})) except InvalidValueError, e: return self.response_error(269, e.param, e.value)
def handle_get(self, request, user, *args, **kwargs): """Handles GET requests to find EnvironmentInterface. URLs: int/get-env-by-interface/<id_interface> """ self.log.info('buscando os ambientes associados a uma interface') try: # User permission if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION): self.log.error( u'User does not have permission to perform the operation.') return self.not_authorized() # Get XML data interface = kwargs.get('id_interface') int_ambiente = EnvironmentInterface.get_by_interface( int(interface)) ambiente_map = [] for ids in int_ambiente: ambiente_map.append( self.get_environment_map(ids.ambiente, ids.vlans)) return self.response(dumps_networkapi({'ambiente': ambiente_map})) except InvalidValueError, e: return self.response_error(269, e.param, e.value)
def get_vlan_range(interface): # TODO Generate vlan range env_ints = EnvironmentInterface.get_by_interface(interface.id) vlan_range = '' vlan_range_list = [] for env_int in env_ints: if env_int.vlans: vlan_range_temp = env_int.vlans vlan_range_list_temp = [vlan_range_temp] else: vlan_range_1 = str(env_int.ambiente.min_num_vlan_1) + \ '-' + str(env_int.ambiente.max_num_vlan_1) vlan_range_2 = str(env_int.ambiente.min_num_vlan_2) + \ '-' + str(env_int.ambiente.max_num_vlan_2) if vlan_range_1 is not vlan_range_2: vlan_range_temp = vlan_range_1 + ',' + vlan_range_2 vlan_range_list_temp = [vlan_range_1, vlan_range_2] else: vlan_range_temp = vlan_range_1 vlan_range_list_temp = [vlan_range_1] if vlan_range is '': vlan_range = vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) elif vlan_range_temp not in vlan_range: vlan_range += ',' + vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) if vlan_range == '': raise exceptions.InterfaceTrunkAllowedVlanException() return [vlan_range, vlan_range_list]
def get_vlan_range(interface): log.info("get_vlan_range") # TODO Generate vlan range env_ints = EnvironmentInterface.get_by_interface(interface.id) vlan_range = '' vlan_range_list = [] for env_int in env_ints: #This test is not good. Has to be treated elsewhere with plugins if interface.equipamento.modelo.marca.nome == "HP": separator = ' to ' range_list_separator = ' ' else: separator = '-' range_list_separator = ',' if env_int.vlans: vlan_range_temp = env_int.vlans vlan_range_temp = vlan_range_temp.replace('-', separator) vlan_range_list_temp = [vlan_range_temp] else: vlan_range_1 = str(env_int.ambiente.min_num_vlan_1) + \ separator + str(env_int.ambiente.max_num_vlan_1) vlan_range_2 = str(env_int.ambiente.min_num_vlan_2) + \ separator + str(env_int.ambiente.max_num_vlan_2) if vlan_range_1 is not vlan_range_2: vlan_range_temp = vlan_range_1 + range_list_separator + vlan_range_2 vlan_range_list_temp = [vlan_range_1, vlan_range_2] else: vlan_range_temp = vlan_range_1 vlan_range_list_temp = [vlan_range_1] if vlan_range is '': vlan_range = vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) elif vlan_range_temp not in vlan_range: vlan_range += range_list_separator + vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) if vlan_range == '': raise exceptions.InterfaceTrunkAllowedVlanException() return [vlan_range, vlan_range_list]
def get_vlan_range(interface): log.info("get_vlan_range") # TODO Generate vlan range env_ints = EnvironmentInterface.get_by_interface(interface.id) vlan_range = '' vlan_range_list = [] for env_int in env_ints: #This test is not good. Has to be treated elsewhere with plugins if interface.equipamento.modelo.marca.nome == "HP": separator = ' to ' range_list_separator = ' ' else: separator = '-' range_list_separator = ',' if env_int.vlans: vlan_range_temp = env_int.vlans vlan_range_temp = vlan_range_temp.replace('-', separator) vlan_range_list_temp = [vlan_range_temp] else: vlan_range_1 = str(env_int.ambiente.min_num_vlan_1) + \ separator + str(env_int.ambiente.max_num_vlan_1) vlan_range_2 = str(env_int.ambiente.min_num_vlan_2) + \ separator + str(env_int.ambiente.max_num_vlan_2) if vlan_range_1 is not vlan_range_2: vlan_range_temp = vlan_range_1 + range_list_separator + vlan_range_2 vlan_range_list_temp = [vlan_range_1, vlan_range_2] else: vlan_range_temp = vlan_range_1 vlan_range_list_temp = [vlan_range_1] if vlan_range is '': vlan_range = vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) elif vlan_range_temp not in vlan_range: vlan_range += range_list_separator + vlan_range_temp vlan_range_list.extend(vlan_range_list_temp) if vlan_range == '': raise exceptions.InterfaceTrunkAllowedVlanException() return [vlan_range, vlan_range_list]
def get_vlan_range(interface): #TODO Generate vlan range env_ints = EnvironmentInterface.get_by_interface(interface.id) vlan_range = "" for env_int in env_ints: vlan_range_1 = str(env_int.ambiente.min_num_vlan_1)+"-"+str(env_int.ambiente.max_num_vlan_1) vlan_range_2 = str(env_int.ambiente.min_num_vlan_2)+"-"+str(env_int.ambiente.max_num_vlan_2) if vlan_range_1 is not vlan_range_2: vlan_range_temp = vlan_range_1+","+vlan_range_2 else: vlan_range_temp = vlan_range_1 if vlan_range is "": vlan_range = vlan_range_temp elif vlan_range_temp not in vlan_range: vlan_range += ","+vlan_range_temp return vlan_range