Пример #1
0
        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)
Пример #2
0
 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)