Пример #1
0
    def resmgr_msg(self):
        """ VLR message for this VLR """
        msg = RwResourceMgrYang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData(
        )
        msg.event_id = self.event_id
        msg.cloud_account = self.datacenter
        msg.request_info.name = self.name
        msg.request_info.vim_network_name = self._vlr_msg.vim_network_name
        msg.request_info.provider_network.from_dict(
            self._vlr_msg.provider_network.as_dict())
        if self._vlr_msg.has_field('ip_profile_params'):
            msg.request_info.ip_profile_params.from_dict(
                self._vlr_msg.ip_profile_params.as_dict())

        for cp in self._vlr_msg.virtual_connection_points:
            vcp = msg.request_info.virtual_cps.add()
            vcp.from_dict({
                k: v
                for k, v in cp.as_dict().items()
                if k in ['name', 'port_security_enabled', 'type_yang']
            })
            if (self._vlr_msg.has_field('ip_profile_params')) and (
                    self._vlr_msg.ip_profile_params.has_field('security_group')
            ):
                vcp.security_group = self._vlr_msg.ip_profile_params.security_group

        return msg
Пример #2
0
    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.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData().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)
Пример #3
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)
Пример #4
0
    def get_network_reserve_msg(self, name, cloud_type, xpath):
        event_id = str(uuid.uuid4())
        msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData()
        msg.event_id = event_id
        msg.request_info.name = name
        attributes = ['physical_network', 'name', 'overlay_type', 'segmentation_id']

        for attr in attributes:
            if resource_requests[cloud_type]['network'][name].has_field('provider_network'):
                if resource_requests[cloud_type]['network'][name].provider_network.has_field(attr):
                    setattr(msg.request_info.provider_network, attr,
                            getattr(resource_requests[cloud_type]['network'][name].provider_network ,attr))

        return msg, xpath.format(quoted_key(event_id))
Пример #5
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)