def _add_mp_vnfd_to_project(self, mp, ec, template=TEMPLATE_VNFD_MP): """ Uses templates/tango_vnfd_mp.yml as basis, extends it and stores it in project folder. Finally the project.yml is updated. """ tpath = os.path.join( os.path.dirname(os.path.abspath(__file__)), template) vnfd = read_yaml(tpath) # TODO better use template engine like Jinja # replace placeholder fields (this highly depends on used template!) vnfd["name"] = mp.get("name") # allow different containers as parameter study vnfd["virtual_deployment_units"][0]["vm_image"] = mp.get("container") # add manually defined data interface address if mp.get("address"): for cp in vnfd["connection_points"]: if cp.get("id") == "data": cp["address"] = mp.get("address") # write vnfd to project vname = "{}.yaml".format(mp.get("name")) write_yaml(os.path.join(ec.project_path, vname), vnfd) # add vnfd to project.yml ppath = os.path.join(ec.project_path, "project.yml") projd = read_yaml(ppath) projd.get("files").append({ "path": vname, "type": "application/vnd.5gtango.vnfd", "tags": ["eu.5gtango", "mp"] }) write_yaml(ppath, projd) LOG.debug("Added MP VNFD {} to project {}" .format(vname, projd.get("name")))
def _add_params_to_project(self, ec): """ Apply parameters, like resource limits, commands, to the project descriptors. """ # 1. read all VNFDs vnfds = self._read_vnfds(ec) # 2. update VNFDs for _, vnfd in vnfds.items(): self._apply_parameters_to_vnfds(ec, vnfd) # 3. write updated VNFDs for path, vnfd in vnfds.items(): write_yaml(path, vnfd)
def _add_mp_to_nsd(self, mp, ec): """ Add MP to NSD: - add VNF to functions section - connect measurement points w. virt. links - update forwarding graph """ # 1. load NSD nsd = read_yaml(self._get_nsd_path(ec)) # 2. add MP VNF to NSD nsd.get("network_functions").append({ "vnf_id": mp.get("name"), "vnf_name": mp.get("name"), "vnf_vendor": "eu.5gtango.benchmark", "vnf_version": "1.0" }) # 3. connect measurement point to service (replace virt. links) mp_cp = mp.get("connection_point") new_cp = "{}:data".format(mp.get("name")) # update links for vl in nsd.get("virtual_links"): cprs = vl.get("connection_points_reference") # replace ns in/out link endpoints in NSD for i in range(0, len(cprs)): if cprs[i] == mp_cp: cprs[i] = new_cp LOG.debug( "Replaced virtual link CPR '{}' by '{}'" .format(mp_cp, cprs[i])) # 4. update forwarding graph (replace ns in and out) for fg in nsd.get("forwarding_graphs"): # add MP VNF to constituent VNF list fg.get("constituent_vnfs").append(mp.get("name")) # update forwarding paths for fp in fg.get("network_forwarding_paths"): # search and replace connection points specified in PED for fp_cp in fp.get("connection_points"): if fp_cp.get("connection_point_ref") == mp_cp: fp_cp["connection_point_ref"] = new_cp # update number of endpoints fg["number_of_endpoints"] -= 1 LOG.debug("Updated forwarding graph '{}': {}" .format(fg.get("fg_id"), fg)) # 5. store updated nsd write_yaml(self._get_nsd_path(ec), nsd) ec.nsd = nsd # 6. log LOG.debug("Added measurement point VNF '{}' to NDS '{}'" .format(mp.get("name"), nsd.get("name")))
def _write(self, output_path): """ Write this SONATA service project structure to disk. This includes all descriptors etc. The generated files can be used as input to the SONATA packaging tool. """ path = os.path.join(output_path, SON_GEN_SERVICES, self.pkg_name) # update package path to reflect new location self.metadata["project_disk_path"] = path # create output folder ensure_dir(path) # write project yml write_yaml(os.path.join(path, "project.yml"), self.pd) # write nsd nsd_dir = os.path.join(path, "sources/nsd") ensure_dir(nsd_dir) write_yaml(os.path.join(nsd_dir, "%s.yml" % self.nsd.get("name")), self.nsd) # write all vnfds vnf_dir = os.path.join(path, "sources/vnf") for vnfd in self.vnfd_list: d = os.path.join(vnf_dir, vnfd.get("name")) ensure_dir(d) write_yaml(os.path.join(d, "%s.yml" % vnfd.get("name")), vnfd) LOG.debug("Wrote: {} to {}".format(self, path)) return path