Exemplo n.º 1
0
    data["custom_search"] = ""
    data["extends_search"] = []

    try:
        types = client.create_api_interface_request().get_interface_type(search=data)
        type_list = types.get('interfaces_type')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        return HttpResponseRedirect('/interface/?search_equipment=%s' % equipment.get('name'))

    lists['type_list'] = type_list

    try:
        first_item, last_item, interface_map = facade.get_interface_map(request, client, interface)
        lists['interface_map'] = facade.get_ordered_list(first_item, last_item, interface_map)
        lists['total_itens'] = last_item - first_item
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.WARNING, 'Não foi possível montar o map da interface.')
        return HttpResponseRedirect('/interface/?search_equipment=%s' % equipment.get('name'))

    return render_to_response(EDIT_EQUIPMENT_INTERFACE, lists, RequestContext(request))


@log
@login_required
@has_perm([{"permission": EQUIPMENT_MANAGEMENT, "write": True, "read": True}])
def edit_interface_post(request, interface=None):

    lists = {}
Exemplo n.º 2
0
def edit_interface_post(request, interface=None):

    lists = {}

    auth = AuthSession(request.session)
    client = auth.get_clientFactory()

    fields = ['id', 'equipment__details', 'front_interface', 'back_interface']

    equipment_name = ""

    try:
        interface_obj = client.create_api_interface_request().get(
            ids=[interface], fields=fields)
        interfaces = interface_obj.get('interfaces')[0]
        equipment = interfaces.get('equipment')
        equipment_name = equipment.get('name')
        lists["equip_name"] = equipment_name
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Erro ao buscar interface %s.' % interface)
        return HttpResponseRedirect('/interface/?search_equipment=%s' %
                                    equipment_name)

    data = dict()
    data["start_record"] = 0
    data["end_record"] = 1000
    data["asorting_cols"] = ["id"]
    data["searchable_columns"] = ["nome"]
    data["custom_search"] = ""
    data["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('/interface/?search_equipment=%s' %
                                    equipment.get('name'))

    lists['type_list'] = type_list

    if request.method == "POST":

        data["searchable_columns"] = ["interface__id"]
        data["custom_search"] = str(interface)

        int_envs = list()
        trunk = False

        int_type = None
        for tipo in type_list:
            if str(tipo.get('type')).lower() == str(
                    request.POST.get('type')).lower():
                int_type = tipo.get('id')
                if str(tipo.get('type')).lower() == "trunk":
                    trunk = True

        try:
            int_envs = client.create_api_interface_request(
            ).get_interface_environments(search=data)
            int_envs = int_envs.get('interface_environments')
        except Exception as e:
            logger.error(e)
            messages.add_message(
                request, messages.WARNING,
                'Erro ao buscar os ambientes associados a interface. '
                'Error: %s' % e)

        interface_dict = dict(
            id=int(interfaces.get('id')),
            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(int_type),
            equipment=int(equipment.get('id')),
            front_interface=interfaces.get('front_interface'),
            back_interface=interfaces.get('back_interface'))

        try:
            client.create_api_interface_request().update([interface_dict])
            messages.add_message(request, messages.SUCCESS,
                                 'Interface atualizada com sucesso.')
        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 int_envs:
            try:
                for env in int_envs:
                    client.create_api_interface_request(
                    ).disassociate_interface_environments([env.get('id')])
            except NetworkAPIClientError as e:
                logger.error(e)
                messages.add_message(
                    request, messages.ERROR,
                    'Erro ao remover os ambientes associados anteriormente.')

        if trunk:
            data = dict()
            data["start_record"] = 0
            data["end_record"] = 30000
            data["asorting_cols"] = []
            data["searchable_columns"] = []
            data["custom_search"] = ""
            data["extends_search"] = []

            envs = client.create_api_environment().search(
                fields=["name", "id"], search=data)

            try:
                for e, v in zip(
                        request.POST.getlist('environmentCh' + str(interface)),
                        request.POST.getlist('rangevlanCh' + str(interface))):
                    for obj in envs.get('environments'):
                        if obj.get('name') in e:
                            int_env_map = dict(interface=int(interface),
                                               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.ERROR,
                                     'Erro ao atualizar os ambientes.')

    try:
        first_item, last_item, interface_map = facade.get_interface_map(
            request, client, interface)
        lists['interface_map'] = facade.get_ordered_list(
            first_item, last_item, interface_map)
        lists['total_itens'] = last_item - first_item
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Não foi possível montar o map da interface.')

    url_list = '/interface/?search_equipment=%s' % equipment.get('name')
    url_edit = request.META.get('HTTP_REFERER') if request.META.get(
        'HTTP_REFERER') else reverse(url_list)

    return HttpResponseRedirect(url_edit)
Exemplo n.º 3
0
    data["custom_search"] = ""
    data["extends_search"] = []

    try:
        types = client.create_api_interface_request().get_interface_type(search=data)
        type_list = types.get('interfaces_type')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        return HttpResponseRedirect('/interface/?search_equipment=%s' % equipment.get('name'))

    lists['type_list'] = type_list

    try:
        first_item, last_item, interface_map = facade.get_interface_map(request, client, interface)
        lists['interface_map'] = facade.get_ordered_list(first_item, last_item, interface_map)
        lists['total_itens'] = last_item - first_item
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.WARNING, 'Não foi possível montar o map da interface.')
        return HttpResponseRedirect('/interface/?search_equipment=%s' % equipment.get('name'))

    return render_to_response(EDIT_EQUIPMENT_INTERFACE, lists, RequestContext(request))


@log
@login_required
@has_perm([{"permission": EQUIPMENT_MANAGEMENT, "write": True, "read": True}])
def edit_interface_post(request, interface=None):

    lists = {}
Exemplo n.º 4
0
def edit_interface_get(request, interface=None):

    lists = {}

    auth = AuthSession(request.session)
    client = auth.get_clientFactory()

    fields = ['id', 'equipment__details', 'front_interface', 'back_interface']

    equipment_name = ""

    try:
        interface_obj = client.create_api_interface_request().get(
            ids=[interface], fields=fields)
        interfaces = interface_obj.get('interfaces')[0]
        equipment = interfaces.get('equipment')
        equipment_name = equipment.get('name')
        lists["equip_name"] = equipment_name
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Erro ao buscar interface %s.' % interface)
        return HttpResponseRedirect('/interface/?search_equipment=%s' %
                                    equipment_name)

    data = dict()
    data["start_record"] = 0
    data["end_record"] = 1000
    data["asorting_cols"] = ["id"]
    data["searchable_columns"] = ["nome"]
    data["custom_search"] = ""
    data["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('/interface/?search_equipment=%s' %
                                    equipment.get('name'))

    lists['type_list'] = type_list

    try:
        first_item, last_item, interface_map = facade.get_interface_map(
            request, client, interface)
        lists['interface_map'] = facade.get_ordered_list(
            first_item, last_item, interface_map)
        lists['total_itens'] = last_item - first_item
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Não foi possível montar o map da interface.')
        return HttpResponseRedirect('/interface/?search_equipment=%s' %
                                    equipment.get('name'))

    return render_to_response(EDIT_EQUIPMENT_INTERFACE, lists,
                              RequestContext(request))