X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwvnfm%2Frift%2Ftasklets%2Frwvnfmtasklet%2Frwvnfmtasklet.py;h=253094f33ad8d8f2fef09806beea61c2d3dbd2e1;hb=a3bb91f092d378448cb870eccd45d43865de143c;hp=abf73aecdad2c75de891b25714f3aee2eb39f16b;hpb=f49375710db1acf3cd74c8651d098b7a08e8d0b2;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py index abf73aec..253094f3 100755 --- a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py +++ b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py @@ -55,6 +55,7 @@ from rift.mano.utils.project import ( ManoProject, ProjectHandler, ) +import rift.mano.utils.short_name as mano_short_name class VMResourceError(Exception): @@ -277,6 +278,7 @@ class VirtualDeploymentUnitRecord(object): project, vdud, vnfr, + nsr_config, mgmt_intf, mgmt_network, cloud_account_name, @@ -289,6 +291,7 @@ class VirtualDeploymentUnitRecord(object): self._project = project self._vdud = vdud self._vnfr = vnfr + self._nsr_config = nsr_config self._mgmt_intf = mgmt_intf self._cloud_account_name = cloud_account_name self._vnfd_package_store = vnfd_package_store @@ -349,6 +352,31 @@ class VirtualDeploymentUnitRecord(object): """ Return this VDUR's name """ return self._name + # Truncated name confirming to RFC 1123 + @property + def unique_short_name(self): + """ Return this VDUR's unique short name """ + # Impose these restrictions on Unique name + # Max 64 + # - Max 10 of NSR name (remove all specialcharacters, only numbers and alphabets) + # - 6 chars of shortened name + # - Max 10 of VDU name (remove all specialcharacters, only numbers and alphabets) + # + def _restrict_tag(input_str): + # Exclude all characters except a-zA-Z0-9 + outstr = re.sub('[^a-zA-Z0-9]', '', input_str) + # Take max of 10 chars + return outstr[-10:] + + # Use NSR name for part1 + part1 = _restrict_tag(self._nsr_config.name) + # Get unique short string (6 chars) + part2 = mano_short_name.StringShortner(self._name) + # Use VDU ID for part3 + part3 = _restrict_tag(self._vdud.id) + shortstr = part1 + "-" + part2.short_string + "-" + part3 + return shortstr + @property def cloud_account_name(self): """ Cloud account this VDU should be created in """ @@ -400,14 +428,17 @@ class VirtualDeploymentUnitRecord(object): "hypervisor_epa", "host_epa", "volumes", - "name"] + ] vdu_copy_dict = {k: v for k, v in self._vdud.as_dict().items() if k in vdu_fields} vdur_dict = {"id": self._vdur_id, "vdu_id_ref": self._vdud.id, "operational_status": self.operational_status, "operational_status_details": self._state_failed_reason, + "name": self.name, + "unique_short_name": self.unique_short_name } + if self.vm_resp is not None: vdur_dict.update({"vim_id": self.vm_resp.vdu_id, "flavor_id": self.vm_resp.flavor_id @@ -623,7 +654,8 @@ class VirtualDeploymentUnitRecord(object): vdu_copy_dict = {k: v for k, v in self._vdud.as_dict().items() if k in vdu_fields} vm_create_msg_dict = { - "name": self.name, + "name": self.unique_short_name, # Truncated name confirming to RFC 1123 + "node_id": self.name, # Rift assigned Id } if self.image_name is not None: @@ -1219,7 +1251,7 @@ class VirtualNetworkFunctionRecord(object): @staticmethod def vnfd_xpath(vnfd_id): """ VNFD xpath associated with this VNFR """ - return ("C,/vnfd:vnfd-catalog/vnfd:vnfd[vnfd:id = '{}']". + return ("C,/project-vnfd:vnfd-catalog/project-vnfd:vnfd[project-vnfd:id = '{}']". format(vnfd_id)) @property @@ -1524,7 +1556,7 @@ class VirtualNetworkFunctionRecord(object): return None @asyncio.coroutine - def get_vdu_placement_groups(self, vdu): + def get_vdu_placement_groups(self, vdu, nsr_config): placement_groups = [] ### Step-1: Get VNF level placement groups for group in self._vnfr_msg.placement_groups_info: @@ -1532,10 +1564,7 @@ class VirtualNetworkFunctionRecord(object): #group_info.from_dict(group.as_dict()) placement_groups.append(group) - ### Step-2: Get NSR config. This is required for resolving placement_groups cloud constructs - nsr_config = yield from self.get_nsr_config() - - ### Step-3: Get VDU level placement groups + ### Step-2: Get VDU level placement groups for group in self.vnfd.placement_groups: for member_vdu in group.member_vdus: if member_vdu.member_vdu_ref == vdu.id: @@ -1583,16 +1612,22 @@ class VirtualNetworkFunctionRecord(object): self._log.info("Creating VDU's for vnfd id: %s", self.vnfd_id) + + # Get NSR config - Needed for placement groups and to derive VDU short-name + nsr_config = yield from self.get_nsr_config() + for vdu in self._rw_vnfd.vdu: self._log.debug("Creating vdu: %s", vdu) vdur_id = get_vdur_id(vdu) - placement_groups = yield from self.get_vdu_placement_groups(vdu) - self._log.info("Launching VDU: %s from VNFD :%s (Member Index: %s) with Placement Groups: %s", + + placement_groups = yield from self.get_vdu_placement_groups(vdu, nsr_config) + self._log.info("Launching VDU: %s from VNFD :%s (Member Index: %s) with Placement Groups: %s, Existing vdur_id %s", vdu.name, self.vnf_name, self.member_vnf_index, - [ group.name for group in placement_groups]) + [ group.name for group in placement_groups], + vdur_id) vdur = VirtualDeploymentUnitRecord( dts=self._dts, @@ -1601,6 +1636,7 @@ class VirtualNetworkFunctionRecord(object): project = self._project, vdud=vdu, vnfr=vnfr, + nsr_config=nsr_config, mgmt_intf=self.has_mgmt_interface(vdu), mgmt_network=self._mgmt_network, cloud_account_name=self.cloud_account_name, @@ -1895,7 +1931,7 @@ class VirtualNetworkFunctionRecord(object): # instantiate VLs - self._log.debug("Instantiate VLs {}: {}".format(self._vnfr_id, self._state)) + self._log.debug("VNFR-ID %s: Instantiate VLs, restart mode %s", self._vnfr_id, restart_mode) try: yield from self.instantiate_vls(xact, restart_mode) except Exception as e: @@ -1906,7 +1942,7 @@ class VirtualNetworkFunctionRecord(object): self.set_state(VirtualNetworkFunctionRecordState.VM_INIT_PHASE) # instantiate VDUs - self._log.debug("Create VDUs {}: {}".format(self._vnfr_id, self._state)) + self._log.debug("VNFR-ID %s: Create VDUs, restart mode %s", self._vnfr_id, restart_mode) yield from self.create_vdus(self, restart_mode) try: @@ -1989,7 +2025,7 @@ class VirtualNetworkFunctionRecord(object): class VnfdDtsHandler(object): """ DTS handler for VNFD config changes """ - XPATH = "C,/vnfd:vnfd-catalog/vnfd:vnfd" + XPATH = "C,/project-vnfd:vnfd-catalog/project-vnfd:vnfd" def __init__(self, dts, log, loop, vnfm): self._dts = dts @@ -2006,7 +2042,7 @@ class VnfdDtsHandler(object): def deregister(self): '''De-register from DTS''' self._log.debug("De-register VNFD DTS handler for project {}". - format(self._project)) + format(self._vnfm._project.name)) if self._regh: self._regh.deregister() self._regh = None @@ -2025,8 +2061,9 @@ class VnfdDtsHandler(object): @asyncio.coroutine def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch): """ on prepare callback """ - self._log.debug("Got on prepare for VNFD (path: %s) (action: %s)", - ks_path.to_xpath(RwVnfmYang.get_schema()), msg) + self._log.debug("Got on prepare for VNFD (path: %s) (action: %s) (msg: %s)", + ks_path.to_xpath(RwVnfmYang.get_schema()), + xact_info.query_action, msg) fref = ProtobufC.FieldReference.alloc() fref.goto_whole_message(msg.to_pbcm()) @@ -2076,7 +2113,7 @@ class VcsComponentDtsHandler(object): def deregister(self): '''De-register from DTS''' self._log.debug("De-register VCS DTS handler for project {}". - format(self._project)) + format(self._vnfm._project)) if self._regh: self._regh.deregister() self._regh = None @@ -2154,7 +2191,7 @@ class VnfrConsoleOperdataDtsHandler(object): if action == rwdts.QueryAction.READ: schema = RwVnfrYang.YangData_RwProject_Project_VnfrConsole_Vnfr_Vdur.schema() path_entry = schema.keyspec_to_entry(ks_path) - self._log.debug("VDU Opdata path is {}".format(path_entry)) + self._log.debug("VDU Opdata path is {}".format(path_entry.key00.id)) try: vnfr = self._vnfm.get_vnfr(self._vnfr_id) except VnfRecordError as e: @@ -2417,7 +2454,7 @@ class VnfdRefCountDtsHandler(object): def deregister(self): '''De-register from DTS''' self._log.debug("De-register VNFD Ref DTS handler for project {}". - format(self._project)) + format(self._vnfm._project)) if self._regh: self._regh.deregister() self._regh = None @@ -2499,6 +2536,8 @@ class VdurDatastore(object): set_if_not_none('name', vdur._vdud.name) set_if_not_none('mgmt.ip', vdur.vm_management_ip) + # The below can be used for hostname + set_if_not_none('vdur_name', vdur.unique_short_name) def update(self, vdur): """Update the VDUR information in the datastore @@ -2527,6 +2566,8 @@ class VdurDatastore(object): set_or_delete('name', vdur._vdud.name) set_or_delete('mgmt.ip', vdur.vm_management_ip) + # The below can be used for hostname + set_or_delete('vdur_name', vdur.unique_short_name) def remove(self, vdur_id): """Remove all of the data associated with specified VDUR @@ -2619,9 +2660,9 @@ class VnfManager(object): yield from hdl.register() def deregister(self): - self.log.debug("De-register VNFM project {}".format(self.name)) + self._log.debug("De-register VNFM project {}".format(self._project.name)) for hdl in self._dts_handlers: - yield from hdl.deregister() + hdl.deregister() @asyncio.coroutine def run(self):