def template_delete(request):

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

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            user = AuthSession(request.session).get_user()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            for id in ids:
                id_split = id.split('+')
                template_name = id_split[0]
                template_name = urllib.unquote_plus(str(template_name))
                network = id_split[1]

                if check_template(template_name, network, user):
                    client.create_ambiente().set_template(
                        0, template_name, network)
                    delete_template(template_name, network, user)

            messages.add_message(request, messages.SUCCESS,
                                 acl_messages.get("success_remove"))
        else:
            messages.add_message(request, messages.ERROR,
                                 error_messages.get("select_one"))

    return HttpResponseRedirect(reverse('acl.template.list'))
Exemple #2
0
def delete_sudoer_all(request):

    if request.method == 'POST':

        ldap = Ldap(AuthSession(request.session).get_user().get_username())
        form = DeleteForm(request.POST)

        if form.is_valid():

            # All cns to be deleted
            cns = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each sudoer selected to remove
            for cn in cns:

                try:

                    ldap.rem_sudoer(cn)

                except LDAPNotFoundError, e:
                    error_list.append(cn)
                    have_errors = True

                except LDAPError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(cns):
                messages.add_message(
                    request, messages.ERROR, error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS, ldap_messages.get("success_remove_sudoer"))

            else:
                messages.add_message(
                    request, messages.SUCCESS, error_messages.get("can_not_remove_error"))
Exemple #3
0
def delete_validate_create_remove(request, operation):

    operation_text = OPERATION.get(int(operation))

    if request.method == 'POST':

        form = DeleteForm(request.POST) if operation_text == 'DELETE'\
            else CreateForm(request.POST) if operation_text == 'CREATE'\
            else RemoveForm(request.POST)

        id = 'ids' if operation_text == 'DELETE' else 'ids_create'\
            if operation_text == 'CREATE' else 'ids_remove'

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_api_vip = auth.get_clientFactory().create_api_vip_request()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data[id])
            vip_id = form.cleaned_data[id]

            # All messages to display
            error_list = list()
            error_list_created = list()
            error_list_not_validate = list()

            # Control others exceptions
            have_errors = False

            # FLAG only for  ERROR  in create
            all_ready_msg_script_error = False

            # For each script selected to remove
            try:
                if operation_text == 'DELETE':
                    client_api_vip.delete_vip_request(vip_id)
                elif operation_text == 'REMOVE':
                    client_api_vip.remove_vip(vip_id)
                elif operation_text == 'CREATE':
                    client_api_vip.create_vip(vip_id)

            except VipAllreadyCreateError, e:
                logger.error(e)
                error_list_created.append(vip_id)
            except VipError, e:
                logger.error(e)
                error_list_not_validate.append(vip_id)
            except ScriptError, e:
                logger.error(e)
                if not all_ready_msg_script_error:
                    messages.add_message(request, messages.ERROR, e)
                all_ready_msg_script_error = True
                error_list.append(vip_id)
def delete_validate_create_remove(request, operation):

    operation_text = OPERATION.get(int(operation))

    if request.method == 'POST':

        form = DeleteForm(request.POST) if operation_text == 'DELETE'\
            else CreateForm(request.POST) if operation_text == 'CREATE'\
            else RemoveForm(request.POST)

        id = 'ids' if operation_text == 'DELETE' else 'ids_create'\
            if operation_text == 'CREATE' else 'ids_remove'

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_api_vip = auth.get_clientFactory().create_api_vip_request()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data[id])
            vip_id = form.cleaned_data[id]

            # All messages to display
            error_list = list()
            error_list_created = list()
            error_list_not_validate = list()

            # Control others exceptions
            have_errors = False

            # FLAG only for  ERROR  in create
            all_ready_msg_script_error = False

            # For each script selected to remove
            try:
                if operation_text == 'DELETE':
                    client_api_vip.delete_vip_request(vip_id)
                elif operation_text == 'REMOVE':
                    client_api_vip.remove_vip(vip_id)
                elif operation_text == 'CREATE':
                    client_api_vip.create_vip(vip_id)

            except VipAllreadyCreateError, e:
                logger.error(e)
                error_list_created.append(vip_id)
            except VipError, e:
                logger.error(e)
                error_list_not_validate.append(vip_id)
            except ScriptError, e:
                logger.error(e)
                if not all_ready_msg_script_error:
                    messages.add_message(request, messages.ERROR, e)
                all_ready_msg_script_error = True
                error_list.append(vip_id)
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_script = auth.get_clientFactory().create_equipamento_roteiro(
            )

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])
            equipment = form.cleaned_data['equip_id']
            equip_nam = form.cleaned_data['equip_name']

            # Control others exceptions
            have_errors = False

            # For each script selected to remove
            for id_es in ids:
                try:

                    # Execute in NetworkAPI
                    equip_script.remover(equipment, 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_script_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 delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():
            auth = AuthSession(request.session)
            client = auth.get_clientFactory()

            ids = split_to_array(form.cleaned_data['ids'])

            error_list = list()
            have_errors = False

            for id_var in ids:
                try:
                    client.create_system().delete_all(id_var)
                except VariableError:
                    error_list.append(id_var)
                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            if len(error_list) == len(ids):
                messages.add_message(request, messages.ERROR,
                                     error_messages.get("can_not_remove_all"))
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "
                msg = error_messages.get("can_not_remove") % msg[:-2]
                messages.add_message(request, messages.WARNING, msg)
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS,
                    system_variable_messages.get("success_delete"))
            else:
                messages.add_message(
                    request, messages.SUCCESS,
                    error_messages.get("can_not_remove_error"))

        else:
            messages.add_message(request, messages.ERROR,
                                 error_messages.get("select_one"))
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"))
Exemple #8
0
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_equip = auth.get_clientFactory().create_equipamento()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            delete_equipments_shared(request, client_equip, ids)
        else:
            messages.add_message(request, messages.ERROR,
                                 error_messages.get('select_one'))

    # Redirect to list_all action
    return redirect('equipment.search.list')
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_equip = auth.get_clientFactory().create_equipamento()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            delete_equipments_shared(request, client_equip, ids)
        else:
            messages.add_message(
                request, messages.ERROR, error_messages.get('select_one'))

    # Redirect to list_all action
    return redirect('equipment.search.list')
Exemple #10
0
def delete_all(request, id_egroup):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_equipament = auth.get_clientFactory().create_equipamento()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each equipment selected to remove
            for id_equip in ids:
                try:

                    # Execute in NetworkAPI
                    client_equipament.remover_grupo(id_equip, id_egroup)

                except EquipmentDontRemoveError, e:
                    # If isn't possible, add in error list
                    error_list.append(id_equip)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If can't remove some
            if len(error_list) > 0:

                list_equipment = cache_list_equipment_all(client_equipament)

                msg = ""
                for id_error in error_list:

                    for equip in list_equipment:

                        if equip['id'] == id_error:
                            msg = msg + equip['nome'] + ", "
                            break

                msg = equip_group_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all have been removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS,
                    equip_group_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS,
                    error_messages.get("can_not_remove_error"))
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            roteiro = auth.get_clientFactory().create_roteiro()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each script selected to remove
            for id_script in ids:
                try:

                    # Execute in NetworkAPI
                    roteiro.remover(id_script)

                except RoteiroError, e:
                    # If isnt possible, add in error list
                    error_list.append(id_script)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(ids):
                messages.add_message(
                    request, messages.ERROR, error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS, script_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS, error_messages.get("can_not_remove_error"))
def delete(request):

    try:

        if request.method == 'POST':

            form = DeleteForm(request.POST)

            id_equip = request.POST['equip_id']

            flag = False

            if form.is_valid():

                # Get user
                auth = AuthSession(request.session)
                equipamento_acesso = auth.get_clientFactory(
                ).create_equipamento_acesso()

                # All ids to be deleted
                ids = split_to_array(form.cleaned_data['ids'])

                # All messages to display
                error_list = list()

                # Control others exceptions
                have_errors = False

                # return with list with equip
                # For each script selected to remove
                for id_equip_access in ids:
                    try:

                        # Execute in NetworkAPI
                        equip_access = equipamento_acesso.get_access(
                            id_equip_access)
                        equip_access = equip_access.get('equipamento_acesso')
                        equipamento_acesso.remover(
                            equip_access.get('tipo_acesso'), id_equip)

                    except EquipamentoError, e:
                        # If isnt possible, add in error list
                        error_list.append(id_equip_access)

                    except NetworkAPIClientError, e:
                        logger.error(e)
                        messages.add_message(request, messages.ERROR, e)
                        have_errors = True
                        break

                    # If cant remove nothing
                    if len(error_list) == len(ids):
                        messages.add_message(
                            request, messages.ERROR, error_messages.get("can_not_remove_all"))

                        # If cant remove someones
                    elif len(error_list) > 0:
                        msg = ""
                        for id_error in error_list:
                            msg = msg + id_error + ", "

                            msg = error_messages.get(
                                "can_not_remove") % msg[:-2]

                            messages.add_message(
                                request, messages.WARNING, msg)

                    # If all has ben removed
                    elif have_errors == False:
                        if not flag:
                            flag = True
                            messages.add_message(
                                request, messages.SUCCESS, equip_access_messages.get("success_remove"))
                    else:
                        messages.add_message(
                            request, messages.ERROR, error_messages.get("select_one"))
Exemple #13
0
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_user = auth.get_clientFactory().create_usuario()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each user selected to remove
            for id_user in ids:
                try:

                    # Execute in NetworkAPI
                    user = client_user.get_by_id(id_user).get('usuario')
                    client_user.alterar(user.get("id"), user.get("user"),
                                        user.get("pwd"), user.get('nome'), 0,
                                        user.get('email'),
                                        user.get('user_ldap'))

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(ids):
                messages.add_message(request, messages.ERROR,
                                     error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors == False:
                messages.add_message(request, messages.SUCCESS,
                                     user_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.ERROR,
                    error_messages.get("can_not_remove_error"))

        else:
            messages.add_message(request, messages.ERROR,
                                 error_messages.get("select_one"))
def delete_user(request, id_ugroup):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_ugroup = auth.get_clientFactory().create_usuario_grupo()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each users selected to remove
            for id_user in ids:
                try:

                    # Execute in NetworkAPI
                    client_ugroup.remover(id_user, id_ugroup)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(ids):
                messages.add_message(
                    request, messages.ERROR, error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors is False:
                messages.add_message(
                    request, messages.SUCCESS, user_group_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS, error_messages.get("can_not_remove_error"))

        else:
            messages.add_message(
                request, messages.ERROR, error_messages.get("select_one"))
Exemple #15
0
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            roteiro = auth.get_clientFactory().create_roteiro()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each script selected to remove
            for id_script in ids:
                try:

                    # Execute in NetworkAPI
                    roteiro.remover(id_script)

                except RoteiroError, e:
                    # If isnt possible, add in error list
                    error_list.append(id_script)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(ids):
                messages.add_message(request, messages.ERROR,
                                     error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors == False:
                messages.add_message(request, messages.SUCCESS,
                                     script_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS,
                    error_messages.get("can_not_remove_error"))
Exemple #16
0
def delete_user_all(request, pattern):

    if request.method == 'POST':

        ldap = Ldap(AuthSession(request.session).get_user().get_username())
        form = DeleteForm(request.POST)

        if form.is_valid():

            # All cns to be deleted
            cns = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each user selected to remove
            for cn in cns:

                try:

                    ldap.rem_user(cn)

                    client_user = AuthSession(
                        request.session).get_clientFactory().create_usuario()

                    try:
                        local_user = client_user.get_by_user_ldap(cn)
                        local_user = local_user['usuario']
                        client_user.alterar(local_user['id'], local_user['user'], local_user[
                                            'pwd'], local_user['nome'], local_user['ativo'], local_user['email'], None)
                    except UsuarioNaoExisteError:
                        pass

                except LDAPMethodError, e:
                    error_list.append(cn)
                    have_errors = True

                except LDAPError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If cant remove nothing
            if len(error_list) == len(cns):
                messages.add_message(
                    request, messages.ERROR, error_messages.get("can_not_remove_all"))

            # If cant remove someones
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all has ben removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS, ldap_messages.get("success_remove_user"))

            else:
                messages.add_message(
                    request, messages.SUCCESS, error_messages.get("can_not_remove_error"))
def delete_all(request, id_egroup):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_equipament = auth.get_clientFactory().create_equipamento()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each equipment selected to remove
            for id_equip in ids:
                try:

                    # Execute in NetworkAPI
                    client_equipament.remover_grupo(id_equip, id_egroup)

                except EquipmentDontRemoveError, e:
                    # If isn't possible, add in error list
                    error_list.append(id_equip)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If can't remove some
            if len(error_list) > 0:

                list_equipment = cache_list_equipment_all(client_equipament)

                msg = ""
                for id_error in error_list:

                    for equip in list_equipment:

                        if equip['id'] == id_error:
                            msg = msg + equip['nome'] + ", "
                            break

                msg = equip_group_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all have been removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS, equip_group_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS, error_messages.get("can_not_remove_error"))
def apply_acl(request, id_vlan, network):

    lists = dict()
    lists['id_vlan'] = id_vlan
    lists['form'] = DeleteForm()

    try:

        # Get user
        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        vlan = client.create_vlan().get(id_vlan).get("vlan")
        environment = client.create_ambiente().buscar_por_id(
            vlan.get("ambiente")).get("ambiente")

        key_acl = acl_key(network)

        if vlan.get(key_acl) is None:
            messages.add_message(request, messages.ERROR,
                                 acl_messages.get("error_acl_not_exist"))
            return HttpResponseRedirect(
                reverse('vlan.edit.by.id', args=[id_vlan]))

        lists['vlan'] = vlan
        lists['environment'] = "%s - %s - %s" % (
            environment.get("nome_divisao"),
            environment.get("nome_ambiente_logico"),
            environment.get("nome_grupo_l3"))

        # Type Network
        lists['network'] = network

        if request.method == "POST":

            form = DeleteForm(request.POST)

            if form.is_valid():

                client_equip = client.create_equipamento()

                # All ids to be apply
                ids = split_to_array(form.cleaned_data['ids'])

                equipments = []

                for _id in ids:

                    try:

                        equip = client_equip.listar_por_id(_id)

                        equipments.append(equip)

                    except NetworkAPIClientError, e:
                        logger.error(e)
                        messages.add_message(request, messages.ERROR, e)

                if equipments is not None and equipments != "":

                    #is_apply, result = applyAcl(equipments, vlan, environment, network, AuthSession(request.session).get_user())
                    apply_result = client.create_vlan().apply_acl(
                        equipments, vlan, environment, network)

                    is_apply = apply_result.get('is_apply')
                    result = apply_result.get('result')
                    if is_apply == '0':

                        lists['result'] = result

                        messages.add_message(request, messages.SUCCESS,
                                             acl_messages.get("success_apply"))

                        return render_to_response(
                            ACL_APPLY_RESULT,
                            lists,
                            context_instance=RequestContext(request))

                    else:
                        messages.add_message(request, messages.ERROR,
                                             acl_messages.get("error_apply"))
            else:
                messages.add_message(request, messages.ERROR,
                                     error_messages.get("select_one"))

        list_equipments = []
        if len(vlan["redeipv4"]) > 0 and network == NETWORK_TYPES.v4:

            for net in vlan["redeipv4"]:

                try:

                    ips = client.create_ip().find_ip4_by_network(
                        net["id"]).get('ips')

                    for ip in ips:
                        equipment = {}
                        equipment["description"] = ip["descricao"]
                        equipment["ip"] = "%s.%s.%s.%s" % (
                            ip["oct1"], ip["oct2"], ip["oct3"], ip["oct4"])
                        equips = validates_dict(ip, "equipamento")

                        for equip in equips:
                            equipment_base = clone(equipment)
                            equipment_base["id"] = equip["id"]
                            equipment_base["name"] = equip["nome"]
                            list_equipments.append(equipment_base)

                except (NetworkAPIClientError, Exception), e:
                    pass
Exemple #19
0
def delete_all(request):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_egroup = auth.get_clientFactory().create_grupo_equipamento()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each equipment group selected to remove
            for id_egroup in ids:
                try:

                    # Execute in NetworkAPI
                    client_egroup.remover(id_egroup)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    break

            # If can't remove nothing
            if len(error_list) == len(ids):
                messages.add_message(request, messages.ERROR,
                                     error_messages.get("can_not_remove_all"))

            # If can't remove some
            elif len(error_list) > 0:
                msg = ""
                for id_error in error_list:
                    msg = msg + id_error + ", "

                msg = error_messages.get("can_not_remove") % msg[:-2]

                messages.add_message(request, messages.WARNING, msg)

            # If all have been removed
            elif have_errors == False:
                messages.add_message(
                    request, messages.SUCCESS,
                    group_equip_messages.get("success_remove"))

            else:
                messages.add_message(
                    request, messages.SUCCESS,
                    error_messages.get("can_not_remove_error"))

        else:
            messages.add_message(request, messages.ERROR,
                                 error_messages.get("select_one"))
def delete_all_network(request, id_vlan='0', sf_number='0', sf_name='0', sf_environment='0', sf_nettype='0', sf_subnet='0', sf_ipversion='0', sf_network='0', sf_iexact='0', sf_acl='0'):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_network = auth.get_clientFactory().create_network()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # Control others exceptions
            have_errors = False
            error_list = list()

            # For each networks selected to remove
            for value in ids:
                try:

                    var = split_to_array(value, sep='-')

                    id_network = var[0]
                    network = var[1]

                    # Execute in NetworkAPI
                    if network == NETWORK_TYPES.v4:
                        client_network.deallocate_network_ipv4(id_network)

                    else:
                        client_network.deallocate_network_ipv6(id_network)

                except VipIpError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    error_list.append(id_network)

                except NetworkAPIClientError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True
                    error_list.append(id_network)

            # If all has ben removed
            if have_errors is False:
                messages.add_message(
                    request, messages.SUCCESS, vlan_messages.get("success_remove_network"))

            else:
                if len(ids) == len(error_list):
                    messages.add_message(
                        request, messages.ERROR, error_messages.get("can_not_remove_error"))
                else:
                    msg = ""
                    for id_error in error_list:
                        msg = msg + id_error + ", "
                    msg = error_messages.get("can_not_remove") % msg[:-2]
                    messages.add_message(request, messages.WARNING, msg)
def delete_all(request, sf_number='0', sf_name='0', sf_environment='0', sf_nettype='0', sf_subnet='0', sf_ipversion='0', sf_network='0', sf_iexact='0', sf_acl='0'):

    if request.method == 'POST':

        form = DeleteForm(request.POST)

        if form.is_valid():

            # Get user
            auth = AuthSession(request.session)
            client_vlan = auth.get_clientFactory().create_vlan()
            client = auth.get_clientFactory()

            # All ids to be deleted
            ids = split_to_array(form.cleaned_data['ids'])

            # All messages to display
            error_list = list()

            # Control others exceptions
            have_errors = False

            # For each vlan selected to remove
            for id_vlan in ids:
                try:

                    vlan = client_vlan.get(id_vlan).get("vlan")
                    environment = client.create_ambiente().buscar_por_id(
                        vlan.get("ambiente")).get("ambiente")

                    # Execute in NetworkAPI
                    client_vlan.deallocate(id_vlan)

                    # commenting code to remove acl files - issue #40
                    # key_acl_v4 = acl_key(NETWORK_TYPES.v4)
                    # key_acl_v6 = acl_key(NETWORK_TYPES.v6)
                    # user = AuthSession(request.session).get_user()

                    # try:
                    #     if vlan.get(key_acl_v4) is not None:
                    #         if checkAclGit(vlan.get(key_acl_v4), environment, NETWORK_TYPES.v4, user):
                    #             deleteAclGit(
                    #                 vlan.get(key_acl_v4), environment, NETWORK_TYPES.v4, user)

                    #     if vlan.get(key_acl_v6) is not None:
                    #         if checkAclGit(vlan.get(key_acl_v6), environment, NETWORK_TYPES.v6, user):
                    #             deleteAclGit(
                    #                 vlan.get(key_acl_v6), environment, NETWORK_TYPES.v6, user)

                    # except GITError, e:
                    #     messages.add_message(
                    #         request, messages.WARNING, vlan_messages.get("vlan_git_error"))

                except VipIpError, e:
                    logger.error(e)
                    messages.add_message(request, messages.ERROR, e)
                    error_list.append(id_vlan)
                    have_errors = True

                except VlanError, e:
                    error_list.append(id_vlan)
                    have_errors = True

                except NetworkAPIClientError, e:
                    logger.error(e)
                    error_list.append(id_vlan)
                    messages.add_message(request, messages.ERROR, e)
                    have_errors = True