diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-01-04 14:41:56 +0100 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-01-04 14:41:56 +0100 |
commit | 295ba85cba341338a2e74fef729dc74d091ac778 (patch) | |
tree | c131d0168a9f2ee10792d9257102dc9266175ed1 /python_moonutilities | |
parent | bb86c23b2b634b855d743e2b005b50391051372b (diff) |
update interface pod name to pipeline
Change-Id: I6a5a9ce3a27ea3ea40735dffa5f6a713f571cdc8
Diffstat (limited to 'python_moonutilities')
-rw-r--r-- | python_moonutilities/python_moonutilities/configuration.py | 36 | ||||
-rw-r--r-- | python_moonutilities/python_moonutilities/exceptions.py | 2 |
2 files changed, 14 insertions, 24 deletions
diff --git a/python_moonutilities/python_moonutilities/configuration.py b/python_moonutilities/python_moonutilities/configuration.py index c31432c3..4a072de4 100644 --- a/python_moonutilities/python_moonutilities/configuration.py +++ b/python_moonutilities/python_moonutilities/configuration.py @@ -25,10 +25,11 @@ def init_logging(): config = get_configuration("logging") logging.config.dictConfig(config['logging']) + def increment_port(): components_object = get_configuration("components/port_start") - if 'port_start' in components_object: - components_port_start = int(get_configuration("components/port_start")['port_start']) + if 'components/port_start' in components_object: + components_port_start = int(components_object['components/port_start']) components_port_start += 1 else: raise exceptions.ConsulComponentContentError("error={}".format(components_object)) @@ -39,6 +40,7 @@ def increment_port(): raise exceptions.ConsulError return components_port_start + def get_configuration(key): url = "http://{}:{}/v1/kv/{}".format(CONSUL_HOST, CONSUL_PORT, key) req = requests.get(url) @@ -62,6 +64,7 @@ def get_configuration(key): } for item in data ] + def add_component(name, uuid, port=None, bind="127.0.0.1", keystone_id="", extra=None, container=None): data = { "hostname": name, @@ -81,29 +84,16 @@ def add_component(name, uuid, port=None, bind="127.0.0.1", keystone_id="", extra logger.debug("data={}".format(data)) raise exceptions.ConsulError logger.info("Add component {}".format(req.text)) - return configuration.get_configuration("components/"+uuid) + return get_configuration("components/"+uuid) + def get_plugins(): - url = "http://{}:{}/v1/kv/plugins?recurse=true".format(CONSUL_HOST, CONSUL_PORT) - req = requests.get(url) - if req.status_code != 200: - logger.info("url={}".format(url)) - raise exceptions.ConsulError - data = req.json() - if len(data) == 1: - data = data[0] - if all(k in data for k in ("Key", "Value")): - return {data["Key"].replace("plugins/", ""): json.loads(base64.b64decode(data["Value"]).decode("utf-8"))} - raise exceptions.ConsulComponentContentError("error={}".format(data)) - else: - for item in data: - if not all(k in item for k in ("Key", "Value")): - logger.warning("invalidate content {}".format(item)) - raise exceptions.ConsulComponentContentError("error={}".format(data)) - return { - item["Key"].replace("plugins/", ""): json.loads(base64.b64decode(item["Value"]).decode("utf-8")) - for item in data - } + pipeline = get_configuration("components/pipeline") + logger.debug("pipeline={}".format(pipeline)) + components = pipeline.get("components/pipeline") + components.pop('interface') + return components + def get_components(): url = "http://{}:{}/v1/kv/components?recurse=true".format(CONSUL_HOST, CONSUL_PORT) diff --git a/python_moonutilities/python_moonutilities/exceptions.py b/python_moonutilities/python_moonutilities/exceptions.py index d85cef49..5b9ff340 100644 --- a/python_moonutilities/python_moonutilities/exceptions.py +++ b/python_moonutilities/python_moonutilities/exceptions.py @@ -3,7 +3,7 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. -from oslo_log import log as logging +import logging from werkzeug.exceptions import HTTPException logger = logging.getLogger("moon.utilities.exceptions") |