diff options
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( |