diff options
Diffstat (limited to 'k8s/k8splugin')
-rw-r--r-- | k8s/k8splugin/discovery.py | 9 | ||||
-rw-r--r-- | k8s/k8splugin/tasks.py | 40 | ||||
-rw-r--r-- | k8s/k8splugin/utils.py | 3 |
3 files changed, 23 insertions, 29 deletions
diff --git a/k8s/k8splugin/discovery.py b/k8s/k8splugin/discovery.py index 56f8260..76c160a 100644 --- a/k8s/k8splugin/discovery.py +++ b/k8s/k8splugin/discovery.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -233,12 +234,10 @@ def add_to_entry(conn, key, add_name, add_value): def _find_matching_services(services, name_search, tags): """Find matching services given search criteria""" - def is_match(service): - srv_name, srv_tags = service - return name_search in srv_name and \ - all(map(lambda tag: tag in srv_tags, tags)) + tags = set(tags) + return [srv_name for srv_name in services + if name_search in srv_name and tags <= set(services[srv_name])] - return [ srv[0] for srv in services.items() if is_match(srv) ] def search_services(conn, name_search, tags): """Search for services that match criteria diff --git a/k8s/k8splugin/tasks.py b/k8s/k8splugin/tasks.py index 108cf31..956fff2 100644 --- a/k8s/k8splugin/tasks.py +++ b/k8s/k8splugin/tasks.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,9 +21,6 @@ # Lifecycle interface calls for containerized components -# Needed by Cloudify Manager to load google.auth for the Kubernetes python client -import cloudify_importer - import time, copy import json from cloudify import ctx @@ -138,16 +136,14 @@ def _parse_streams(**kwargs): """Parse streams and setup for DMaaP plugin""" # The DMaaP plugin requires this plugin to set the runtime properties # keyed by the node name. - def setup_publishes(s): - kwargs[s["name"]] = s - - map(setup_publishes, kwargs["streams_publishes"]) + for stream in kwargs["streams_publishes"]: + kwargs[stream["name"]] = stream - def setup_subscribes(s): - if s["type"] == "data_router": + for stream in kwargs["streams_subscribes"]: + if stream["type"] == "data_router": # Don't want to mutate the source - s = copy.deepcopy(s) + stream = copy.deepcopy(stream) # Set up the delivery URL # Using service_component_name as the host name in the subscriber URL @@ -156,29 +152,27 @@ def _parse_streams(**kwargs): # more remote ("edge") locations depends on how networking and DNS is set # up in a multi-cluster deployment service_component_name = kwargs["name"] - ports,_ = k8sclient.parse_ports(kwargs["ports"]) - (dport, _) = ports[0] + ports, _ = k8sclient.parse_ports(kwargs["ports"]) + dport, _ = ports[0] subscriber_host = "{host}:{port}".format(host=service_component_name, port=dport) - scheme = s["scheme"] if "scheme" in s else DEFAULT_SCHEME - if "route" not in s: + scheme = stream.get("scheme", DEFAULT_SCHEME) + if "route" not in stream: raise NonRecoverableError("'route' key missing from data router subscriber") - path = s["route"] - s["delivery_url"] = "{scheme}://{host}/{path}".format( + path = stream["route"] + stream["delivery_url"] = "{scheme}://{host}/{path}".format( scheme=scheme, host=subscriber_host, path=path) # If username and password has not been provided then generate it. The # DMaaP plugin doesn't generate for subscribers. The generation code # and length of username password has been lifted from the DMaaP # plugin. - if not s.get("username", None): - s["username"] = utils.random_string(8) - if not s.get("password", None): - s["password"] = utils.random_string(10) - - kwargs[s["name"]] = s + if not stream.get("username", None): + stream["username"] = utils.random_string(8) + if not stream.get("password", None): + stream["password"] = utils.random_string(10) - map(setup_subscribes, kwargs["streams_subscribes"]) + kwargs[stream["name"]] = stream return kwargs diff --git a/k8s/k8splugin/utils.py b/k8s/k8splugin/utils.py index c45af68..6475aaa 100644 --- a/k8s/k8splugin/utils.py +++ b/k8s/k8splugin/utils.py @@ -2,6 +2,7 @@ # org.onap.dcae # ================================================================================ # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,7 +35,7 @@ def update_dict(d, u): Update dict d with dict u """ - for k, v in u.iteritems(): + for k, v in u.items(): if isinstance(v, collections.Mapping): r = update_dict(d.get(k, {}), v) d[k] = r |