diff options
author | Luc Provoost <luc.provoost@gmail.com> | 2023-01-17 12:23:58 +0100 |
---|---|---|
committer | Luc Provoost <luc.provoost@gmail.com> | 2023-01-17 17:45:13 +0000 |
commit | 77efe56b635f105502270010e365ddadef6ddbe1 (patch) | |
tree | 0b8945c0ba47150c88535f2da078b4647edfe6e8 /VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py | |
parent | f87088f24875450847dc305e6e7c56db8264bdbc (diff) |
Allow a different pod spec for each pod
A new parameter is now introduced in the [PODx] sections of the
rapid.pods file. This parameter specifies the pod spec yaml file that
will be used to create this specif pod. When this parameter is not
available, the default pod-rapid.yaml file will be used. The parameter
name is spec_file_name.
Also cleaned some lines of code exceeding 80 characters.
Signed-off-by: Luc Provoost <luc.provoost@gmail.com>
Change-Id: Id26881517d45baf4bf6be2e82b4f9e049f2b2547
Diffstat (limited to 'VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py')
-rw-r--r-- | VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py index d15fe7ff..3a90dcb2 100644 --- a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py +++ b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_pod.py @@ -32,6 +32,7 @@ class Pod: _name = "pod" _namespace = "default" _nodeSelector_hostname = None + _spec_filename = None _last_status = None _id = None _admin_ip = None @@ -56,10 +57,11 @@ class Pod: if self._ssh_client is not None: self._ssh_client.disconnect() - def create_from_yaml(self, file_name): + def create_from_yaml(self): """Load POD description from yaml file. """ - with open(path.join(path.dirname(__file__), file_name)) as yaml_file: + with open(path.join(path.dirname(__file__), + self._spec_filename)) as yaml_file: self.body = yaml.safe_load(yaml_file) self.body["metadata"]["name"] = self._name @@ -67,14 +69,16 @@ class Pod: if (self._nodeSelector_hostname is not None): if ("nodeSelector" not in self.body["spec"]): self.body["spec"]["nodeSelector"] = {} - self.body["spec"]["nodeSelector"]["kubernetes.io/hostname"] = self._nodeSelector_hostname + self.body["spec"]["nodeSelector"]["kubernetes.io/hostname"] = \ + self._nodeSelector_hostname self._log.debug("Creating POD, body:\n%s" % self.body) try: self.k8s_CoreV1Api.create_namespaced_pod(body = self.body, namespace = self._namespace) except client.rest.ApiException as e: - self._log.error("Couldn't create POD %s!\n%s\n" % (self._name, e)) + self._log.error("Couldn't create POD %s!\n%s\n" % (self._name, + e)) def terminate(self): """Terminate POD. Close SSH connection. @@ -204,6 +208,11 @@ class Pod: """ self._nodeSelector_hostname = hostname + def set_spec_file_name(self, file_name): + """Set pod spec filename. + """ + self._spec_filename = file_name + def set_ssh_credentials(self, user, rsa_private_key): """Set SSH credentials for the SSH connection to the POD. """ |