diff options
author | John O Loughlin <john.oloughlin@intel.com> | 2018-07-13 10:41:15 +0100 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-07-20 11:17:49 +0000 |
commit | d0c9fc59e53cace276093f8785fbdcd16fb1d2aa (patch) | |
tree | e4acfb114b5bbcd9e4a981fb3cd55f0e46be5a63 /yardstick/common | |
parent | 438f7b5100e05ed668a0ea90674008a391eb5784 (diff) |
Check for network already created k8
When creating a network the host should be checked to see if the network
is already created. If the required network is already there it should be used.
JIRA: YARDSTICK-1315
Change-Id: I09b114a728364ee56397af70cc48f1b7904f06cc
Signed-off-by: John O Loughlin <john.oloughlin@intel.com>
Diffstat (limited to 'yardstick/common')
-rw-r--r-- | yardstick/common/kubernetes_utils.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index 42267fc41..d1dd42173 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -241,10 +241,30 @@ def get_custom_resource_definition(kind): action='delete', resource='CustomResourceDefinition') -def create_network(scope, group, version, plural, body, namespace='default'): +def get_network(scope, group, version, plural, name, namespace='default'): api = get_custom_objects_api() try: if scope == consts.SCOPE_CLUSTER: + network = api.get_cluster_custom_object(group, version, plural, name) + else: + network = api.get_namespaced_custom_object( + group, version, namespace, plural, name) + except ApiException as e: + if e.status in [404]: + return + else: + raise exceptions.KubernetesApiException( + action='get', resource='Custom Object: Network') + return network + + +def create_network(scope, group, version, plural, body, name, namespace='default'): + api = get_custom_objects_api() + if get_network(scope, group, version, plural, name, namespace): + logging.info('Network %s already exists', name) + return + try: + if scope == consts.SCOPE_CLUSTER: api.create_cluster_custom_object(group, version, plural, body) else: api.create_namespaced_custom_object( |