Exemple #1
0
    def __init__(self, log, loop, dts, ping_pong, cloud_account_name):
        self.dts = dts
        self.log = log
        self.loop = loop
        self.ref = None

        self.nsr_config = rwnsryang.YangData_Nsr_NsInstanceConfig()

        nsr = rwnsryang.YangData_Nsr_NsInstanceConfig_Nsr()
        nsr.id = str(uuid.uuid4())
        nsr.name = "ns1.{}".format(nsr.id)
        nsr.nsd_ref = ping_pong.nsd_id
        nsr.cloud_account = cloud_account_name

        inputs = nsryang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter()
        inputs.xpath = "/nsd:nsd-catalog/nsd:nsd[nsd:id={}]/nsd:name".format(
            ping_pong.nsd_id)
        inputs.value = "inigo montoya"

        fast_cpu = {'metadata_key': 'FASTCPU', 'metadata_value': 'True'}
        self.create_nsd_placement_group_map(nsr,
                                            group_name='Orcus',
                                            cloud_type='openstack',
                                            construct_type='host_aggregate',
                                            construct_value=[fast_cpu])

        fast_storage = {'metadata_key': 'FASTSSD', 'metadata_value': 'True'}
        self.create_nsd_placement_group_map(nsr,
                                            group_name='Quaoar',
                                            cloud_type='openstack',
                                            construct_type='host_aggregate',
                                            construct_value=[fast_storage])

        fast_cpu = {'metadata_key': 'BLUE_HW', 'metadata_value': 'True'}
        self.create_vnfd_placement_group_map(nsr,
                                             group_name='Eris',
                                             vnfd_id=ping_pong.ping_vnfd_id,
                                             cloud_type='openstack',
                                             construct_type='host_aggregate',
                                             construct_value=[fast_cpu])

        fast_storage = {'metadata_key': 'YELLOW_HW', 'metadata_value': 'True'}
        self.create_vnfd_placement_group_map(nsr,
                                             group_name='Weywot',
                                             vnfd_id=ping_pong.pong_vnfd_id,
                                             cloud_type='openstack',
                                             construct_type='host_aggregate',
                                             construct_value=[fast_storage])

        nsr.input_parameter.append(inputs)

        self._nsr = nsr
        self.nsr_config.nsr.append(nsr)

        self._ready_event = asyncio.Event(loop=self.loop)
        asyncio.ensure_future(self.register(), loop=loop)
        def on_prepare(xact_info, action, ks_path, msg):
            """ prepare callback from dts """
            xpath = ks_path.to_xpath(RwNsrYang.get_schema())
            if action == rwdts.QueryAction.READ:
                schema = RwNsrYang.YangData_RwProject_Project_NsInstanceOpdata_Nsr.schema(
                )
                path_entry = schema.keyspec_to_entry(ks_path)
                try:
                    nsr_id = path_entry.key00.ns_instance_config_ref

                    #print("###>>> self.nsm.nsrs:", self.nsm.nsrs)
                    nsr_ids = []
                    if nsr_id is None or nsr_id == "":
                        nsrs = list(self.nsm.nsrs.values())
                        nsr_ids = [nsr.id for nsr in nsrs if nsr is not None]
                    else:
                        nsr_ids = [nsr_id]

                    for nsr_id in nsr_ids:
                        jobs = self.cfgm.get_job(nsr_id)

                        for job in jobs:
                            xact_info.respond_xpath(
                                rwdts.XactRspCode.MORE,
                                self.cfg_job_xpath(nsr_id, job.id), job.job)

                except Exception as e:
                    self._log.exception("Caught exception:%s", str(e))
                xact_info.respond_xpath(rwdts.XactRspCode.ACK)

            else:
                xact_info.respond_xpath(rwdts.XactRspCode.NA)
Exemple #3
0
        def on_prepare(xact_info, action, ks_path, msg):
            """ prepare callback from dts """
            xpath = ks_path.to_xpath(RwNsrYang.get_schema())
            if action == rwdts.QueryAction.READ:
                schema = RwNsrYang.YangData_Nsr_NsInstanceOpdata_Nsr.schema()
                path_entry = schema.keyspec_to_entry(ks_path)
                try:
                    nsr_id = path_entry.key00.ns_instance_config_ref

                    nsr_ids = []
                    if nsr_id is None or nsr_id == "":
                        nsrs = list(self.nsm.nsrs.values())
                        nsr_ids = [nsr.id for nsr in nsrs]
                    else:
                        nsr_ids = [nsr_id]

                    for nsr_id in nsr_ids:
                        job = self.cfgm.get_job(nsr_id)

                        # If no jobs are queued for the NSR
                        if job is None:
                            continue

                        xact_info.respond_xpath(
                            rwdts.XactRspCode.MORE,
                            CfgAgentJobDtsHandler.cfg_job_xpath(nsr_id, job.job_id),
                            job)

                except Exception as e:
                    self._log.exception("Caught exception:", str(e))
                xact_info.respond_xpath(rwdts.XactRspCode.ACK)

            else:
                xact_info.respond_xpath(rwdts.XactRspCode.NA)
    def test_nsr_handler(self):
        yield from self.store.register()

        mock_nsr = RwNsrYang.YangData_RwProject_Project_NsInstanceOpdata_Nsr()
        mock_nsr.ns_instance_config_ref = str(uuid.uuid1())
        mock_nsr.name_ref = "Foo"

        w_xpath = "D,/rw-project:project/nsr:ns-instance-opdata/nsr:nsr"
        xpath = "{}[nsr:ns-instance-config-ref={}]".format(
            w_xpath, quoted_key(mock_nsr.ns_instance_config_ref))
        yield from self.publisher.publish(w_xpath, xpath, mock_nsr)

        yield from asyncio.sleep(5, loop=self.loop)
        assert len(self.store.nsr) == 1
        assert self.store.get_nsr(
            self.store.nsr[0].ns_instance_config_ref) is not None

        yield from self.dts.query_update(xpath, rwdts.XactFlag.ADVISE,
                                         mock_nsr)
        yield from asyncio.sleep(5, loop=self.loop)
        assert len(self.store.nsr) == 1

        yield from self.dts.query_delete(xpath, flags=rwdts.XactFlag.ADVISE)
        yield from asyncio.sleep(5, loop=self.loop)
        assert len(self.store.nsr) == 0
def create_nsr_from_nsd_id(nsd_id):
    nsr = RwNsrYang.YangData_Nsr_NsInstanceConfig_Nsr()
    nsr.id = str(uuid.uuid4())
    nsr.name = "nsr_name"
    nsr.short_name = "nsr_short_name"
    nsr.description = "This is a description"
    nsr.nsd_ref = nsd_id
    nsr.admin_status = "ENABLED"
    nsr.cloud_account = "cloud_account_name"

    return nsr
Exemple #6
0
def create_nsr_from_nsd_id(nsd_id):
    nsr = RwNsrYang.YangData_Nsr_NsInstanceConfig_Nsr()
    nsr.id = str(uuid.uuid4())
    nsr.name = "pingpong_{}".format(datetime.datetime.now().strftime("%Y%m%d_%H%M%S"))
    nsr.short_name = "nsr_short_name"
    nsr.description = "This is a description"
    nsr.nsd_ref = nsd_id
    nsr.admin_status = "ENABLED"
    nsr.cloud_account = "openstack"

    param = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter()
    param.xpath = '/nsd:nsd-catalog/nsd:nsd/nsd:vendor'
    param.value = "rift-o-matic"

    nsr.input_parameter.append(param)

    return nsr
def create_nsr(nsd_id, input_param_list, cloud_account_name):
    """
    Create the NSR record object

    Arguments:
         nsd_id             -  NSD id
         input_param_list - list of input-parameter objects

    Return:
         NSR object
    """
    nsr = RwNsrYang.YangData_Nsr_NsInstanceConfig_Nsr()

    nsr.id = str(uuid.uuid4())
    nsr.name = rift.auto.mano.resource_name(nsr.id)
    nsr.short_name = "nsr_short_name"
    nsr.description = "This is a description"
    nsr.nsd_ref = nsd_id
    nsr.admin_status = "ENABLED"
    nsr.input_parameter.extend(input_param_list)
    nsr.cloud_account = cloud_account_name

    return nsr