diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-01-08 16:20:29 +0100 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-01-08 16:20:29 +0100 |
commit | 9e25cdc18d6a5013db876641ef0a151f34ff62c5 (patch) | |
tree | 12ce89c8b33d174c4cc978ddfa9f17e04a7349d1 /moon_manager/moon_manager/api | |
parent | 48857b80be18bb0985aab643f5c8c899194d636b (diff) |
Implement the delete_pod function in Manager and Orchestrator
Change-Id: I55da3610fa791ec9b3343cca49c5ca034cc7579f
Diffstat (limited to 'moon_manager/moon_manager/api')
-rw-r--r-- | moon_manager/moon_manager/api/pdp.py | 33 |
1 files changed, 30 insertions, 3 deletions
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 |