aboutsummaryrefslogtreecommitdiffstats
path: root/moon_orchestrator/moon_orchestrator/api
diff options
context:
space:
mode:
Diffstat (limited to 'moon_orchestrator/moon_orchestrator/api')
-rw-r--r--moon_orchestrator/moon_orchestrator/api/__init__.py0
-rw-r--r--moon_orchestrator/moon_orchestrator/api/generic.py99
-rw-r--r--moon_orchestrator/moon_orchestrator/api/pods.py174
-rw-r--r--moon_orchestrator/moon_orchestrator/api/slaves.py46
4 files changed, 0 insertions, 319 deletions
diff --git a/moon_orchestrator/moon_orchestrator/api/__init__.py b/moon_orchestrator/moon_orchestrator/api/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/moon_orchestrator/moon_orchestrator/api/__init__.py
+++ /dev/null
diff --git a/moon_orchestrator/moon_orchestrator/api/generic.py b/moon_orchestrator/moon_orchestrator/api/generic.py
deleted file mode 100644
index 9128140a..00000000
--- a/moon_orchestrator/moon_orchestrator/api/generic.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# 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'.
-"""
-Those API are helping API used to manage the Moon platform.
-"""
-
-from flask_restful import Resource, request
-import logging
-import moon_orchestrator.api
-from python_moonutilities.security_functions import check_auth
-
-__version__ = "4.3.1"
-
-logger = logging.getLogger("moon.orchestrator.api." + __name__)
-
-
-class Status(Resource):
- """
- Endpoint for status requests
- """
-
- __urls__ = ("/status", "/status/", "/status/<string:component_id>")
-
- def get(self, component_id=None):
- """Retrieve status of all components
-
- :return: {
- "orchestrator": {
- "status": "Running"
- },
- "security_router": {
- "status": "Running"
- }
- }
- """
- raise NotImplemented
-
-
-class API(Resource):
- """
- Endpoint for API requests
- """
-
- __urls__ = (
- "/api",
- "/api/",
- "/api/<string:group_id>",
- "/api/<string:group_id>/",
- "/api/<string:group_id>/<string:endpoint_id>")
-
- @check_auth
- def get(self, group_id="", endpoint_id="", user_id=""):
- """Retrieve all API endpoints or a specific endpoint if endpoint_id is given
-
- :param group_id: the name of one existing group (ie generic, ...)
- :param endpoint_id: the name of one existing component (ie Logs, Status, ...)
- :return: {
- "group_name": {
- "endpoint_name": {
- "description": "a description",
- "methods": {
- "get": "description of the HTTP method"
- },
- "urls": ('/api', '/api/', '/api/<string:endpoint_id>')
- }
- }
- """
- __methods = ("get", "post", "put", "delete", "options", "patch")
- api_list = filter(lambda x: "__" not in x, dir(moon_orchestrator.api))
- api_desc = dict()
- for api_name in api_list:
- api_desc[api_name] = {}
- group_api_obj = eval("moon_interface.api.{}".format(api_name))
- api_desc[api_name]["description"] = group_api_obj.__doc__
- if "__version__" in dir(group_api_obj):
- api_desc[api_name]["version"] = group_api_obj.__version__
- object_list = list(filter(lambda x: "__" not in x, dir(group_api_obj)))
- for obj in map(lambda x: eval("moon_interface.api.{}.{}".format(api_name, x)),
- object_list):
- if "__urls__" in dir(obj):
- api_desc[api_name][obj.__name__] = dict()
- api_desc[api_name][obj.__name__]["urls"] = obj.__urls__
- api_desc[api_name][obj.__name__]["methods"] = dict()
- for _method in filter(lambda x: x in __methods, dir(obj)):
- docstring = eval(
- "moon_interface.api.{}.{}.{}.__doc__".format(api_name, obj.__name__,
- _method))
- api_desc[api_name][obj.__name__]["methods"][_method] = docstring
- api_desc[api_name][obj.__name__]["description"] = str(obj.__doc__)
- if group_id in api_desc:
- if endpoint_id in api_desc[group_id]:
- return {group_id: {endpoint_id: api_desc[group_id][endpoint_id]}}
- elif len(endpoint_id) > 0:
- logger.error("Unknown endpoint_id {}".format(endpoint_id))
- return {"error": "Unknown endpoint_id {}".format(endpoint_id)}
- return {group_id: api_desc[group_id]}
- return api_desc
diff --git a/moon_orchestrator/moon_orchestrator/api/pods.py b/moon_orchestrator/moon_orchestrator/api/pods.py
deleted file mode 100644
index 8943e018..00000000
--- a/moon_orchestrator/moon_orchestrator/api/pods.py
+++ /dev/null
@@ -1,174 +0,0 @@
-# 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'.
-
-from flask import request
-from flask_restful import Resource
-from python_moonutilities.security_functions import check_auth
-from python_moonutilities import exceptions
-import logging
-
-logger = logging.getLogger("moon.orchestrator.api.pods")
-
-
-class Pods(Resource):
- """
- Endpoint for pdp requests
- """
-
- __version__ = "4.3.1"
- POD_TYPES = ("authz", "wrapper")
-
- __urls__ = (
- "/pods",
- "/pods/",
- "/pods/<string:uuid>",
- "/pods/<string:uuid>/",
- )
-
- def __init__(self, **kwargs):
- self.driver = kwargs.get("driver")
-
- @check_auth
- def get(self, uuid=None, user_id=None):
- """Retrieve all pods
-
- :param uuid: uuid of the pod
- :param user_id: user ID who do the request
- :return: {
- "pod_id1": {
- "name": "...",
- "replicas": "...",
- "description": "...",
- }
- }
- :internal_api: get_pdp
- """
- pods = {}
- try:
- if uuid:
- return {"pods": self.driver.get_pods(uuid)}
- for _pod_key, _pod_values in self.driver.get_pods().items():
- pods[_pod_key] = []
- for _pod_value in _pod_values:
- if "namespace" in _pod_value and _pod_value['namespace'] != "moon":
- continue
- pods[_pod_key].append(_pod_value)
- return {"pods": pods}
- except Exception as e:
- return {"result": False, "message": str(e)}, 500
-
- def __validate_pod_with_keystone_pid(self, keystone_pid):
- for pod_key, pod_values in self.driver.get_pods().items():
- if pod_values and "keystone_project_id" in pod_values[0] \
- and pod_values[0]['keystone_project_id'] == keystone_pid:
- return True
-
- def __is_slave_exist(self, slave_name):
- for slave in self.driver.get_slaves():
- if "name" in slave and "configured" in slave \
- and slave_name == slave["name"] and slave["configured"]:
- return True
-
- def __get_slave_names(self):
- for slave in self.driver.get_slaves():
- if "name" in slave:
- yield slave["name"]
-
- @check_auth
- def post(self, uuid=None, user_id=None):
- """Create a new pod.
-
- :param uuid: uuid of the pod (not used here)
- :param user_id: user ID who do the request
- :request body: {
- "pdp_id": "fa2323f7055d4a88b1b85d31fe5e8369",
- "name": "pdp_rbac3",
- "keystone_project_id": "ceacbb5564cc48ad929dd4f00e52bf63",
- "models": {...},
- "policies": {...},
- "description": "test",
- "security_pipeline": [...],
- "slave_name": ""
- }
- :return: {
- "pdp_id1": {
- "name": "...",
- "replicas": "...",
- "description": "...",
- }
- }
- """
- if "security_pipeline" in request.json:
- if self.__validate_pod_with_keystone_pid(request.json.get("keystone_project_id")):
- raise exceptions.PipelineConflict
- if not request.json.get("pdp_id"):
- raise exceptions.PdpUnknown
- if not request.json.get("security_pipeline"):
- raise exceptions.PolicyUnknown
- self.driver.create_pipeline(
- request.json.get("keystone_project_id"),
- request.json.get("pdp_id"),
- request.json.get("security_pipeline"),
- manager_data=request.json,
- slave_name=request.json.get("slave_name"))
- else:
- logger.info("------------------------------------")
- logger.info(list(self.__get_slave_names()))
- logger.info("------------------------------------")
- if self.__is_slave_exist(request.json.get("slave_name")):
- raise exceptions.WrapperConflict
- if request.json.get("slave_name") not in self.__get_slave_names():
- raise exceptions.SlaveNameUnknown
- slave_name = request.json.get("slave_name")
- if not slave_name:
- slave_name = self.driver.get_slaves(active=True)
- self.driver.create_wrappers(slave_name)
- return {"pods": self.driver.get_pods()}
-
- @check_auth
- def delete(self, uuid=None, user_id=None):
- """Delete a pod
-
- :param uuid: uuid of the pod to delete
- :param user_id: user ID who do the request
- :return: {
- "result": "True or False",
- "message": "optional message"
- }
- """
- try:
- self.driver.delete_pipeline(uuid)
- return {'result': True}
- except exceptions.PipelineUnknown:
- for slave in self.driver.get_slaves():
- if "name" in slave and "wrapper_name" in slave:
- if uuid in (slave['name'], slave["wrapper_name"]):
- self.driver.delete_wrapper(name=slave["wrapper_name"])
- else:
- raise exceptions.SlaveNameUnknown
- except Exception as e:
- return {"result": False, "message": str(e)}, 500
-
- # @check_auth
- # def patch(self, uuid=None, user_id=None):
- # """Update a pod
- #
- # :param uuid: uuid of the pdp to update
- # :param user_id: user ID who do the request
- # :request body: {
- # "name": "...",
- # "replicas": "...",
- # "description": "...",
- # }
- # :return: {
- # "pod_id1": {
- # "name": "...",
- # "replicas": "...",
- # "description": "...",
- # }
- # }
- # :internal_api: update_pdp
- # """
- # return {"pods": None}
diff --git a/moon_orchestrator/moon_orchestrator/api/slaves.py b/moon_orchestrator/moon_orchestrator/api/slaves.py
deleted file mode 100644
index 7453d305..00000000
--- a/moon_orchestrator/moon_orchestrator/api/slaves.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# 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'.
-
-from flask import request
-from flask_restful import Resource
-from python_moonutilities.security_functions import check_auth
-import logging
-
-logger = logging.getLogger("moon.orchestrator.api.slaves")
-
-
-class Slaves(Resource):
- """
- Endpoint for slaves requests
- """
-
- __version__ = "4.3.1"
-
- __urls__ = (
- "/slaves",
- "/slaves/",
- "/slaves/<string:uuid>",
- "/slaves/<string:uuid>/",
- )
-
- def __init__(self, **kwargs):
- self.driver = kwargs.get("driver")
-
- @check_auth
- def get(self, uuid=None, user_id=None):
- """Retrieve all pods
-
- :param uuid: uuid of the pod
- :param user_id: user ID who do the request
- :return: {
- "pod_id1": {
- "name": "...",
- "replicas": "...",
- "description": "...",
- }
- }
- """
- slaves = self.driver.get_slaves()
- return {"slaves": slaves}