From: Ananda Baitharu Date: Tue, 15 Nov 2016 15:18:19 +0000 (-0500) Subject: RIFT-14481 uptime for vlr, vnfr, nsr X-Git-Tag: v1.1.0~52^2~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=055eabb8205cf0707a139f394f0afb5dbfa7423c;p=osm%2FSO.git RIFT-14481 uptime for vlr, vnfr, nsr Signed-off-by: Ananda Baitharu --- diff --git a/models/plugins/yang/nsr.yang b/models/plugins/yang/nsr.yang index c2b7d06b..f7c16fe6 100644 --- a/models/plugins/yang/nsr.yang +++ b/models/plugins/yang/nsr.yang @@ -613,6 +613,14 @@ module nsr type uint32; } + leaf uptime { + description + "Active period of this Network Service. + Uptime is expressed in seconds"; + + type uint32; + } + list connection-point { description "List for external connection points. diff --git a/models/plugins/yang/vlr.yang b/models/plugins/yang/vlr.yang index ef3d6039..20ba6f7e 100644 --- a/models/plugins/yang/vlr.yang +++ b/models/plugins/yang/vlr.yang @@ -132,6 +132,14 @@ module vlr type uint32; } + leaf uptime { + description + "Active period of this Virtual Link. + Uptime is expressed in seconds"; + + type uint32; + } + leaf network-id { description "Identifier for the allocated network resource."; diff --git a/models/plugins/yang/vnfr.yang b/models/plugins/yang/vnfr.yang index 4a427d4a..a4419ce6 100644 --- a/models/plugins/yang/vnfr.yang +++ b/models/plugins/yang/vnfr.yang @@ -199,6 +199,14 @@ module vnfr type uint32; } + leaf uptime { + description + "Active period of this Virtual Network Function. + Uptime is expressed in seconds"; + + type uint32; + } + leaf vnfd-ref { description "Reference to VNFD"; type leafref { diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py index 002431de..62d06f92 100755 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py @@ -460,6 +460,7 @@ class VnffgRecord(object): class VirtualLinkRecord(object): """ Virtual Link Records class""" + XPATH = "D,/vlr:vlr-catalog/vlr:vlr" @staticmethod @asyncio.coroutine def create_record(dts, log, loop, nsr_name, vld_msg, cloud_account_name, om_datacenter, ip_profile, nsr_id, restart_mode=False): @@ -647,7 +648,6 @@ class VirtualLinkRecord(object): @asyncio.coroutine def instantiate(self): """ Instantiate this VL """ - self._log.debug("Instaniating VLR key %s, vld %s", self.xpath, self._vld_msg) vlr = None @@ -1233,7 +1233,8 @@ class NetworkServiceRecord(object): """ Network service record """ XPATH = "D,/nsr:ns-instance-opdata/nsr:nsr" - def __init__(self, dts, log, loop, nsm, nsm_plugin, nsr_cfg_msg, sdn_account_name, key_pairs, restart_mode=False): + def __init__(self, dts, log, loop, nsm, nsm_plugin, nsr_cfg_msg, sdn_account_name, key_pairs, restart_mode=False, + vlr_handler=None): self._dts = dts self._log = log self._loop = loop @@ -1241,6 +1242,7 @@ class NetworkServiceRecord(object): self._nsr_cfg_msg = nsr_cfg_msg self._nsm_plugin = nsm_plugin self._sdn_account_name = sdn_account_name + self._vlr_handler = vlr_handler self._nsd = None self._nsr_msg = None @@ -1454,6 +1456,18 @@ class NetworkServiceRecord(object): for vlr in self._vlrs: yield from self.nsm_plugin.instantiate_vl(self, vlr) vlr.state = VlRecordState.ACTIVE + self._loop.create_task(self.vlr_uptime_update(vlr)) + + + def vlr_uptime_update(self, vlr): + vlr_ = RwVlrYang.YangData_Vlr_VlrCatalog_Vlr.from_dict({'id': vlr.id}) + while True: + if vlr.state not in [VlRecordState.INIT, VlRecordState.INSTANTIATION_PENDING, VlRecordState.ACTIVE]: + return + vlr_.uptime = int(time.time()) - vlr._create_time + yield from self._vlr_handler.update(None, VirtualLinkRecord.vlr_xpath(vlr), vlr_) + yield from asyncio.sleep(2, loop=self._loop) + @asyncio.coroutine def create(self, config_xact): @@ -2474,6 +2488,7 @@ class NetworkServiceRecord(object): nsr.config_status = self.map_config_status() nsr.config_status_details = self._config_status_details nsr.create_time = self._create_time + nsr.uptime = int(time.time()) - self._create_time for cfg_prim in self.nsd_msg.service_primitive: cfg_prim = NsrYang.YangData_Nsr_NsInstanceOpdata_Nsr_ServicePrimitive.from_dict( @@ -3837,7 +3852,8 @@ class NsManager(object): nsr_msg, sdn_account_name, key_pairs, - restart_mode=restart_mode + restart_mode=restart_mode, + vlr_handler=self._ro_plugin_selector._records_publisher._vlr_pub_hdlr ) self._nsrs[nsr_msg.id] = nsr nsm_plugin.create_nsr(nsr_msg, nsr_msg.nsd, key_pairs) diff --git a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py index 2c6c1024..1a896812 100755 --- a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py +++ b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py @@ -1227,6 +1227,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 @@ -1760,6 +1761,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 +1802,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 """