aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorEmma Foley <emma.l.foley@intel.com>2018-07-31 08:39:47 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-07-31 08:39:48 +0000
commit8a52d114404a03b4adbb49ff7f221819502bf672 (patch)
treef7182af42d5d2b10f9a2a35dddce3cbc9842535e /yardstick/common
parent5e8b885c30a1cc1eda23a6cb608566990e7d145c (diff)
parentd0c9fc59e53cace276093f8785fbdcd16fb1d2aa (diff)
Merge "Check for network already created k8"
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/kubernetes_utils.py22
1 files changed, 21 insertions, 1 deletions
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,10 +263,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(