-#
+#
# Copyright 2016 RIFT.IO Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
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):
self._vlr_id = str(uuid.uuid4())
self._state = VlRecordState.INIT
self._prev_state = None
-
+ self._create_time = int(time.time())
+
@property
def xpath(self):
""" path for this object """
"nsr_id_ref": self._nsr_id,
"vld_ref": self.vld_msg.id,
"name": self.name,
+ "create_time": self._create_time,
"cloud_account": self.cloud_account_name,
"om_datacenter": self.om_datacenter_name,
}
@asyncio.coroutine
def instantiate(self):
""" Instantiate this VL """
-
self._log.debug("Instaniating VLR key %s, vld %s",
self.xpath, self._vld_msg)
vlr = None
vnfr_dict = {
"id": self.id,
"nsr_id_ref": self._nsr_id,
- "vnfd_ref": self.vnfd.id,
"name": self.name,
"cloud_account": self._cloud_account_name,
"om_datacenter": self._om_datacenter_name,
vnfr_dict.update(vnfd_copy_dict)
vnfr = RwVnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr.from_dict(vnfr_dict)
+
+ vnfr.vnfd = VnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr_Vnfd.from_dict(self.vnfd.as_dict())
vnfr.member_vnf_index_ref = self.member_vnf_index
vnfr.vnf_configuration.from_dict(self._vnfd.vnf_configuration.as_dict())
cpr.vlr_ref = vlr_ref.id
self.vnfr_msg.connection_point.append(cpr)
self._log.debug("Connection point [%s] added, vnf id=%s vnfd id=%s",
- cpr, self.vnfr_msg.id, self.vnfr_msg.vnfd_ref)
+ cpr, self.vnfr_msg.id, self.vnfr_msg.vnfd.id)
if not self.restart_mode:
yield from self._dts.query_create(self.xpath,
""" 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
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
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):
self._vnffgrs[vnffgr.id] = vnffgr
def resolve_vld_ip_profile(self, nsd_msg, vld):
+ self._log.debug("Receieved ip profile ref is %s",vld.ip_profile_ref)
if not vld.has_field('ip_profile_ref'):
return None
- profile = [ profile for profile in nsd_msg.ip_profiles if profile.name == vld.ip_profile_ref ]
+ profile = [profile for profile in nsd_msg.ip_profiles if profile.name == vld.ip_profile_ref]
return profile[0] if profile else None
@asyncio.coroutine
def _create_vls(self, vld, cloud_account,om_datacenter):
"""Create a VLR in the cloud account specified using the given VLD
-
+
Args:
vld : VLD yang obj
cloud_account : Cloud account name
-
+
Returns:
VirtualLinkRecord
"""
""" This function creates VLs for every VLD in the NSD
associated with this NSR"""
for vld in self.nsd_msg.vld:
+
self._log.debug("Found vld %s in nsr id %s", vld, self.id)
cloud_account_list = self._extract_cloud_accounts_for_vl(vld)
for cloud_account,om_datacenter in cloud_account_list:
if vlr is None:
cloud_account_list = self._extract_cloud_accounts_for_vl(vld)
- for account in cloud_account_list:
- vlr = yield from self._create_vls(vld, account)
+ for account,om_datacenter in cloud_account_list:
+ vlr = yield from self._create_vls(vld, account,om_datacenter)
self._vlrs.append(vlr)
vlr.state = VlRecordState.INSTANTIATION_PENDING
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(
rpc_op = NsrYang.YangOutput_Nsr_StartNetworkService.from_dict({
"nsr_id":str(uuid.uuid4())
})
-
+
if not ('name' in rpc_ip and 'nsd_ref' in rpc_ip and ('cloud_account' in rpc_ip or 'om_datacenter' in rpc_ip)):
self._log.error("Mandatory parameters name or nsd_ref or cloud account not found in start-network-service {}".format(rpc_ip))
-
+
self._log.debug("start-network-service RPC input: {}".format(rpc_ip))
try:
# Add used value to the pool
self._log.debug("RPC output: {}".format(rpc_op))
-
+
nsd_copy = self.nsm.get_nsd(rpc_ip.nsd_ref)
#if not self._manager:
# self._manager = yield from self._connect()
-
+
self._log.debug("Configuring ns-instance-config with name %s nsd-ref: %s",
rpc_ip.name, rpc_ip.nsd_ref)
def get_nsr_key_pairs(dts_member_reg, xact):
key_pairs = {}
for instance_cfg, keyspec in dts_member_reg.get_xact_elements(xact, include_keyspec=True):
- self._log.debug("Key pair received is {} KS: {}".format(instance_cfg, keyspec))
+ self._log.debug("Key pair received is {} KS: {}".format(instance_cfg, keyspec))
xpath = keyspec.to_xpath(RwNsrYang.get_schema())
key_pairs[instance_cfg.name] = instance_cfg
- return key_pairs
+ return key_pairs
def on_apply(dts, acg, xact, action, scratch):
"""Apply the configuration"""
# msg.nsr_id_ref,
# msg.scaling_group_name_ref,
# msg.instance_id)
-
+
def nsr_update_cfg(self, nsr_id, msg):
nsr = self._nsrs[nsr_id]
nsr.nsr_cfg_msg= msg
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)
self.create_nsd(nsd)
else:
self._log.debug("Updating NSD id = %s, nsd = %s", nsd.id, nsd)
- self._nsds[nsd.id].update(nsd)
+ self._nsds[nsd.id].update(nsd)
def delete_nsd(self, nsd_id):
""" Delete the Network service descriptor with the passed id """
""" Update the virtual network function descriptor """
self._log.debug("Update virtual network function descriptor- %s", vnfd)
- # Hack to remove duplicates from leaf-lists - to be fixed by RIFT-6511
- for ivld in vnfd.internal_vld:
- ivld.internal_connection_point_ref = list(set(ivld.internal_connection_point_ref))
if vnfd.id not in self._vnfds:
self._log.debug("No VNFD found - creating VNFD id = %s", vnfd.id)