-#
+#
# Copyright 2016 RIFT.IO Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
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:
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,
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
if (vlr.has_field('ip_profile_params')) and (vlr.ip_profile_params.has_field('security_group')):
cp_info['security_group'] = vlr.ip_profile_params.security_group
-
+
cp_list.append(cp_info)
for intf, cp, vlr in self._int_intf:
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
for ivld_msg in self.vnfd.msg.internal_vld:
self._log.debug("Creating internal vld:"
" %s, int_cp_ref = %s",
- ivld_msg, ivld_msg.internal_connection_point_ref
+ ivld_msg, ivld_msg.internal_connection_point
)
vlr = InternalVirtualLinkRecord(dts=self._dts,
log=self._log,
)
self._vlrs.append(vlr)
- for int_cp in ivld_msg.internal_connection_point_ref:
- if int_cp in self._vlr_by_cp:
+ for int_cp in ivld_msg.internal_connection_point:
+ if int_cp.id_ref in self._vlr_by_cp:
msg = ("Connection point %s already "
- " bound %s" % (int_cp, self._vlr_by_cp[int_cp]))
+ " bound %s" % (int_cp.id_ref, self._vlr_by_cp[int_cp.id_ref]))
raise InternalVirtualLinkRecordError(msg)
self._log.debug("Setting vlr %s to internal cp = %s",
- vlr, int_cp)
- self._vlr_by_cp[int_cp] = vlr
+ vlr, int_cp.id_ref)
+ self._vlr_by_cp[int_cp.id_ref] = vlr
@asyncio.coroutine
def instantiate_vls(self, xact, restart_mode=False):
# 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
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 """
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 """
if not vdur._state == VDURecordState.READY:
self._log.debug("VDUR state is not READY. current state is {}".format(vdur._state))
xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK)
- return
+ return
with self._dts.transaction() as new_xact:
resp = yield from vdur.read_resource(new_xact)
vdur_console = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur()
vdur_console = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur()
vdur_console.id = self._vdur_id
vdur_console.console_url = 'none'
-
+
xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK,
xpath=self.vnfr_vdu_console_xpath,
msg=vdur_console)
#raise VnfRecordError("Not supported operation %s" % action)
self._log.error("Not supported operation %s" % action)
xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK)
- return
-
+ return
+
self._log.debug("Registering for VNFR VDU using xpath: %s",
self.vnfr_vdu_console_xpath)
""" 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)
self.create_vnfd(vnfd)