Beispiel #1
0
from flask import request, Response
from flask_restplus import Resource
import json
import logging

from nat.nat_controller import NatController
from nat.rest_api.api import api

nat_root_ns = api.namespace('', 'Nat Root Resource')

@nat_root_ns.route('/', methods=['GET','PUT'])
class Nat(Resource):
    @nat_root_ns.response(200, 'Nat status retrieved.')
    @nat_root_ns.response(500, 'Internal Error.')
    def get(self):
        """
        Gets the status of the nat
        """
        try:
            natController = NatController()
            json_data = json.dumps(natController.get_full_status())
            resp = Response(json_data, status=200, mimetype="application/json")
            return resp

        except Exception as err:
            return Response(json.dumps(str(err)), status=500, mimetype="application/json")

    @nat_root_ns.param("Nat Configuration", "Nat Configuration to update", "body", type="string", required=True)
    @nat_root_ns.response(202, 'Nat configuration updated.')
    @nat_root_ns.response(400, 'Bad request.')
    @nat_root_ns.response(500, 'Internal Error.')
Beispiel #2
0
from flask import request, Response
from flask_restplus import Resource
import json
import logging

from nat.nat_controller import NatController
from nat.rest_api.api import api

nat_table_ns = api.namespace('nat', 'Nat Table Resource')


@nat_table_ns.route('/nat-table', methods=['GET'])
class Nat_Table(Resource):
    @nat_table_ns.response(200, 'Nat table retrieved.')
    @nat_table_ns.response(500, 'Internal Error.')
    def get(self):
        """
        Gets the nat table
        """
        try:
            natController = NatController()
            json_data = json.dumps(natController.get_nat_table())
            resp = Response(json_data, status=200, mimetype="application/json")
            return resp

        except Exception as err:
            return Response(json.dumps(str(err)),
                            status=500,
                            mimetype="application/json")
Beispiel #3
0
from flask import request, Response
from flask_restplus import Resource
import json
import logging

from nat.nat_controller import NatController
from nat.rest_api.api import api

nat_ns = api.namespace('nat', 'Nat Resource')

@nat_ns.route('', methods=['GET','PUT'])
class Nat(Resource):
    @nat_ns.response(200, 'Nat status retrieved.')
    @nat_ns.response(500, 'Internal Error.')
    def get(self):
        """
        Gets the status of the nat
        """
        try:
            natController = NatController()
            json_data = json.dumps(natController.get_nat_status())
            resp = Response(json_data, status=200, mimetype="application/json")
            return resp

        except Exception as err:
            return Response(json.dumps(str(err)), status=500, mimetype="application/json")

    @nat_ns.param("Nat Configuration", "Nat Configuration to update", "body", type="string", required=True)
    @nat_ns.response(202, 'Nat configuration updated.')
    @nat_ns.response(400, 'Bad request.')
    @nat_ns.response(500, 'Internal Error.')
Beispiel #4
0
from flask import request, Response
from flask_restplus import Resource
import json
import logging

from nat.nat_controller import NatController
from nat.rest_api.api import api

arp_table_ns = api.namespace('nat', 'Arp Table Resource')


@arp_table_ns.route('/arp-table', methods=['GET', 'POST'])
@arp_table_ns.route('/arp-table/<id>', methods=['DELETE'])
class Arp_Table(Resource):
    @arp_table_ns.param("Arp entry",
                        "Arp entry to add",
                        "body",
                        type="string",
                        required=True)
    @arp_table_ns.response(202, 'Arp entry correctly added.')
    @arp_table_ns.response(400, 'Bad request.')
    @arp_table_ns.response(500, 'Internal Error.')
    def post(self):
        """
        Add an arp entry
        """
        try:
            natController = NatController()
            json_data = json.loads(request.data.decode())
            natController.add_arp_entry(json_data)
            return Response(status=202)
Beispiel #5
0
from flask import request, Response
from flask_restplus import Resource
import json
import logging

from nat.nat_controller import NatController
from nat.rest_api.api import api

floatingIP_ns = api.namespace('nat', 'Floating IP Resource')


@floatingIP_ns.route('/floatingIP', methods=['GET', 'POST'])
@floatingIP_ns.route('/floatingIP/<id>', methods=['GET', 'PUT', 'DELETE'])
class Nat_FloatingIP(Resource):
    @floatingIP_ns.param("Floating IP",
                         "Floating IP to add",
                         "body",
                         type="string",
                         required=True)
    @floatingIP_ns.response(202, 'Floating IP correctly added.')
    @floatingIP_ns.response(400, 'Bad request.')
    @floatingIP_ns.response(500, 'Internal Error.')
    def post(self):
        """
        Add a Floating IP
        """
        try:
            natController = NatController()
            json_data = json.loads(request.data.decode())
            natController.add_floating_ip(json_data)
            return Response(status=202)