def delete_interface(request, interface_id=None): auth = AuthSession(request.session) equip_interface = auth.get_clientFactory().create_api_interface_request() try: equip_interface.remove([interface_id]) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_remove")) except NetworkAPIClientError as e: message = str( error_messages.get("can_not_remove_error")) + " " + str(e) logger.error(e) messages.add_message(request, messages.WARNING, message) except ValueError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) except Exception as e: logger.error(e) messages.add_message(request, messages.ERROR, e) url = request.META.get('HTTP_REFERER') if request.META.get( 'HTTP_REFERER') else reverse('interface.list') return HttpResponseRedirect(url)
def delete_channel(request, channel_id=None): auth = AuthSession(request.session) client = auth.get_clientFactory() try: client.create_api_interface_request().remove_channel([channel_id]) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_remove_channel")) except ValueError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)
def disconnect(request, id_interface, back_or_front, equip_name, id_interf_edit): try: auth = AuthSession(request.session) client = auth.get_clientFactory() client.create_api_interface_request().remove_connection(id_interface, back_or_front) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_disconnect")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)
def delete_channel(request, channel_id=None): auth = AuthSession(request.session) client = auth.get_clientFactory() try: client.create_api_interface_request().remove_channel([channel_id]) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_remove_channel")) except ValueError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)
def delete_interface(request, interface_id=None): auth = AuthSession(request.session) equip_interface = auth.get_clientFactory().create_api_interface_request() try: equip_interface.remove([interface_id]) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_remove")) except NetworkAPIClientError, e: message = str(error_messages.get("can_not_remove_error")) + " " + str(e) logger.error(e) messages.add_message(request, messages.WARNING, message)
def delete_interface(request, interface_id=None): auth = AuthSession(request.session) equip_interface = auth.get_clientFactory().create_api_interface_request() try: equip_interface.remove([interface_id]) messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_remove") ) except NetworkAPIClientError, e: message = str( error_messages.get("can_not_remove_error") ) + " " + str(e) logger.error(e) messages.add_message(request, messages.WARNING, message)
def delete_all(request): equip_nam = request.POST['equip_name'] if request.method == 'POST': form = DeleteForm(request.POST) if form.is_valid(): # Get user auth = AuthSession(request.session) equip_interface = auth.get_clientFactory().create_interface() # All ids to be deleted ids = split_to_array(form.cleaned_data['ids']) equip_nam = form.cleaned_data['equip_name'] # Control others exceptions have_errors = False # For each interface selected for id_es in ids: try: # Remove in NetworkAPI equip_interface.remover(id_es) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) have_errors = True break # If all has ben removed if have_errors == False: messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_remove")) else: messages.add_message( request, messages.WARNING, error_messages.get("can_not_remove_error")) else: messages.add_message(request, messages.ERROR, error_messages.get("select_one"))
def channel_delete(request): equip_nam = request.POST['equip_name'] if request.method == 'POST': form = DeleteChannelForm(request.POST) if form.is_valid(): # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() # All ids to be deleted ids = split_to_array(form.cleaned_data['ids_chan']) equip_nam = form.cleaned_data['equip_name'] # Control others exceptions have_errors = False for idt in ids: try: client.create_interface().delete_channel(idt) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) have_errors = True if have_errors == False: messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_remove_channel")) else: messages.add_message(request, messages.WARNING, error_messages.get("can_not_remove_error")) else: messages.add_message(request, messages.ERROR, error_messages.get("select_one"))
def add_channel(request, equip_name=None): lists = dict() lists['equip_name'] = equip_name try: auth = AuthSession(request.session) client = auth.get_clientFactory() equip = client.create_equipamento().listar_por_nome(str(equip_name)) equip = equip.get('equipamento') equip_interface_list = client.create_interface().list_all_by_equip(equip['id']) environment_list = get_equip_environment(client, equip['id']) if request.method == "GET": requestGet = request.GET['ids'] requestGet = requestGet.split("?") ids = requestGet[0] for var in ids.split('-'): if len(var) > 1: interface = var try: interface = client.create_interface().get_by_id(int(interface)) interface = interface.get('interface') except: messages.add_message(request, messages.ERROR, u'Interface %s não encontrada.' % var) return redirect('interface.list') if interface['channel'] is not None: messages.add_message(request, messages.ERROR, u'Interface %s já está associada ao channel %s.' % (interface['interface'],interface['channel'])) return redirect('interface.list') try: interface = interface['id_ligacao_front'] interface = client.create_interface().get_by_id(int(interface)) interface = interface.get('interface') except: messages.add_message(request, messages.ERROR, u'Interface não conectada') return redirect('interface.list') tipo = interface['tipo'] if "access" in tipo: tipo = 0 else: tipo = 1 form = ChannelAddForm(equip_interface_list, initial={'ids': ids, 'equip_name': equip_name, 'int_type': tipo, 'vlan': interface['vlan']}) lists['form'] = form if environment_list is not None: if tipo: envform = AddEnvInterfaceForm(environment_list) else: envform = AddEnvInterfaceForm(environment_list) lists['envform'] = envform else: messages.add_message(request, messages.WARNING, "O equipamento não possui ambientes cadastrados.") if request.method == "POST": form = ChannelAddForm(equip_interface_list, request.POST) lists['form'] = form if environment_list is not None: envform = AddEnvInterfaceForm(environment_list, request.POST) if form.is_valid(): name = form.cleaned_data['name'] lacp = form.cleaned_data['lacp'] int_type = form.cleaned_data['int_type'] vlan_nativa = form.cleaned_data['vlan'] interfaces_ids = form.cleaned_data['ids'] equip_nam = form.cleaned_data['equip_name'] if int_type == "0": int_type = "access" env_vlans_list = [] else: int_type = "trunk" if environment_list is None: messages.add_message(request, messages.ERROR, "O equipamento não possui ambientes cadastrados.") return render_to_response(EQUIPMENT_INTERFACE_ADD_CHANNEL, lists, context_instance=RequestContext(request)) if envform.is_valid(): environment = request.POST.getlist('environment') vlan_range = request.POST.getlist('vlans') env_vlans_list = env_vlans(environment_list.get("ambiente"), environment, vlan_range) try: client.create_interface().inserir_channel(interfaces_ids, name, lacp, int_type, vlan_nativa, env_vlans_list) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_insert_channel")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(EQUIPMENT_INTERFACE_ADD_CHANNEL, lists, context_instance=RequestContext(request)) except Exception, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(EQUIPMENT_INTERFACE_ADD_CHANNEL, lists, context_instance=RequestContext(request))
def connect_interfaces(request, id_interface=None, front_or_back=None, all_interfaces=None): auth = AuthSession(request.session) client = auth.get_clientFactory() lists = dict() lists['id_interface'] = id_interface lists['front_or_back'] = front_or_back if request.method == "GET": if request.GET.__contains__('search_equip'): equipment_name = request.GET.get('search_equip') logger.debug(equipment_name) else: try: int(all_interfaces) return render_to_response(NEW_INTERFACE_CONNECT_FORM, lists, RequestContext(request)) except Exception: equipment_name = all_interfaces data = dict() data["start_record"] = 0 data["end_record"] = 1000 data["asorting_cols"] = ["id"] data["searchable_columns"] = ["nome"] data["custom_search"] = equipment_name data["extends_search"] = [] equipment = list() try: search_equipment = client.create_api_equipment().search( search=data) equipment = search_equipment.get('equipments') except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) except Exception as e: logger.error(e) messages.add_message(request, messages.ERROR, e) interface_list = list() for equip in equipment: data["searchable_columns"] = [""] data["custom_search"] = "" data["extends_search"] = [{'equipamento__id': equip.get('id')}] try: search_interface = client.create_api_interface_request( ).search(fields=[ 'id', 'interface', 'front_interface__basic', 'back_interface__basic' ], search=data) interface_list = search_interface.get('interfaces') except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) except Exception as e: logger.error(e) messages.add_message(request, messages.ERROR, e) if not interface_list: logger.error('Equipment do not have interfaces availables.') messages.add_message( request, messages.ERROR, 'Equipment do not have interfaces availables.') return render_to_response(NEW_INTERFACE_CONNECT_FORM, lists, RequestContext(request)) try: int(front_or_back) for i in interface_list: if front_or_back and i.get( 'front_interface') or not front_or_back and i.get( 'back_interface'): interface_list.remove(i) lists['connect_form'] = ConnectFormV3(equipment[0], interface_list, initial={ 'equip_name': equipment[0].get('name'), 'equip_id': equipment[0].get('id') }) lists['equipment'] = equipment[0] except Exception: if all_interfaces: allInt = list() for i in interface_list: allInt.append({ 'id': i.get('id'), 'interface': i.get('interface') }) lists['all_interfaces'] = allInt return render_to_response_ajax( AJAX_LIST_INTERFACES, lists, context_instance=RequestContext(request)) elif request.method == "POST": equip_id = request.POST['equip_id'] search_equipment = client.create_api_equipment().get([equip_id]) equipment = search_equipment.get('equipments') interface_list = list() data = dict() data["start_record"] = 0 data["end_record"] = 1000 data["asorting_cols"] = ["id"] data["searchable_columns"] = [""] data["custom_search"] = "" for equip in equipment: data["extends_search"] = [{'equipamento__id': equip.get('id')}] try: search_interface = client.create_api_interface_request( ).search(fields=[ 'id', 'interface', 'front_interface__basic', 'back_interface__basic' ], search=data) interface_list = search_interface.get('interfaces') except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) except Exception as e: logger.error(e) messages.add_message(request, messages.ERROR, e) for i in interface_list: if front_or_back and i.get( 'front_interface') or not front_or_back and i.get( 'back_interface'): interface_list.remove(i) form = ConnectFormV3(equipment[0], interface_list, request.POST) if form.is_valid(): front = form.cleaned_data['front'] back = form.cleaned_data['back'] link_a = "front" if front_or_back else "back" interface_a = dict(link=link_a, id=id_interface) if front: interface_b = dict(link="front", id=front) else: interface_b = dict(link="back", id=back) try: client.create_api_interface_request().connecting_interfaces( [interface_a, interface_b]) messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_connect")) except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, 'Erro linkando as interfaces: %s' % e) except Exception as e: logger.error(e) messages.add_message(request, messages.ERROR, 'Erro linkando as interfaces: %s' % e) response = HttpResponseRedirect( reverse("interface.edit", args=[id_interface])) response.status_code = 278 return response else: lists['connect_form'] = form lists['equipment'] = equipment[0] return render_to_response(NEW_INTERFACE_CONNECT_FORM, lists, RequestContext(request))
def connect(request, id_interface, front_or_back): lists = dict() if not (front_or_back == "0" or front_or_back == "1"): raise Http404 try: # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() lists['id_interface'] = id_interface lists['front_or_back'] = front_or_back lists['search_form'] = SearchEquipForm() if request.method == "GET": if request.GET.__contains__('equip_name'): lists['search_form'] = search_form = SearchEquipForm( request.GET) if search_form.is_valid(): # Get equip name in form name_equip = search_form.cleaned_data['equip_name'] # Get equipment by name from NetworkAPI equipment = client.create_equipamento().listar_por_nome( name_equip)['equipamento'] # Get interfaces related to equipment selected interf_list = client.create_interface().list_all_by_equip( equipment['id']) # Remove interface that is being added to the combobox i = [] for inter in interf_list['interfaces']: if id_interface != inter['id']: i.append(inter) interf_list = {} interf_list['interfaces'] = i lists['connect_form'] = ConnectForm(equipment, interf_list['interfaces'], initial={ 'equip_name': equipment['nome'], 'equip_id': equipment['id']}) lists['equipment'] = equipment elif request.method == "POST": equip_id = request.POST['equip_id'] # Get equipment by name from NetworkAPI equipment = client.create_equipamento().listar_por_id( equip_id)['equipamento'] # Get interfaces related to equipment selected interf_list = client.create_interface().list_all_by_equip( equipment['id']) form = ConnectForm( equipment, interf_list['interfaces'], request.POST) if form.is_valid(): front = form.cleaned_data['front'] back = form.cleaned_data['back'] # Get interface to link interface_client = client.create_interface() interface = interface_client.get_by_id(id_interface) interface = interface.get("interface") if interface['protegida'] == "True": interface['protegida'] = 1 else: interface['protegida'] = 0 if len(front) > 0: # Get front interface selected inter_front = interface_client.get_by_id(front) inter_front = inter_front.get("interface") if inter_front['protegida'] == "True": inter_front['protegida'] = 1 else: inter_front['protegida'] = 0 related_list = client.create_interface().list_connections( inter_front["interface"], inter_front["equipamento"]) for i in related_list.get('interfaces'): if i['equipamento'] == interface['equipamento']: lists['connect_form'] = form lists['equipment'] = equipment raise Exception( 'Configuração inválida. Loop detectado nas ligações entre patch-panels') # Business Rules interface_client.alterar(inter_front['id'], inter_front['interface'], inter_front['protegida'], inter_front['descricao'], interface['id'], inter_front['ligacao_back'], inter_front['tipo'], inter_front['vlan']) if front_or_back == "0": interface_client.alterar(interface['id'], interface['interface'], interface['protegida'], interface['descricao'], interface['ligacao_front'], inter_front['id'], interface['tipo'], interface['vlan']) else: interface_client.alterar(interface['id'], interface['interface'], interface['protegida'], interface['descricao'], inter_front['id'], interface['ligacao_back'], interface['tipo'], interface['vlan']) else: # Get back interface selected inter_back = interface_client.get_by_id(back) inter_back = inter_back.get("interface") if inter_back['protegida'] == "True": inter_back['protegida'] = 1 else: inter_back['protegida'] = 0 related_list = client.create_interface().list_connections( inter_back["interface"], inter_back["equipamento"]) for i in related_list.get('interfaces'): if i['equipamento'] == interface['equipamento']: lists['connect_form'] = form lists['equipment'] = equipment raise Exception('Configuração inválida. Loop detectado nas ligações entre patch-panels') # Business Rules interface_client.alterar(inter_back['id'], inter_back['interface'], inter_back['protegida'], inter_back['descricao'], inter_back['ligacao_front'], interface['id'], inter_back['tipo'], inter_back['vlan']) if front_or_back == "0": interface_client.alterar(interface['id'], interface['interface'], interface['protegida'], interface['descricao'], interface['ligacao_front'], inter_back['id'], interface['tipo'], interface['vlan']) else: interface_client.alterar(interface['id'], interface['interface'], interface['protegida'], interface['descricao'], inter_back['id'], interface['ligacao_back'], interface['tipo'], interface['vlan']) messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_connect")) url_param = reverse( "equip.interface.edit.form", args=[interface['equipamento_nome'], id_interface]) response = HttpResponseRedirect(url_param) response.status_code = 278 return response else: lists['connect_form'] = form lists['equipment'] = equipment except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)
def edit_channel(request, channel_name, equip_name, channel=None): lists = dict() auth = AuthSession(request.session) client = auth.get_clientFactory() lists['channel_name'] = channel_name lists['channel'] = channel try: equip = client.create_equipamento().listar_por_nome(str(equip_name)) equip = equip.get('equipamento') equip_interface_list = client.create_interface().list_available_interfaces(channel, equip['id']) try: equip_interface_list.get('interface')['id'] equip_interface_list = equip_interface_list.get('interface') interface = list() interface.append(equip_interface_list) equip_interface_list = dict() equip_interface_list['interfaces'] = interface except: pass environment_list = get_equip_environment(client, equip['id']) channel = client.create_interface().get_interface_by_channel(channel_name, equip_name) channel = channel.get('interfaces') if type(channel) is list: lists['equip_interface'] = channel channel = channel[0] else: equip_int = [] equip_int.append(channel) lists['equip_interface'] = equip_int if request.method == "GET": tipo = channel['tipo'] if "access" in tipo: tipo = 0 else: tipo = 1 if channel['lacp']=="True": lacp = 1 else: lacp = 0 form = ChannelAddForm(equip_interface_list, initial={'id': channel['id_channel'], 'name': channel['channel'], 'lacp': lacp, 'equip_name': equip_name, 'type':tipo, 'int_type': tipo, 'vlan': channel['vlan_nativa']}) lists['form'] = form if environment_list is not None: envs = environment_list.get('ambiente') lists['environment_list'] = envs if tipo: try: int_envs = client.create_interface().get_env_by_id(channel['id']) int_envs = int_envs.get('ambiente') if type(int_envs) is not list: i = int_envs int_envs = [] int_envs.append(i) envform_list = [] for i in int_envs: envform = AddEnvInterfaceForm(environment_list, initial={'environment': int(i.get('id')), 'vlans': i.get('vlans')}) envform_list.append(envform) except: envform = AddEnvInterfaceForm(environment_list) envform_list.append(envform) pass lists['envform'] = envform_list else: envform = AddEnvInterfaceForm(environment_list) lists['envform'] = envform lists['envsform'] = AddEnvInterfaceForm(environment_list) else: messages.add_message(request, messages.WARNING, "O equipamento não possui ambientes cadastrados.") if request.method == "POST": form = ChannelAddForm(equip_interface_list, request.POST) lists['form'] = form if environment_list is not None: envform = AddEnvInterfaceForm(environment_list, request.POST) if form.is_valid(): id_channel = form.cleaned_data['id'] name = form.cleaned_data['name'] lacp = form.cleaned_data['lacp'] int_type = form.cleaned_data['int_type'] vlan_nativa = form.cleaned_data['vlan'] interfaces_ids = request.POST.getlist('idsInterface') if int_type=="0": int_type = "access" env_vlans_list = [] else: int_type = "trunk" if environment_list is None: messages.add_message(request, messages.ERROR, "O equipamento não possui ambientes cadastrados.") return render_to_response(EQUIPMENT_INTERFACE_EDIT_CHANNEL, lists, context_instance=RequestContext(request)) if envform.is_valid(): environment = request.POST.getlist('environment') vlan_range = request.POST.getlist('vlans') env_vlans_list = env_vlans(environment_list.get("ambiente"), environment, vlan_range) try: client.create_interface().editar_channel(id_channel, name, lacp, int_type, vlan_nativa, env_vlans_list, interfaces_ids) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_edit_channel")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(EQUIPMENT_INTERFACE_EDIT_CHANNEL, lists, context_instance=RequestContext(request)) except Exception, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(EQUIPMENT_INTERFACE_EDIT_CHANNEL, lists, context_instance=RequestContext(request))
int_type = form.cleaned_data['int_type'] vlan = form.cleaned_data['vlan'] envs = None if environment_list is not None and envform.is_valid(): envs = envform.cleaned_data['environment'] trunk = 0 if int_type=="0": int_type = "access" else: int_type = "trunk" trunk = 1 id_int = client.create_interface().inserir(name, protected, description, None, None, equip['id'], int_type, vlan) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_insert")) id_int = id_int.get("interface") if trunk and envs is not None: for env in envs: client.create_interface().associar_ambiente(env, id_int['id']) messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_associando_amb")) url_param = reverse("interface.list") if len(equip_name) > 2: url_param = url_param + "?search_equipment=" + equip_name return HttpResponseRedirect(url_param) else: lists['form'] = form
interface = { 'interface': request.POST.get('name'), 'description': request.POST.get('description'), 'protected': True if int(request.POST.get('protected')) else False, 'native_vlan': request.POST.get('vlan_nativa'), 'type': int(request.POST.get('access')), 'equipment': int(equips.get('id')) } try: interface_obj = client.create_api_interface_request().create( [interface]) interface_id = interface_obj.get('interfaces')[0].get('id') messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_insert")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(ADD_EQUIPMENT_INTERFACE, lists, RequestContext(request)) data["end_record"] = 30000 data["asorting_cols"] = [] data["searchable_columns"] = [] envs = client.create_api_environment().search(fields=["name", "id"], search=data) try: for e, v in zip(request.POST.getlist('environment'),
def add_interface(request, equipment=None): # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() url = request.META.get('HTTP_REFERER') if request.META.get( 'HTTP_REFERER') else reverse('interface.list') try: search_equipment = client.create_api_equipment().get( ids=[equipment], kind='details', fields=['id', 'name', 'environments']) equips = search_equipment.get('equipments')[0] except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) return HttpResponseRedirect(url) lists = { 'environments': equips.get('environments'), 'equip_name': equips.get('name'), 'equip_id': equips.get('id') } data = { "start_record": 0, "end_record": 1000, "asorting_cols": ["id"], "searchable_columns": ["nome"], "custom_search": "", "extends_search": [] } try: types = client.create_api_interface_request().get_interface_type( search=data) type_list = types.get('interfaces_type') except NetworkAPIClientError as e: logger.error(e) messages.add_message( request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e) return HttpResponseRedirect(url) lists['type_list'] = type_list if request.method == "POST": interface = { 'interface': request.POST.get('name'), 'description': request.POST.get('description'), 'protected': True if int(request.POST.get('protected')) else False, 'native_vlan': request.POST.get('vlan_nativa'), 'type': int(request.POST.get('access')), 'equipment': int(equips.get('id')) } try: interface_obj = client.create_api_interface_request().create( [interface]) interface_id = interface_obj.get('interfaces')[0].get('id') messages.add_message( request, messages.SUCCESS, equip_interface_messages.get("success_insert")) except NetworkAPIClientError as e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(ADD_EQUIPMENT_INTERFACE, lists, RequestContext(request)) data["end_record"] = 30000 data["asorting_cols"] = [] data["searchable_columns"] = [] envs = client.create_api_environment().search(fields=["name", "id"], search=data) try: for e, v in zip(request.POST.getlist('environment'), request.POST.getlist('rangevlan')): for obj in envs.get('environments'): if obj.get('name') in e: int_env_map = dict(interface=int(interface_id), environment=int(obj.get('id')), range_vlans=v) client.create_api_interface_request( ).associate_interface_environments([int_env_map]) except NetworkAPIClientError as e: logger.error(e) messages.add_message( request, messages.WARNING, 'Os ambientes não foram associados à interface.') return HttpResponseRedirect('/interface/?search_equipment=%s' % equips.get('name')) return render_to_response(ADD_EQUIPMENT_INTERFACE, lists, RequestContext(request))
if request.method == "POST": interface = { 'interface': request.POST.get('name'), 'description': request.POST.get('description'), 'protected': True if int(request.POST.get('protected')) else False, 'native_vlan': request.POST.get('vlan_nativa'), 'type': int(request.POST.get('access')), 'equipment': int(equips.get('id')) } try: interface_obj = client.create_api_interface_request().create([interface]) interface_id = interface_obj.get('interfaces')[0].get('id') messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_insert")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(ADD_EQUIPMENT_INTERFACE, lists, RequestContext(request)) data["end_record"] = 30000 data["asorting_cols"] = [] data["searchable_columns"] = [] envs = client.create_api_environment().search(fields=["name", "id"], search=data) try: for e, v in zip(request.POST.getlist('environment'), request.POST.getlist('rangevlan')): for obj in envs.get('environments'): if obj.get('name') in e:
if request.method == "POST": interface = { 'interface': request.POST.get('name'), 'description': request.POST.get('description'), 'protected': True if int(request.POST.get('protected')) else False, 'native_vlan': request.POST.get('vlan_nativa'), 'type': int(request.POST.get('access')), 'equipment': int(equips.get('id')) } try: interface_obj = client.create_api_interface_request().create([interface]) interface_id = interface_obj.get('interfaces')[0].get('id') messages.add_message(request, messages.SUCCESS, equip_interface_messages.get("success_insert")) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) return render_to_response(ADD_EQUIPMENT_INTERFACE, lists, RequestContext(request)) data["end_record"] = 30000 data["asorting_cols"] = [] data["searchable_columns"] = [] envs = client.create_api_environment().search(fields=["name", "id"], search=data) try: for e, v in zip(request.POST.getlist('environment'), request.POST.getlist('rangevlan')): for obj in envs.get('environments'): if obj.get('name') in e: