X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2Fkubernetes_utils.py;h=323f13abbff366a38cecd2b132270f1c9c776b26;hb=3914b4028025fee9f5037ba29453201f99720f24;hp=e708dc503c388f0a1b74005189d6062c262670b4;hpb=b7ce705c0662671983f034d99c01941af8bc5d68;p=yardstick.git diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index e708dc503..323f13abb 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -263,8 +263,28 @@ 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)