aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-07-06 09:00:20 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-07-06 09:00:20 +0000
commit3fd6e3cb5bfee0c29e2e880b5ec019c4ccb16df5 (patch)
treec28f86bec982bc5209241e728829e08ccf0e11b9 /yardstick/common
parent093ab6a10558456c0cf61091d69648638e311143 (diff)
parent1042a7077bba049d51022b7f4914048afb521cb1 (diff)
Merge "Add new Kubernetes resource kind: "Network""
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/exceptions.py9
-rw-r--r--yardstick/common/kubernetes_utils.py47
2 files changed, 56 insertions, 0 deletions
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 981e6f9d9..2d160bef1 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -219,6 +219,15 @@ class KubernetesCRDObjectDefinitionError(YardstickException):
'parameters: %(missing_parameters)s')
+class KubernetesNetworkObjectDefinitionError(YardstickException):
+ message = ('Kubernetes Network object definition error, missing '
+ 'parameters: %(missing_parameters)s')
+
+
+class KubernetesNetworkObjectKindMissing(YardstickException):
+ message = 'Kubernetes kind "Network" is not defined'
+
+
class ScenarioCreateNetworkError(YardstickException):
message = 'Create Neutron Network Scenario failed'
diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py
index a472b6de5..42267fc41 100644
--- a/yardstick/common/kubernetes_utils.py
+++ b/yardstick/common/kubernetes_utils.py
@@ -36,6 +36,14 @@ def get_extensions_v1beta_api():
return client.ApiextensionsV1beta1Api()
+def get_custom_objects_api():
+ try:
+ config.load_kube_config(config_file=consts.K8S_CONF_FILE)
+ except IOError:
+ raise exceptions.KubernetesConfigFileNotFound()
+ return client.CustomObjectsApi()
+
+
def get_node_list(**kwargs): # pragma: no cover
core_v1_api = get_core_api()
try:
@@ -220,6 +228,45 @@ def delete_custom_resource_definition(name):
action='delete', resource='CustomResourceDefinition')
+def get_custom_resource_definition(kind):
+ api = get_extensions_v1beta_api()
+ try:
+ crd_list = api.list_custom_resource_definition()
+ for crd_obj in (crd_obj for crd_obj in crd_list.items
+ if crd_obj.spec.names.kind == kind):
+ return crd_obj
+ return None
+ except ApiException:
+ raise exceptions.KubernetesApiException(
+ action='delete', resource='CustomResourceDefinition')
+
+
+def create_network(scope, group, version, plural, body, namespace='default'):
+ api = get_custom_objects_api()
+ try:
+ if scope == consts.SCOPE_CLUSTER:
+ api.create_cluster_custom_object(group, version, plural, body)
+ else:
+ api.create_namespaced_custom_object(
+ group, version, namespace, plural, body)
+ except ApiException:
+ raise exceptions.KubernetesApiException(
+ action='create', resource='Custom Object: Network')
+
+
+def delete_network(scope, group, version, plural, name, namespace='default'):
+ api = get_custom_objects_api()
+ try:
+ if scope == consts.SCOPE_CLUSTER:
+ api.delete_cluster_custom_object(group, version, plural, name, {})
+ else:
+ api.delete_namespaced_custom_object(
+ group, version, namespace, plural, name, {})
+ except ApiException:
+ raise exceptions.KubernetesApiException(
+ action='delete', resource='Custom Object: Network')
+
+
def get_pod_list(namespace='default'): # pragma: no cover
core_v1_api = get_core_api()
try: