from flask import request, Response from flask_restplus import Resource import json import logging from dhcp.dhcp_controller import DhcpController from dhcp.rest_api.api import api dhcp_root_ns = api.namespace('', 'Dhcp Root Resource') @dhcp_root_ns.route('/', methods=['GET','PUT']) class DhcpRoot(Resource): @dhcp_root_ns.response(200, 'Dhcp full status retrieved.') @dhcp_root_ns.response(500, 'Internal Error.') def get(self): """ Gets the status of the dhcp server """ try: dhcpController = DhcpController() json_data = json.dumps(dhcpController.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") @dhcp_root_ns.param("Dhcp Configuration", "Dhcp Configuration to update", "body", type="string", required=True) @dhcp_root_ns.response(202, 'Nat configuration updated.') @dhcp_root_ns.response(400, 'Bad request.') @dhcp_root_ns.response(500, 'Internal Error.')
from flask import request, Response from flask_restplus import Resource import json import logging from dhcp.dhcp_controller import DhcpController from dhcp.rest_api.api import api client_ns = api.namespace('dhcp', 'Dhcp Server Client Resource') @client_ns.route('/clients', methods=['GET']) @client_ns.route('/clients/<id>', methods=['GET']) class Client(Resource): @client_ns.response(200, 'Client retrieved.') @client_ns.response(404, 'Client not found.') @client_ns.response(500, 'Internal Error.') def get(self, id=None): """ Gets the dhcp client """ try: dhcpController = DhcpController() if id is None: json_data = json.dumps(dhcpController.get_clients()) else: json_data = json.dumps(dhcpController.get_client(id)) resp = Response(json_data, status=200, mimetype="application/json") return resp except ValueError as ve: return Response(json.dumps(str(ve)), status=404, mimetype="application/json")
from flask import request, Response from flask_restplus import Resource import json import logging from dhcp.dhcp_controller import DhcpController from dhcp.rest_api.api import api config_ns = api.namespace('dhcp', 'Dhcp Server Configuration Resource') @config_ns.route('/server', methods=['GET']) class DhcpServer_Configuration(Resource): @config_ns.response(200, 'Dhcp server configuration retrieved.') @config_ns.response(404, 'Dhcp server not found.') @config_ns.response(500, 'Internal Error.') def get(self): """ Gets the configuration of the dhcp server """ try: dhcpController = DhcpController() json_data = json.dumps( dhcpController.get_dhcp_server_configuration()) resp = Response(json_data, status=200, mimetype="application/json") return resp except ValueError as ve: return Response(json.dumps(str(ve)), status=404, mimetype="application/json")
from flask import request, Response from flask_restplus import Resource import json import logging from dhcp.dhcp_controller import DhcpController from dhcp.rest_api.api import api interface_ns = api.namespace('interfaces', 'Interface Resource') @interface_ns.route('', methods=['GET']) class Interface(Resource): @interface_ns.response(200, 'Interfaces retrieved.') @interface_ns.response(500, 'Internal Error.') def get(self): """ Gets the status of all interfaces """ try: dhcpController = DhcpController() json_data = json.dumps(dhcpController.get_interfaces_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")
from flask import request, Response from flask_restplus import Resource import json import logging from dhcp.dhcp_controller import DhcpController from dhcp.rest_api.api import api dhcp_ns = api.namespace('dhcp', 'Dhcp Resource') @dhcp_ns.route('', methods=['GET', 'PUT']) class DhcpServer(Resource): @dhcp_ns.response(200, 'Dhcp status retrieved.') @dhcp_ns.response(500, 'Internal Error.') def get(self): """ Gets the status of the dhcp server """ try: dhcpController = DhcpController() json_data = json.dumps(dhcpController.get_dhcp_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") @dhcp_ns.param("Dhcp Configuration",