diff options
author | Sridhar Rao <sridhar.rao@spirent.com> | 2021-08-27 02:46:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2021-08-27 02:46:07 +0000 |
commit | 4d2d65ec768a959ef788c7c9f5745901155a1b1f (patch) | |
tree | 474f3e2f56f455888146848e5be7dbe76e4c9053 /pods/papi/papi.py | |
parent | f1737f24bcc72b08bc13728b56f8b3f50edcff03 (diff) | |
parent | 558c274c0a8f5736e05f5d40d4279d13dde975c1 (diff) |
Merge "Enhance Pod-Deployment using Python-API."
Diffstat (limited to 'pods/papi/papi.py')
-rw-r--r-- | pods/papi/papi.py | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/pods/papi/papi.py b/pods/papi/papi.py index 5c15fa04..67cc3bc5 100644 --- a/pods/papi/papi.py +++ b/pods/papi/papi.py @@ -1,4 +1,4 @@ -# Copyright 2020 University Of Delhi. +# Copyright 2021 University Of Delhi, Spirent Communications # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -55,8 +55,11 @@ class Papi(IPod): namespace = 'default' pod_manifests = S.getValue('POD_MANIFEST_FILEPATH') pod_count = int(S.getValue('POD_COUNT')) - #namespace = 'vswitchperf' - # replace_namespace(api, namespace) + if S.hasValue('POD_NAMESPACE'): + namespace = S.getValue('POD_NAMESPACE') + else: + namespace = 'default' + dep_pod_list = [] # sriov configmap if S.getValue('PLUGIN') == 'sriov': @@ -70,8 +73,7 @@ class Papi(IPod): group = 'k8s.cni.cncf.io' version = 'v1' kind_plural = 'network-attachment-definitions' - api = client.CustomObjectsApi() - + api = client.CustomObjectsApi() assert pod_count <= len(pod_manifests) for nad_filepath in S.getValue('NETWORK_ATTACHMENT_FILEPATH'): @@ -87,10 +89,10 @@ class Papi(IPod): #create pod workloads api = client.CoreV1Api() - for count in range(pod_count): + dep_pod_info = {} pod_manifest = load_manifest(pod_manifests[count]) - + dep_pod_info['name'] = pod_manifest["metadata"]["name"] try: response = api.create_namespaced_pod(namespace, pod_manifest) self._logger.info(str(response)) @@ -98,7 +100,40 @@ class Papi(IPod): except ApiException as err: raise Exception from err - time.sleep(12) + # Wait for the pod to start + time.sleep(5) + status = "Unknown" + count = 0 + while True: + if count == 10: + break + try: + response = api.read_namespaced_pod_status(dep_pod_info['name'], + namespace) + status = response.status.phase + except ApiException as err: + raise Exception from err + if (status == "Running" + or status == "Failed" + or status == "Unknown"): + break + else: + time.sleep(5) + count = count + 1 + # Now Get the Pod-IP + try: + response = api.read_namespaced_pod_status(dep_pod_info['name'], + namespace) + dep_pod_info['pod_ip'] = response.status.pod_ip + except ApiException as err: + raise Exception from err + dep_pod_info['namespace'] = namespace + dep_pod_list.append(dep_pod_info) + cmd = ['cat', '/etc/podnetinfo/annotations'] + execute_command(api, dep_pod_info, cmd) + + S.setValue('POD_LIST',dep_pod_list) + return dep_pod_list def terminate(self): """ |