Ejemplo n.º 1
0
def insert_vrf(request):
    try:
        lists = {}

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

        lists["form_vrf"] = VrfForm()  # TODO Alterar depois de edit pra ""

        if request.method == 'POST':
            # Set data in form
            vrf_form = VrfForm(request.POST)

            # Return data to form in case of error
            lists["form_vrf"] = vrf_form

            # Validate
            if vrf_form.is_valid():
                vrf = vrf_form.cleaned_data["vrf"]
                internal_name = vrf_form.cleaned_data["internal_name"]

                list_vrf = [{"vrf": vrf, "internal_name": internal_name}]

                client.create_api_vrf().create(list_vrf)
                messages.add_message(request, messages.SUCCESS,
                                     vrf_messages.get("success_insert"))

                return redirect('vrf.list')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 2
0
def insert_vrf(request):
    try:
        lists = {}

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

        lists["form_vrf"] = VrfForm()  # TODO Alterar depois de edit pra ""

        if request.method == 'POST':
            # Set data in form
            vrf_form = VrfForm(request.POST)

            # Return data to form in case of error
            lists["form_vrf"] = vrf_form

            # Validate
            if vrf_form.is_valid():
                vrf = vrf_form.cleaned_data["vrf"]
                internal_name = vrf_form.cleaned_data["internal_name"]

                list_vrf = [{
                    "vrf": vrf,
                    "internal_name": internal_name

                }]

                client.create_api_vrf().create(list_vrf)
                messages.add_message(
                    request, messages.SUCCESS, vrf_messages.get("success_insert"))

                return redirect('vrf.list')
    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 3
0
def edit_vrf(request, id_vrf):
    try:
        lists = {}

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

        vrf = client.create_api_vrf().get(ids=[id_vrf]).get("vrfs")[0]

        lists['form_vrf'] = VrfForm(
            initial=vrf
        )

        if request.method == 'POST':
            # Set data in form
            vrf_form = VrfForm(request.POST)

            # Return data to form in case of error
            lists["form_vrf"] = vrf_form

            if vrf_form.is_valid():
                id = vrf_form.cleaned_data["id"]
                vrf = vrf_form.cleaned_data["vrf"]
                internal_name = vrf_form.cleaned_data["internal_name"]

                list_vrf = [{
                    "id": id,
                    "vrf": vrf,
                    "internal_name": internal_name
                }]

                client.create_api_vrf().update(list_vrf)
                messages.add_message(
                    request, messages.SUCCESS, vrf_messages.get("success_edit"))

                return redirect('vrf.list')

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 4
0
def edit_vrf(request, id_vrf):
    try:
        lists = {}

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

        vrf = client.create_api_vrf().get(ids=[id_vrf]).get("vrfs")[0]

        lists['form_vrf'] = VrfForm(
            initial=vrf
        )

        if request.method == 'POST':
            # Set data in form
            vrf_form = VrfForm(request.POST)

            # Return data to form in case of error
            lists["form_vrf"] = vrf_form

            if vrf_form.is_valid():
                id = vrf_form.cleaned_data["id"]
                vrf = vrf_form.cleaned_data["vrf"]
                internal_name = vrf_form.cleaned_data["internal_name"]

                list_vrf = [{
                    "id": id,
                    "vrf": vrf,
                    "internal_name": internal_name
                }]

                client.create_api_vrf().update(list_vrf)
                messages.add_message(
                    request, messages.SUCCESS, vrf_messages.get("success_edit"))

                return redirect('vrf.list')

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 5
0
def add_vrf(request):
    """ function to handle the creation of a new vrf
    """

    try:

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

        if request.method == 'POST':
            name = request.POST.get('vrfName')
            internal_name = request.POST.get('vrfInternalName')

            vrf = dict(vrf=name, internal_name=internal_name)
            client.create_api_vrf().create([vrf])

            messages.add_message(request,
                                 messages.SUCCESS,
                                 vrf_messages.get("success_insert"))

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