From 9e25cdc18d6a5013db876641ef0a151f34ff62c5 Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Mon, 8 Jan 2018 16:20:29 +0100 Subject: Implement the delete_pod function in Manager and Orchestrator Change-Id: I55da3610fa791ec9b3343cca49c5ca034cc7579f --- moon_manager/moon_manager/api/pdp.py | 33 +++++++++++++++++++++++++++--- moon_manager/tests/unit_python/conftest.py | 28 ++++++++++++------------- 2 files changed, 43 insertions(+), 18 deletions(-) (limited to 'moon_manager') diff --git a/moon_manager/moon_manager/api/pdp.py b/moon_manager/moon_manager/api/pdp.py index 3ae55d33..4f11135e 100644 --- a/moon_manager/moon_manager/api/pdp.py +++ b/moon_manager/moon_manager/api/pdp.py @@ -14,6 +14,8 @@ 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.2" @@ -22,7 +24,29 @@ logger = logging.getLogger("moon.manager.api." + __name__) def delete_pod(uuid): - raise NotImplementedError + conf = configuration.get_configuration("components/orchestrator") + hostname = conf["components/orchestrator"].get("hostname", "orchestrator") + port = conf["components/orchestrator"].get("port", 80) + proto = conf["components/orchestrator"].get("protocol", "http") + # while True: + # try: + url = "{}://{}:{}/pods".format(proto, hostname, port) + req = requests.get(url) + # except requests.exceptions.ConnectionError: + # logger.warning("Orchestrator is not ready, standby... {}".format(url)) + # time.sleep(1) + # else: + # break + for pod_key, pod_list in req.json().get("pods", {}).items(): + for pod_value in pod_list: + if "pdp_id" in pod_value: + if pod_value["pdp_id"] == uuid: + req = requests.delete("{}://{}:{}/pods/{}".format(proto, hostname, port, pod_key)) + if req.status_code != 200: + logger.warning("Cannot delete pod {} - {}".format(pod_key, pod_value['name'])) + logger.debug(req.content) + # Note (Asteroide): no need to go further if one match + break def add_pod(uuid, data): @@ -31,6 +55,8 @@ def add_pod(uuid, data): logger.info("Add a new pod {}".format(data)) if "pdp_id" not in data: data["pdp_id"] = uuid + data['policies'] = PolicyManager.get_policies(user_id="admin") + data['models'] = ModelManager.get_models(user_id="admin") conf = configuration.get_configuration("components/orchestrator") hostname = conf["components/orchestrator"].get("hostname", "orchestrator") port = conf["components/orchestrator"].get("port", 80) @@ -41,8 +67,9 @@ def add_pod(uuid, data): "{}://{}:{}/pods".format(proto, hostname, port), json=data, headers={"content-type": "application/json"}) - except requests.exceptions.ConnectionError: - logger.warning("Orchestrator is not ready, standby...") + except requests.exceptions.ConnectionError as e: + logger.warning("add_pod: Orchestrator is not ready, standby...") + logger.exception(e) time.sleep(1) else: break diff --git a/moon_manager/tests/unit_python/conftest.py b/moon_manager/tests/unit_python/conftest.py index c59fae40..3f73f2da 100644 --- a/moon_manager/tests/unit_python/conftest.py +++ b/moon_manager/tests/unit_python/conftest.py @@ -37,21 +37,19 @@ CONF = { "container": "wukongsun/moon_orchestrator:v4.3", "hostname": "interface" }, - "interface": { - "bind": "0.0.0.0", - "port": 8080, - "container": "wukongsun/moon_interface:v4.3", - "hostname": "interface" - } - }, - "plugins": { - "session": { - "port": 8082, - "container": "asteroide/session:latest" - }, - "authz": { - "port": 8081, - "container": "wukongsun/moon_authz:v4.3" + "pipeline": { + "interface": { + "bind": "0.0.0.0", + "port": 8080, + "container": "wukongsun/moon_interface:v4.3", + "hostname": "interface" + }, + "authz": { + "bind": "0.0.0.0", + "port": 8081, + "container": "wukongsun/moon_authz:v4.3", + "hostname": "authz" + }, } }, "logging": { -- cgit 1.2.3-korg