X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwvnfm%2Frift%2Ftasklets%2Frwvnfmtasklet%2Frwvnfmtasklet.py;h=36f0351f7f077325fa79ae8e6310e4f5bdc21358;hb=0c288cecce7762d51431c4a044588736a8571371;hp=2c6c1024da68d65af926bb99f6acfbfc4a966485;hpb=e5ce4ffee708ce25521d0a95280c25904ab94ddd;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 2c6c1024..36f0351f 100755 --- a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py +++ b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py @@ -308,6 +308,14 @@ class VirtualDeploymentUnitRecord(object): return conn_point.ip_address return "0.0.0.0" + def cp_mac_addr(self, cp_name): + """ Find mac address by connection point name """ + if self._vm_resp is not None: + for conn_point in self._vm_resp.connection_points: + if conn_point.name == cp_name: + return conn_point.mac_addr + return "00:00:00:00:00:00" + def cp_id(self, cp_name): """ Find connection point id by connection point name """ if self._vm_resp is not None: @@ -408,7 +416,8 @@ class VirtualDeploymentUnitRecord(object): icp_list.append({"name": cp.name, "id": cp.id, "type_yang": "VPORT", - "ip_address": self.cp_ip_addr(cp.id)}) + "ip_address": self.cp_ip_addr(cp.id), + "mac_address": self.cp_mac_addr(cp.id)}) ii_list.append({"name": intf.name, "vdur_internal_connection_point_ref": cp.id, @@ -423,7 +432,10 @@ class VirtualDeploymentUnitRecord(object): ei_list.append({"name": cp, "vnfd_connection_point_ref": cp, "virtual_interface": {}}) - self._vnfr.update_cp(cp, self.cp_ip_addr(cp), self.cp_id(cp)) + self._vnfr.update_cp(cp, + self.cp_ip_addr(cp), + self.cp_mac_addr(cp), + self.cp_id(cp)) vdur_dict["external_interface"] = ei_list @@ -1227,6 +1239,7 @@ class VirtualNetworkFunctionRecord(object): vnfr_dict.update(vnfd_copy_dict) vnfr_msg = RwVnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr.from_dict(vnfr_dict) + vnfr_msg.uptime = int(time.time()) - self._create_time vnfr_msg.mgmt_interface = mgmt_intf # Add all the VLRs to VNFR @@ -1651,13 +1664,14 @@ class VirtualNetworkFunctionRecord(object): # Update the VNFR with the changed status yield from self.publish(None) - def update_cp(self, cp_name, ip_address, cp_id): + def update_cp(self, cp_name, ip_address, mac_addr, cp_id): """Updated the connection point with ip address""" for cp in self._cprs: if cp.name == cp_name: self._log.debug("Setting ip address and id for cp %s, cpr %s with ip %s id %s", cp_name, cp, ip_address, cp_id) cp.ip_address = ip_address + cp.mac_address = mac_addr cp.connection_point_id = cp_id return @@ -1760,6 +1774,10 @@ class VirtualNetworkFunctionRecord(object): self._log.debug("VNFR-ID %s: Instantiation Done", self._vnfr_id) + # create task updating uptime for this vnfr + self._log.debug("VNFR-ID %s: Starting task to update uptime", self._vnfr_id) + self._loop.create_task(self.vnfr_uptime_update(xact)) + @asyncio.coroutine def terminate(self, xact): """ Terminate this virtual network function """ @@ -1797,6 +1815,19 @@ class VirtualNetworkFunctionRecord(object): self._log.debug("Terminated VNF id %s", self.vnfr_id) self.set_state(VirtualNetworkFunctionRecordState.TERMINATED) + @asyncio.coroutine + def vnfr_uptime_update(self, xact): + while True: + # Return when vnfr state is FAILED or TERMINATED etc + if self._state not in [VirtualNetworkFunctionRecordState.INIT, + VirtualNetworkFunctionRecordState.VL_INIT_PHASE, + VirtualNetworkFunctionRecordState.VM_INIT_PHASE, + VirtualNetworkFunctionRecordState.READY]: + return + yield from self.publish(xact) + yield from asyncio.sleep(2, loop=self._loop) + + class VnfdDtsHandler(object): """ DTS handler for VNFD config changes """