Exemplo n.º 1
0
        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)
Exemplo n.º 2
0
        def monitor_vdu_state(response_xpath, event_id, vdu_timeout):
            self._log.info("Initiating VDU state monitoring for xpath: %s ", response_xpath)
            sleep_time = 2
            loop_cnt = int(vdu_timeout/sleep_time)

            for i in range(loop_cnt):
                self._log.debug(
                    "VDU state monitoring for xpath: %s. Sleeping for 2 second", response_xpath)
                yield from asyncio.sleep(2, loop = self._loop)

                try:
                    response_info = yield from self._parent.read_virtual_compute_info(event_id)
                except Exception as e:
                    self._log.info(
                        "VDU state monitoring: Received exception %s in VDU state monitoring for %s. Aborting monitoring", str(e),response_xpath)

                    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:
                    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:
                ### End of loop. This is only possible if VDU did not reach active state
                err_msg = ("VDU state monitoring: VDU at xpath :{} did not reached active " +
                           "state in {} seconds. Aborting monitoring".
                           format(response_xpath, time_to_wait))
                self._log.info(err_msg)
                response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_ResourceInfo()
                response_info.resource_state = 'failed'
                response_info.resource_errors = err_msg
                yield from self._dts.query_update(response_xpath,
                                                  rwdts.XactFlag.ADVISE,
                                                  response_info)
            return
Exemplo n.º 3
0
        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"
            response_xpath = self._add_config_flag(response_xpath)
            schema = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData().schema()
            pathentry = schema.keyspec_to_entry(ks_path)

            if action == rwdts.QueryAction.CREATE:
                response_info = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VduEvent_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:
                # TODO: Check why we are getting null event id request
                if pathentry.key00.event_id:
                    response_info = yield from self._parent.read_virtual_compute_info(pathentry.key00.event_id)
                else:
                    xact_info.respond_xpath(rwdts.XactRspCode.NA)
                    return
            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)
Exemplo n.º 4
0
        def monitor_vdu_state(response_xpath, event_id):
            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(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.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_ResourceInfo()
            response_info.resource_state = 'failed'
            yield from self._dts.query_update(response_xpath,
                                              rwdts.XactFlag.ADVISE,
                                              response_info)
            return