Exemple #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"
     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)
Exemple #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.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 create_cloudsim_resource_template():
    ### Resource to be reuqested for 'cloudsim'
    resource_requests = {'compute': {}, 'network': {}}

    ###### mycompute-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = "1"
    msg.vm_flavor.vcpu_count = 4
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 40
    resource_requests['compute']['mycompute-0'] = msg

    ###### mycompute-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = "1"
    msg.vm_flavor.vcpu_count = 2
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 20
    resource_requests['compute']['mycompute-1'] = msg

    ####### mynet-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    resource_requests['network']['mynet-0'] = msg

    ####### mynet-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    resource_requests['network']['mynet-1'] = msg

    return resource_requests
def create_openstack_static_template():
    ### Resource to be reuqested for 'openstack_static'
    resource_requests = {'compute': {}, 'network': {}}

    ###### mycompute-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = openstack_info['image_id']
    msg.vm_flavor.vcpu_count = 4
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 80
    resource_requests['compute']['mycompute-0'] = msg

    ###### mycompute-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = openstack_info['image_id']
    msg.vm_flavor.vcpu_count = 2
    msg.vm_flavor.memory_mb = 4096
    msg.vm_flavor.storage_gb = 40
    resource_requests['compute']['mycompute-1'] = msg

    ####### mynet-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    msg.provider_network.physical_network = 'PHYSNET1'
    msg.provider_network.overlay_type = 'VLAN'
    msg.provider_network.segmentation_id = 17
    resource_requests['network']['mynet-0'] = msg

    ####### mynet-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    msg.provider_network.physical_network = 'PHYSNET1'
    msg.provider_network.overlay_type = 'VLAN'
    msg.provider_network.segmentation_id = 18
    resource_requests['network']['mynet-1'] = msg

    return resource_requests
def create_mock_resource_temaplate():
    ### Resource to be reuqested for 'mock'
    resource_requests = {'compute': {}, 'network': {}}

    ###### mycompute-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = str(uuid.uuid3(uuid.NAMESPACE_DNS, 'image-0'))
    msg.vm_flavor.vcpu_count = 4
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 40
    resource_requests['compute']['mycompute-0'] = msg

    ###### mycompute-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = str(uuid.uuid3(uuid.NAMESPACE_DNS, 'image-1'))
    msg.vm_flavor.vcpu_count = 2
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 20
    resource_requests['compute']['mycompute-1'] = msg

    ####### mynet-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    resource_requests['network']['mynet-0'] = msg

    ####### mynet-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    resource_requests['network']['mynet-1'] = msg

    return resource_requests
Exemple #6
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)
Exemple #7
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.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_prepare(xact_info, action, ks_path, msg):
            self._log.debug("ResourceMgr providing resource-pool information")
            msg = RwResourceMgrYang.YangData_RwProject_Project_ResourcePoolRecords(
            )

            cloud_accounts = self._parent.get_cloud_account_names()
            for cloud_account_name in cloud_accounts:
                pools = self._parent.get_pool_list(cloud_account_name)
                self._log.debug(
                    "Publishing information about cloud account %s %d resource pools",
                    cloud_account_name, len(pools))

                cloud_account_msg = msg.cloud_account.add()
                cloud_account_msg.name = cloud_account_name
                for pool in pools:
                    pool_info = self._parent.get_pool_info(
                        cloud_account_name, pool.name)
                    cloud_account_msg.records.append(pool_info)

            xact_info.respond_xpath(
                rwdts.XactRspCode.ACK,
                self._project.add_project(
                    ResourceMgrConfig.XPATH_POOL_OPER_DATA),
                msg=msg,
            )
Exemple #9
0
 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)
Exemple #10
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
Exemple #11
0
 def get_compute_pool_msg(self, name, pool_type, cloud_type):
     pool_config = rmgryang.ResourcePools()
     pool = pool_config.pools.add()
     pool.name = name
     pool.resource_type = "compute"
     if pool_type == "static":
         pool.pool_type = 'static'
         acct = get_cal_account(cloud_type)
         rwcal = create_cal_plugin(acct, self.tinfo.get_rwlog_ctx())
         rc, rsp = rwcal.get_vdu_list(acct)
         assert rc == RwStatus.SUCCESS
         
         if cloud_type == 'openstack_static':
             for vdu in rsp.vdu_info_list:
                 if vdu.name in openstack_info['vms']:
                     self.log.info("Adding the static compute resource: %s to compute pool", vdu.name)
                     r = pool.resources.add()
                     r.resource_id = vdu.vdu_id
         else:
             # 'mock', 'cloudsim' 'openstack_dynamic' etc
             for vdu in rsp.vdu_info_list:
                 self.log.info("Adding the static compute resource: %s to compute pool", vdu.name)
                 r = pool.resources.add()
                 r.resource_id = vdu.vdu_id
     else:
         pool.pool_type = 'dynamic'
         pool.max_size = 10
     return pool_config
 def get_network_pool_msg(self, name, pool_type, cloud_type):
     pool_config = rmgryang.YangData_RwProject_Project_ResourceMgrConfig_ResourcePools()
     pool = pool_config.pools.add()
     pool.name = name
     pool.resource_type = "network"
     if pool_type == "static":
         pool.pool_type = 'static'
         acct = get_cal_account(cloud_type)
         rwcal = create_cal_plugin(acct, self.tinfo.get_rwlog_ctx())
         rc, rsp = rwcal.get_virtual_link_list(acct)
         assert rc == RwStatus.SUCCESS
         if cloud_type == 'openstack_static':
             for vlink in rsp.virtual_link_info_list:
                 if vlink.name in openstack_info['networks']:
                     self.log.info("Adding the static network resource: %s to network pool", vlink.name)
                     r = pool.resources.add()
                     r.resource_id = vlink.virtual_link_id
         else:
             # 'mock', 'cloudsim', 'openstack_dynamic' etc
             for vlink in rsp.virtual_link_info_list:
                 self.log.info("Adding the static network resource: %s to network pool", vlink.name)
                 r = pool.resources.add()
                 r.resource_id = vlink.virtual_link_id
     else:
         pool.pool_type = 'dynamic'
         pool.max_size = 4
     return pool_config
Exemple #13
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
def create_openstack_dynamic_template():
    ### Resource to be reuqested for 'openstack_dynamic'
    resource_requests = {'compute': {}, 'network': {}}

    ###### mycompute-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = openstack_info['image_id']
    msg.vm_flavor.vcpu_count = 2
    msg.vm_flavor.memory_mb = 4096
    msg.vm_flavor.storage_gb = 40
    msg.guest_epa.mempage_size = 'LARGE'
    msg.guest_epa.cpu_pinning_policy = 'DEDICATED'
    msg.allocate_public_address = True

    resource_requests['compute']['mycompute-0'] = msg

    ###### mycompute-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData_RequestInfo()
    msg.image_id  = openstack_info['image_id']
    msg.vm_flavor.vcpu_count = 4
    msg.vm_flavor.memory_mb = 8192
    msg.vm_flavor.storage_gb = 40
    msg.guest_epa.mempage_size = 'LARGE'
    msg.guest_epa.cpu_pinning_policy = 'DEDICATED'
    msg.allocate_public_address = True

    resource_requests['compute']['mycompute-1'] = msg

    ####### mynet-0
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    #msg.provider_network.overlay_type = 'VXLAN'
    #msg.provider_network.segmentation_id = 71

    resource_requests['network']['mynet-0'] = msg

    ####### mynet-1
    msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VlinkEvent_VlinkEventData_RequestInfo()
    #msg.provider_network.overlay_type = 'VXLAN'
    #msg.provider_network.segmentation_id = 73
    resource_requests['network']['mynet-1'] = msg

    return resource_requests
Exemple #15
0
 def monitor_vdu_state(response_xpath, pathentry):
     self._log.info("Initiating VDU state monitoring for xpath: %s ",
                    response_xpath)
     loop_cnt = 180
     for i in range(loop_cnt):
         self._log.debug(
             "VDU state monitoring for xpath: %s. Sleeping for 1 second",
             response_xpath)
         yield from asyncio.sleep(1, loop=self._loop)
         try:
             response_info = yield from self._parent.read_virtual_compute_info(
                 pathentry.key00.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.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 == '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
         self._log.info(
             "VDU state monitoring: VDU at xpath :{} did not reached active state in {} seconds. Aborting monitoring"
             .format(response_xpath, loop_cnt))
         response_info = RwResourceMgrYang.VDUEventData_ResourceInfo()
         response_info.resource_state = 'failed'
         yield from self._dts.query_update(response_xpath,
                                           rwdts.XactFlag.ADVISE,
                                           response_info)
     return
Exemple #16
0
    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)
Exemple #17
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"
            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)
Exemple #19
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)
Exemple #20
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.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 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))
Exemple #22
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_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)
Exemple #23
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)
Exemple #24
0
    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
Exemple #25
0
        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)
Exemple #26
0
        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
    def get_compute_reserve_msg(self, name, cloud_type, xpath, vlinks):
        event_id = str(uuid.uuid4())
        msg = rmgryang.YangData_RwProject_Project_ResourceMgmt_VduEvent_VduEventData()
        msg.event_id = event_id
        msg.request_info.name = name
        msg.request_info.image_id = resource_requests[cloud_type]['compute'][name].image_id
        attributes = ['image_id', 'vcpu_count', 'memory_mb', 'storage_gb']

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

        attributes = ['mempage_size', 'cpu_pinning_policy']

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

        if resource_requests[cloud_type]['compute'][name].has_field('allocate_public_address'):
            msg.request_info.allocate_public_address = resource_requests[cloud_type]['compute'][name].allocate_public_address

        cnt = 0
        for link in vlinks:
            c1 = msg.request_info.connection_points.add()
            c1.name = name+"-port-"+str(cnt)
            cnt += 1
            c1.virtual_link_id = link

        self.log.info("Sending message :%s", msg)
        return msg, xpath.format(quoted_key(event_id))
Exemple #28
0
 def configure_schema(cls):
     return rmgryang.get_schema()
Exemple #29
0
    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)
 def configure_schema(cls):
     return rmgryang.get_schema()