def on_link_request_prepare(xact_info, action, ks_path, request_msg): self._log.debug("Received virtual-link on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VirtualLinkEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = yield from self._parent.allocate_virtual_network(pathentry.key00.event_id, request_msg.cloud_account, request_msg.request_info) request_msg.resource_info = response_info self.create_record_dts(self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema()), request_msg) elif action == rwdts.QueryAction.DELETE: yield from self._parent.release_virtual_network(pathentry.key00.event_id) self.delete_record_dts(self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema())) elif action == rwdts.QueryAction.READ: response_info = yield from self._parent.read_virtual_network_info(pathentry.key00.event_id) else: raise ValueError("Only read/create/delete actions available. Received action: %s" %(action)) self._log.debug("Responding with VirtualLinkInfo at xpath %s: %s.", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def on_link_request_prepare(xact_info, action, ks_path, request_msg): self._log.debug( "Received virtual-link on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: try: response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_ResourceInfo() response_info.resource_state = 'pending' request_msg.resource_info = response_info self.create_record_dts(self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema()), request_msg) asyncio.ensure_future(allocate_vlink_task(ks_path, pathentry.key00.event_id, request_msg.cloud_account, request_msg.request_info), loop = self._loop) except Exception as e: self._log.error( "Encountered exception: %s while creating virtual network", str(e)) self._log.exception(e) response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_ResourceInfo() response_info.resource_state = 'failed' response_info.resource_errors = str(e) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) elif action == rwdts.QueryAction.DELETE: yield from self._parent.release_virtual_network(pathentry.key00.event_id) self.delete_record_dts(self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema())) elif action == rwdts.QueryAction.READ: # TODO: Check why we are getting null event id request if pathentry.key00.event_id: response_info = yield from self._parent.read_virtual_network_info(pathentry.key00.event_id) else: xact_info.respond_xpath(rwdts.XactRspCode.NA) return else: raise ValueError( "Only read/create/delete actions available. Received action: %s" %(action)) self._log.info("Responding with VirtualLinkInfo at xpath %s: %s.", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def on_link_request_prepare(self, xact_info, action, ks_path, request_msg): if not self._registered: self._log.error("Got a prepare callback when not registered!") xact_info.respond_xpath(rwdts.XactRspCode.NA) return self._log.debug("Received virtual-link on_prepare callback (self: %s, xact_info: %s, action: %s): %s", self, xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VirtualLinkEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = self._allocate_virtual_network( pathentry.key00.event_id, request_msg.request_info, ) elif action == rwdts.QueryAction.DELETE: self._release_virtual_network(pathentry.key00.event_id) elif action == rwdts.QueryAction.READ: response_info = self._read_virtual_network( pathentry.key00.event_id ) else: raise ValueError("Only read/create/delete actions available. Received action: %s" %(action)) self._log.debug("Responding with VirtualLinkInfo at xpath %s: %s.", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def allocate_vdu_task(ks_path, event_id, cloud_account, request_msg): response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VDUEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) try: response_info = yield from self._parent.allocate_virtual_compute(event_id, cloud_account, request_msg,) except Exception as e: self._log.error("Encountered exception : %s while creating virtual compute", str(e)) response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() response_info.resource_state = 'failed' yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: if response_info.resource_state == 'failed' or response_info.resource_state == 'active' : self._log.info("Virtual compute create task completed. Publishing VDU info: %s at path: %s", response_info, response_xpath) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: asyncio.ensure_future(monitor_vdu_state(response_xpath, pathentry), loop = self._loop)
def allocate_vdu_task(ks_path, event_id, cloud_account, request_msg): response_xpath = ks_path.to_xpath( RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VDUEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) try: response_info = yield from self._parent.allocate_virtual_compute( event_id, cloud_account, request_msg, ) except Exception as e: self._log.error( "Encountered exception : %s while creating virtual compute", str(e)) response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() response_info.resource_state = 'failed' yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: if response_info.resource_state == 'failed' or response_info.resource_state == 'active': self._log.info( "Virtual compute create task completed. Publishing VDU info: %s at path: %s", response_info, response_xpath) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: asyncio.ensure_future(monitor_vdu_state( response_xpath, pathentry), loop=self._loop)
def allocate_vdu_task(ks_path, event_id, cloud_account, request_msg): response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" response_xpath = self._add_config_flag(response_xpath) schema = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) try: response_info = yield from self._parent.allocate_virtual_compute(event_id, cloud_account, request_msg,) except Exception as e: self._log.error("Encountered exception : %s while creating virtual compute", str(e)) response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_ResourceInfo() response_info.resource_state = 'failed' response_info.resource_errors = str(e) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: cloud_account = self._parent.get_cloud_account_detail(cloud_account) #RIFT-17719 - Set the resource state to active if no floating ip pool specified and is waiting for public ip. if response_info.resource_state == 'pending' and cloud_account.has_field('openstack') \ and not (cloud_account.openstack.has_field('floating_ip_pool')) : if (request_msg.has_field('allocate_public_address')) and (request_msg.allocate_public_address == True): if not response_info.has_field('public_ip'): response_info.resource_state = 'active' if response_info.resource_state == 'failed' or response_info.resource_state == 'active' : self._log.debug("Virtual compute create task completed. Publishing VDU info: %s at path: %s", response_info, response_xpath) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: asyncio.ensure_future(monitor_vdu_state(response_xpath, pathentry.key00.event_id, cloud_account.vdu_instance_timeout), loop = self._loop)
def start(self): super(ResMgrTasklet, self).start() self.log.debug("Starting ResMgrTasklet") self.log.debug("Registering with dts") self._dts = rift.tasklets.DTS(self.tasklet_info, RwResourceMgrYang.get_schema(), self.loop, self.on_dts_state_change) self.log.debug("Created DTS Api GI Object: %s", self._dts)
def on_vdu_request_prepare(xact_info, action, ks_path, request_msg): self._log.debug( "Received vdu on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_xpath = ks_path.to_xpath( RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VDUEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() response_info.resource_state = 'pending' request_msg.resource_info = response_info self.create_record_dts( self._vdu_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema()), request_msg) asyncio.ensure_future(allocate_vdu_task( ks_path, pathentry.key00.event_id, request_msg.cloud_account, request_msg.request_info), loop=self._loop) elif action == rwdts.QueryAction.DELETE: response_info = None yield from self._parent.release_virtual_compute( pathentry.key00.event_id) self.delete_record_dts( self._vdu_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema())) elif action == rwdts.QueryAction.READ: response_info = yield from self._parent.read_virtual_compute_info( pathentry.key00.event_id) else: raise ValueError( "Only create/delete actions available. Received action: %s" % (action)) self._log.debug("Responding with VDUInfo at xpath %s: %s", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def start(self): super(ResMgrTasklet, self).start() self.log.info("Starting ResMgrTasklet") self.log.debug("Registering with dts") self._dts = rift.tasklets.DTS(self.tasklet_info, RwResourceMgrYang.get_schema(), self.loop, self.on_dts_state_change) self.log.debug("Created DTS Api GI Object: %s", self._dts)
def on_link_request_prepare(xact_info, action, ks_path, request_msg): self._log.debug( "Received virtual-link on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath( RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VirtualLinkEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = yield from self._parent.allocate_virtual_network( pathentry.key00.event_id, request_msg.cloud_account, request_msg.request_info) request_msg.resource_info = response_info self.create_record_dts( self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema()), request_msg) elif action == rwdts.QueryAction.DELETE: yield from self._parent.release_virtual_network( pathentry.key00.event_id) self.delete_record_dts( self._link_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema())) elif action == rwdts.QueryAction.READ: response_info = yield from self._parent.read_virtual_network_info( pathentry.key00.event_id) else: raise ValueError( "Only read/create/delete actions available. Received action: %s" % (action)) self._log.debug("Responding with VirtualLinkInfo at xpath %s: %s.", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def on_vdu_request_prepare(xact_info, action, ks_path, request_msg): self._log.debug("Received vdu on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VDUEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() response_info.resource_state = 'pending' request_msg.resource_info = response_info self.create_record_dts(self._vdu_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema()), request_msg) asyncio.ensure_future(allocate_vdu_task(ks_path, pathentry.key00.event_id, request_msg.cloud_account, request_msg.request_info), loop = self._loop) elif action == rwdts.QueryAction.DELETE: yield from self._parent.release_virtual_compute(pathentry.key00.event_id) self.delete_record_dts(self._vdu_reg, None, ks_path.to_xpath(RwResourceMgrYang.get_schema())) elif action == rwdts.QueryAction.READ: response_info = yield from self._parent.read_virtual_compute_info(pathentry.key00.event_id) else: raise ValueError("Only create/delete actions available. Received action: %s" %(action)) self._log.debug("Responding with VDUInfo at xpath %s: %s", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)
def __init__(self, log, loop, launchpad, vm_pool_mgr, network_pool_mgr): self._log = log self._loop = loop self._launchpad = launchpad self._vm_pool_mgr = vm_pool_mgr self._network_pool_mgr = network_pool_mgr self._manager = None self._model = RwYang.Model.create_libncx() self._model.load_schema_ypbc(RwCloudYang.get_schema()) self._model.load_schema_ypbc(RwBaseYang.get_schema()) self._model.load_schema_ypbc(RwResourceMgrYang.get_schema()) self._model.load_schema_ypbc(RwNsmYang.get_schema()) self._model.load_schema_ypbc(RwConmanYang.get_schema()) self._model.load_schema_ypbc(RwLaunchpadYang.get_schema()) self._cloud_account = None
def on_prepare(xact_info, query_action, ks_path, msg): """ prepare callback on Virtual Link Events """ try: self._log.debug( "Got on prepare for Virtual Link Event id (ks_path: %s) (msg: %s)", ks_path.to_xpath(RwResourceMgrYang.get_schema()), msg) event_id = self.event_id_from_keyspec(ks_path) if event_id: if query_action == rwdts.QueryAction.CREATE or query_action == rwdts.QueryAction.UPDATE: yield from self._vnsm.update_virual_link_event( event_id, msg) elif query_action == rwdts.QueryAction.DELETE: self._vnsm.delete_virual_link_event(event_id) except Exception as e: self._log.exception( "Caught execption in Virtual Link Event handler", e) xact_info.respond_xpath(rwdts.XactRspCode.ACK)
def allocate_vlink_task(ks_path, event_id, cloud_account, request_info): response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) try: response_info = yield from self._parent.allocate_virtual_network(pathentry.key00.event_id, cloud_account, request_info) except Exception as e: self._log.error("Encountered exception: %s while creating virtual network", str(e)) self._log.exception(e) response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_ResourceInfo() response_info.resource_state = 'failed' response_info.resource_errors = str(e) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) else: yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info)
def configure_schema(cls): return rmgryang.get_schema()
def configure_schema(cls): return rmgryang.get_schema()
def on_vdu_request_prepare(self, xact_info, action, ks_path, request_msg): if not self._registered: self._log.error("Got a prepare callback when not registered!") xact_info.respond_xpath(rwdts.XactRspCode.NA) return @asyncio.coroutine def monitor_vdu_state(response_xpath, pathentry): self._log.info("Initiating VDU state monitoring for xpath: %s ", response_xpath) loop_cnt = 120 while loop_cnt > 0: self._log.debug("VDU state monitoring: Sleeping for 1 second ") yield from asyncio.sleep(1, loop = self._loop) try: response_info = self._read_virtual_compute( pathentry.key00.event_id ) except Exception as e: self._log.error( "VDU state monitoring: Received exception %s " "in VDU state monitoring for %s. Aborting monitoring", str(e), response_xpath ) raise if response_info.resource_state == 'active' or response_info.resource_state == 'failed': self._log.info( "VDU state monitoring: VDU reached terminal state." "Publishing VDU info: %s at path: %s", response_info, response_xpath ) yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) return else: loop_cnt -= 1 ### End of while loop. This is only possible if VDU did not reach active state self._log.info("VDU state monitoring: VDU at xpath :%s did not reached active state in 120 seconds. Aborting monitoring", response_xpath) response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() response_info.resource_state = 'failed' yield from self._dts.query_update(response_xpath, rwdts.XactFlag.ADVISE, response_info) return self._log.debug("Received vdu on_prepare callback (xact_info: %s, action: %s): %s", xact_info, action, request_msg) response_info = None response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" schema = RwResourceMgrYang.VDUEventData().schema() pathentry = schema.keyspec_to_entry(ks_path) if action == rwdts.QueryAction.CREATE: response_info = self._allocate_virtual_compute( pathentry.key00.event_id, request_msg.request_info, ) if response_info.resource_state == 'pending': asyncio.ensure_future(monitor_vdu_state(response_xpath, pathentry), loop = self._loop) elif action == rwdts.QueryAction.DELETE: self._release_virtual_compute( pathentry.key00.event_id ) elif action == rwdts.QueryAction.READ: response_info = self._read_virtual_compute( pathentry.key00.event_id ) else: raise ValueError("Only create/delete actions available. Received action: %s" %(action)) self._log.debug("Responding with VDUInfo at xpath %s: %s", response_xpath, response_info) xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info)