Пример #1
0
    data["searchable_columns"] = ["interface__id"]
    data["custom_search"] = str(sw_ids[0])

    try:
        environments = client.create_api_interface_request().get_interface_environments(search=data,
                                                                                        fields=['environment__basic',
                                                                                                'range_vlans'])
        environments = environments.get('interface_environments')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get('HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    try:
        lists['server_map'] = facade.get_environments(client, server_interfaces.get('interfaces'))
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get('HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    lists['total_itens'] = len(server_interfaces) - 1

    try:
        sw_int_map, channel_map = facade.get_channel_map(sw_interfaces)
        sw_int_map['environments'] = environments
        lists['channel_map'] = channel_map
        lists['total_channel'] = len(channel_map) - 1
        lists['sw_int_map'] = sw_int_map
        lists['total_sw'] = len(sw_int_map) - 1
Пример #2
0
    data["searchable_columns"] = ["interface__id"]
    data["custom_search"] = str(sw_ids[0])

    try:
        environments = client.create_api_interface_request().get_interface_environments(search=data,
                                                                                        fields=['environment__basic',
                                                                                                'range_vlans'])
        environments = environments.get('interface_environments')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get('HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    try:
        lists['server_map'] = facade.get_environments(client, server_interfaces.get('interfaces'))
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, 'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get('HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    lists['total_itens'] = len(server_interfaces) - 1

    try:
        sw_int_map, channel_map = facade.get_channel_map(sw_interfaces)
        sw_int_map['environments'] = environments
        lists['channel_map'] = channel_map
        lists['total_channel'] = len(channel_map) - 1
        lists['sw_int_map'] = sw_int_map
        lists['total_sw'] = len(sw_int_map) - 1
Пример #3
0
def edit_channel_(request, channel_id=None):

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

    lists = dict()
    lists['channel_id'] = channel_id

    fields = ['id', 'front_interface__id']

    fields_get = [
        'id', 'interface', 'description', 'protected', 'type__details',
        'native_vlan', 'equipment__basic', 'front_interface__basic',
        'back_interface', 'channel__basic'
    ]

    search = {
        "start_record": 0,
        "end_record": 50,
        "asorting_cols": [],
        "searchable_columns": [],
        "custom_search": "",
        "extends_search": [{
            "channel": channel_id
        }]
    }

    try:
        sw_ids = []
        server_ids = []
        interfaces = client.create_api_interface_request().search(
            search=search, fields=fields).get('interfaces')
        for i in interfaces:
            sw_ids.append(i.get('id'))
            server_ids.append(i.get('front_interface'))
        sw_interfaces = client.create_api_interface_request().get(
            sw_ids, fields=fields_get).get('interfaces')
        server_interfaces = client.create_api_interface_request().get(
            server_ids, fields=fields_get)
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Erro ao buscar o channel de Id %s.' % channel_id)
        url = request.META.get('HTTP_REFERER') if request.META.get(
            'HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    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)
        url = request.META.get('HTTP_REFERER') if request.META.get(
            'HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    lists['type_list'] = type_list

    if request.method == "POST":

        lacp = True if int(request.POST.get('lacp')) else False
        protected = True if int(request.POST.get('protected')) else False

        envs_vlans = list()

        if str(request.POST.get('type')).lower() in "Access".lower():
            int_type = "Access"
        else:
            int_type = "Trunk"

            for e, v in zip(request.POST.getlist('environment'),
                            request.POST.getlist('rangevlan')):
                env_id = e.split("-")[0]
                group = dict(env=int(env_id), vlans=v)
                envs_vlans.append(group)

        channel_obj = dict(id=channel_id,
                           name=str(request.POST.get('channelnumber')),
                           lacp=lacp,
                           protected=protected,
                           int_type=int_type,
                           vlan=int(request.POST.get('vlan_nativa')),
                           interfaces=sw_ids,
                           envs_vlans=envs_vlans)

        try:
            client.create_api_interface_request().update_channel([channel_obj])
            messages.add_message(request, messages.SUCCESS,
                                 "O channel foi editado com sucesso!")
        except NetworkAPIClientError as e:
            logger.error(e)
            messages.add_message(request, messages.ERROR,
                                 'Erro ao atualizar o channel. Error: %s' % e)
            url = request.META.get('HTTP_REFERER') if request.META.get(
                'HTTP_REFERER') else reverse('interface.list')
            return HttpResponseRedirect(url)

        try:
            sw_ids = []
            server_ids = []
            interfaces = client.create_api_interface_request().search(
                search=search, fields=fields).get('interfaces')
            for i in interfaces:
                sw_ids.append(i.get('id'))
                server_ids.append(i.get('front_interface'))
            sw_interfaces = client.create_api_interface_request().get(
                sw_ids, fields=fields_get).get('interfaces')
            server_interfaces = client.create_api_interface_request().get(
                server_ids, fields=fields_get)
        except NetworkAPIClientError as e:
            logger.error(e)
            messages.add_message(
                request, messages.WARNING,
                'Erro ao buscar o channel de Id %s.' % channel_id)
            url = request.META.get('HTTP_REFERER') if request.META.get(
                'HTTP_REFERER') else reverse('interface.list')
            return HttpResponseRedirect(url)

    data["asorting_cols"] = ["id"]
    data["searchable_columns"] = ["interface__id"]
    data["custom_search"] = str(sw_ids[0])

    try:
        environments = client.create_api_interface_request(
        ).get_interface_environments(
            search=data, fields=['environment__basic', 'range_vlans'])
        environments = environments.get('interface_environments')
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(
            request, messages.ERROR,
            'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get(
            'HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    try:
        lists['server_map'] = facade.get_environments(
            client, server_interfaces.get('interfaces'))
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(
            request, messages.ERROR,
            'Erro ao buscar os tipos de interface. Error: %s' % e)
        url = request.META.get('HTTP_REFERER') if request.META.get(
            'HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

    lists['total_itens'] = len(server_interfaces) - 1

    try:
        sw_int_map, channel_map = facade.get_channel_map(sw_interfaces)
        sw_int_map['environments'] = environments
        lists['channel_map'] = channel_map
        lists['total_channel'] = len(channel_map) - 1
        lists['sw_int_map'] = sw_int_map
        lists['total_sw'] = len(sw_int_map) - 1
    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.WARNING,
                             'Não foi possível montar o map do channel.')
        url = request.META.get('HTTP_REFERER') if request.META.get(
            'HTTP_REFERER') else reverse('interface.list')
        return HttpResponseRedirect(url)

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