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 | |
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')
3 files changed, 37 insertions, 23 deletions
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_deployment.py b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_deployment.py index bfb81611..9ef7ef6d 100644 --- a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_deployment.py +++ b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_deployment.py @@ -121,6 +121,14 @@ class K8sDeployment: else: pod_nodeselector_hostname = None + # Search for POD spec + if self._create_config.has_option("POD%d" % i, + "spec_file_name"): + pod_spec_file_name = self._create_config.get( + "POD%d" % i, "spec_file_name") + else: + pod_spec_file_name = K8sDeployment.POD_YAML_TEMPLATE_FILE_NAME + # Search for POD dataplane static IP if self._create_config.has_option("POD%d" % i, "dp_ip"): @@ -139,6 +147,7 @@ class K8sDeployment: pod = Pod(pod_name, self._namespace) pod.set_nodeselector(pod_nodeselector_hostname) + pod.set_spec_file_name(pod_spec_file_name) pod.set_dp_ip(pod_dp_ip) pod.set_dp_subnet(pod_dp_subnet) pod.set_id(i) @@ -157,7 +166,7 @@ class K8sDeployment: # Create PODs using template from yaml file for pod in self._pods: self._log.info("Creating POD %s...", pod.get_name()) - pod.create_from_yaml(K8sDeployment.POD_YAML_TEMPLATE_FILE_NAME) + pod.create_from_yaml() # Wait for PODs to start for pod in self._pods: 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. """ diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py index 352561d0..f00f916b 100644 --- a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py +++ b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py @@ -43,8 +43,7 @@ class RapidMachine(object): mac_key = 'dp_mac{}'.format(index) if ip_key in machine_params.keys(): if mac_key in machine_params.keys(): - dp_port = {'ip': machine_params[ip_key], - 'mac' : machine_params[mac_key]} + dp_port = {'ip': machine_params[ip_key], 'mac' : machine_params[mac_key]} else: dp_port = {'ip': machine_params[ip_key], 'mac' : None} self.dp_ports.append(dict(dp_port)) @@ -59,8 +58,7 @@ class RapidMachine(object): PROXConfigfile = open (self.machine_params['config_file'], 'r') PROXConfig = PROXConfigfile.read() PROXConfigfile.close() - self.all_tasks_for_this_cfg = set(re.findall("task\s*=\s*(\d+)", - PROXConfig)) + self.all_tasks_for_this_cfg = set(re.findall("task\s*=\s*(\d+)",PROXConfig)) def get_cores(self): return (self.machine_params['cores']) @@ -94,19 +92,16 @@ class RapidMachine(object): else: RapidLog.critical('{Cannot determine cpuset') cpuset_cpus = self._client.run_cmd(cmd).decode().rstrip() - RapidLog.debug('{} ({}): Allocated cpuset: {}'.format(self.name, - self.ip, cpuset_cpus)) + RapidLog.debug('{} ({}): Allocated cpuset: {}'.format(self.name, self.ip, cpuset_cpus)) self.cpu_mapping = self.expand_list_format(cpuset_cpus) - RapidLog.debug('{} ({}): Expanded cpuset: {}'.format(self.name, - self.ip, self.cpu_mapping)) + RapidLog.debug('{} ({}): Expanded cpuset: {}'.format(self.name, self.ip, self.cpu_mapping)) # Log CPU core mapping for user information cpu_mapping_str = '' for i in range(len(self.cpu_mapping)): cpu_mapping_str = cpu_mapping_str + '[' + str(i) + '->' + str(self.cpu_mapping[i]) + '], ' cpu_mapping_str = cpu_mapping_str[:-2] - RapidLog.debug('{} ({}): CPU mapping: {}'.format(self.name, self.ip, - cpu_mapping_str)) + RapidLog.debug('{} ({}): CPU mapping: {}'.format(self.name, self.ip, cpu_mapping_str)) def remap_cpus(self, cpus): """Convert relative cpu ids provided as function parameter to match @@ -126,14 +121,12 @@ class RapidMachine(object): if 'mcore' in self.machine_params.keys(): cpus_remapped = self.remap_cpus(self.machine_params['mcore']) - RapidLog.debug('{} ({}): mcore {} remapped to {}'.format(self.name, - self.ip, self.machine_params['mcore'], cpus_remapped)) + RapidLog.debug('{} ({}): mcore {} remapped to {}'.format(self.name, self.ip, self.machine_params['mcore'], cpus_remapped)) self.machine_params['mcore'] = cpus_remapped if 'cores' in self.machine_params.keys(): cpus_remapped = self.remap_cpus(self.machine_params['cores']) - RapidLog.debug('{} ({}): cores {} remapped to {}'.format(self.name, - self.ip, self.machine_params['cores'], cpus_remapped)) + RapidLog.debug('{} ({}): cores {} remapped to {}'.format(self.name, self.ip, self.machine_params['cores'], cpus_remapped)) self.machine_params['cores'] = cpus_remapped def devbind(self): @@ -170,17 +163,20 @@ class RapidMachine(object): else: LuaFile.write("eal=\"\"\n") if 'mcore' in self.machine_params.keys(): - LuaFile.write('mcore="%s"\n'% ','.join(map(str, self.machine_params['mcore']))) + LuaFile.write('mcore="%s"\n'% ','.join(map(str, + self.machine_params['mcore']))) if 'cores' in self.machine_params.keys(): - LuaFile.write('cores="%s"\n'% ','.join(map(str, self.machine_params['cores']))) + LuaFile.write('cores="%s"\n'% ','.join(map(str, + self.machine_params['cores']))) if 'ports' in self.machine_params.keys(): - LuaFile.write('ports="%s"\n'% ','.join(map(str, self.machine_params['ports']))) + LuaFile.write('ports="%s"\n'% ','.join(map(str, + self.machine_params['ports']))) if 'dest_ports' in self.machine_params.keys(): for index, dest_port in enumerate(self.machine_params['dest_ports'], start = 1): LuaFile.write('dest_ip{}="{}"\n'.format(index, dest_port['ip'])) LuaFile.write('dest_hex_ip{}=convertIPToHex(dest_ip{})\n'.format(index, index)) if dest_port['mac']: - LuaFile.write('dest_hex_mac{}="{}"\n'.format(index, + LuaFile.write('dest_hex_mac{}="{}"\n'.format(index , dest_port['mac'].replace(':',' '))) if 'gw_vm' in self.machine_params.keys(): for index, gw_ip in enumerate(self.machine_params['gw_ips'], |