diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-01-15 21:12:32 +0100 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-01-15 21:12:32 +0100 |
commit | ba90e446c6d5a51c9ed392416f90b7bb56d11603 (patch) | |
tree | d4f2f02ace9af594fbe6abce3824cfb494ece998 /moon_manager | |
parent | 1da8f2e5f28813a90ecc329462dcc647ce757494 (diff) |
Add th ability to (un)load wrapper components through API
Change-Id: I58a25dbc0479e416d471115885dab7ccfb27e18a
Diffstat (limited to 'moon_manager')
-rw-r--r-- | moon_manager/moon_manager/api/slaves.py | 110 | ||||
-rw-r--r-- | moon_manager/moon_manager/http_server.py | 3 |
2 files changed, 112 insertions, 1 deletions
diff --git a/moon_manager/moon_manager/api/slaves.py b/moon_manager/moon_manager/api/slaves.py new file mode 100644 index 00000000..d87b8aad --- /dev/null +++ b/moon_manager/moon_manager/api/slaves.py @@ -0,0 +1,110 @@ +# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. +""" +PDP are Policy Decision Point. + +""" + +from flask import request +from flask_restful import Resource +import logging +import requests +import time +from python_moonutilities.security_functions import check_auth +from python_moondb.core import PDPManager +from python_moondb.core import PolicyManager +from python_moondb.core import ModelManager +from python_moonutilities import configuration, exceptions + +__version__ = "4.3.0" + +logger = logging.getLogger("moon.manager.api." + __name__) + + +class Slaves(Resource): + """ + Endpoint for pdp requests + """ + + __urls__ = ( + "/slaves", + "/slaves/", + "/slaves/<string:uuid>", + "/slaves/<string:uuid>/", + ) + + def __init__(self, **kwargs): + conf = configuration.get_configuration("components/orchestrator") + self.orchestrator_hostname = conf["components/orchestrator"].get("hostname", + "orchestrator") + self.orchestrator_port = conf["components/orchestrator"].get("port", + 80) + + @check_auth + def get(self, uuid=None, user_id=None): + """Retrieve all slaves + + :param uuid: uuid of the slave + :param user_id: user ID who do the request + :return: { + "slaves": { + "XXX": { + "name": "...", + "installed": True + }, + "YYY": { + "name": "...", + "installed": False + } + } + } + """ + req = requests.get("http://{}:{}/slaves".format( + self.orchestrator_hostname, self.orchestrator_port + )) + return {"slaves": req.json()} + + @check_auth + def patch(self, uuid=None, user_id=None): + """Update a slave + + :param uuid: uuid of the slave to update + :param user_id: user ID who do the request + :request body: { + "op": "replace", + "variable": "configured", + "value": True, + } + :return: 204 + :internal_api: add_pdp + """ + logger.info("Will made a request for {}".format(uuid)) + if request.json.get("op") == "replace" \ + and request.json.get("variable") == "configured" \ + and request.json.get("value"): + req = requests.post("http://{}:{}/pods".format( + self.orchestrator_hostname, self.orchestrator_port, + ), + json={"slave_name": uuid} + ) + if req.status_code != 200: + logger.warning("Get error from Orchestrator {} {}".format( + req.reason, req.status_code + )) + return "Orchestrator: " + str(req.reason), req.status_code + elif request.json.get("op") == "replace" \ + and request.json.get("variable") == "configured" \ + and not request.json.get("value"): + req = requests.delete("http://{}:{}/pods/{}".format( + self.orchestrator_hostname, self.orchestrator_port, uuid + )) + if req.status_code != 200: + logger.warning("Get error from Orchestrator {} {}".format( + req.reason, req.status_code + )) + return "Orchestrator: " + str(req.reason), req.status_code + else: + return "Malformed request", 400 + return {"slaves": req.json()} diff --git a/moon_manager/moon_manager/http_server.py b/moon_manager/moon_manager/http_server.py index d67e1121..a98cab43 100644 --- a/moon_manager/moon_manager/http_server.py +++ b/moon_manager/moon_manager/http_server.py @@ -14,6 +14,7 @@ from moon_manager.api.generic import Status, Logs, API from moon_manager.api.models import Models from moon_manager.api.policies import Policies from moon_manager.api.pdp import PDP +from moon_manager.api.slaves import Slaves from moon_manager.api.meta_rules import MetaRules from moon_manager.api.meta_data import SubjectCategories, ObjectCategories, ActionCategories from moon_manager.api.perimeter import Subjects, Objects, Actions @@ -32,7 +33,7 @@ __API__ = ( Subjects, Objects, Actions, Rules, SubjectAssignments, ObjectAssignments, ActionAssignments, SubjectData, ObjectData, ActionData, - Models, Policies, PDP + Models, Policies, PDP, Slaves ) |