def generate_nsr(name, nsd_ref, short_name="test short name", description="test description", admin_status="ENABLED", nsr_id=None): ''' A helper method for generating an NSR Arguments: name - name of the nsr being generated nsd_ref - reference to the nsd this NSR is an instance of short_name - short name of the nsr being generated description - description of the nsr being generated admin_status - flag indicating NSR admin status (enabled/disabled) nsr_id - unique identifier of this NSR ''' nsr = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr.name = rift.auto.mano.resource_name(name) nsr.nsd_ref = nsd_ref nsr.short_name = short_name nsr.description = description nsr.admin_status = "ENABLED" if nsr_id: nsr.id = nsr_id else: nsr.id = str(uuid.uuid4()) return nsr
def start(self): super().start() self.log.info("Starting MonitoringParameterTasklet") self.log.debug("Registering with dts") self.dts = rift.tasklets.DTS(self.tasklet_info, NsrYang.get_schema(), self.loop, self.on_dts_state_change)
def test_instantiate_multi_vm_vnf_nsr(self, logger, nsd_proxy, nsr_proxy, rwnsr_proxy, base_proxy, cloud_account_name): def verify_input_parameters(running_config, config_param): """ Verify the configured parameter set against the running configuration """ for run_input_param in running_config.input_parameter: if (input_param.xpath == config_param.xpath and input_param.value == config_param.value): return True assert False, ( "Verification of configured input parameters: { xpath:%s, value:%s} " "is unsuccessful.\nRunning configuration: %s" % (config_param.xpath, config_param.value, running_nsr_config.input_parameter)) catalog = nsd_proxy.get_config( '/rw-project:project[rw-project:name="default"]/nsd-catalog') nsd = catalog.nsd[0] input_parameters = [] descr_xpath = "/rw-project:project/project-nsd:nsd-catalog/project-nsd:nsd[project-nsd:id=%s]/project-nsd:description" % quoted_key( nsd.id) descr_value = "New NSD Description" in_param_id = str(uuid.uuid4()) input_param_1 = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter( xpath=descr_xpath, value=descr_value) input_parameters.append(input_param_1) nsr = create_nsr(nsd.id, input_parameters, cloud_account_name) logger.info("Instantiating the Network Service") rwnsr_proxy.create_config( '/rw-project:project[rw-project:name="default"]/ns-instance-config/nsr', nsr) nsr_opdata = rwnsr_proxy.get( '/rw-project:project[rw-project:name="default"]/ns-instance-opdata' ) nsrs = nsr_opdata.nsr # Verify the input parameter configuration running_config = rwnsr_proxy.get_config( "/rw-project:project[rw-project:name='default']/ns-instance-config/nsr[id=%s]" % quoted_key(nsr.id)) for input_param in input_parameters: verify_input_parameters(running_config, input_param) assert len(nsrs) == 1 assert nsrs[0].ns_instance_config_ref == nsr.id xpath = "/rw-project:project[rw-project:name='default']/ns-instance-opdata/nsr[ns-instance-config-ref={}]/operational-status".format( quoted_key(nsr.id)) rwnsr_proxy.wait_for(xpath, "running", fail_on=['failed'], timeout=360)
def create_record_msg(self): """ Returns a NSR Scaling group record """ msg = NsrYang.YangData_RwProject_Project_NsInstanceOpdata_Nsr_ScalingGroupRecord( scaling_group_name_ref=self.name, ) for instance in self.instances: msg.instance.append(instance.create_record_msg()) return msg
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 create_nsr_from_nsd_id(nsd_id): nsr = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr() nsr.id = str(uuid.uuid4()) nsr.name = "TG-2Vrouter-TS EPA" nsr.short_name = "TG-2Vrouter-TS EPA" nsr.description = "4 VNFs with Trafgen, 2 Vrouters and Trafsink EPA" nsr.nsd_ref = nsd_id nsr.admin_status = "ENABLED" return nsr
def create_nsr_from_nsd_id(nsd_id): nsr = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr.id = str(uuid.uuid4()) nsr.name = "TG-Vrouter-TS-EPA-SRIOV" nsr.short_name = "TG-Vrouter-TS-EPA-SRIOV" nsr.description = "3 VNFs with Trafgen, Vrouter and Trafsink EPA SRIOV" nsr.nsd_ref = nsd_id nsr.admin_status = "ENABLED" return nsr
def create_nsr_from_nsd_id(nsd_id): nsr = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr() nsr.id = str(uuid.uuid4()) nsr.name = "UTM-only" nsr.short_name = "UTM-only" nsr.description = "1 VNFs with 5 VLs" nsr.nsd_ref = nsd_id nsr.admin_status = "ENABLED" return nsr
def test_substitution(self): """ Test that substitution of input parameters occurs as expected. """ # Define the original NSD nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd() nsd.name = "robert" nsd.short_name = "bob" # Define which parameters may be modified nsd.input_parameter_xpath.extend([ NsdYang.YangData_Nsd_NsdCatalog_Nsd_InputParameterXpath( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name", label="NSD Name", ), NsdYang.YangData_Nsd_NsdCatalog_Nsd_InputParameterXpath( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name", label="NSD Short Name", ), ]) # Define the input parameters that are intended to be modified nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() nsr_config.input_parameter.extend([ NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name", value="robert", ), NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name", value="bob", ), ]) self.substitute_input_parameters(nsd, nsr_config) # Verify that both the 'name' and 'short-name' fields are correctly # replaced. self.assertEqual("robert", nsd.name) self.assertEqual("bob", nsd.short_name)
def test_instantiate_nsr(self, logger, nsd_proxy, rwnsr_proxy, base_proxy, cloud_account_name): def verify_input_parameters(running_config, config_param): """ Verify the configured parameter set against the running configuration """ for run_input_param in running_config.input_parameter: if (run_input_param.xpath == config_param.xpath and run_input_param.value == config_param.value): return True assert False, ( "Verification of configured input parameters: { xpath:%s, value:%s} " "is unsuccessful.\nRunning configuration: %s" % (config_param.xpath, config_param.value, running_config.input_parameter)) catalog = nsd_proxy.get_config( '/rw-project:project[rw-project:name="default"]/nsd-catalog') nsd = catalog.nsd[0] input_parameters = [] descr_xpath = "/nsd:nsd-catalog/nsd:nsd/nsd:vendor" descr_value = "New Vendor" in_param_id = str(uuid.uuid4()) input_param_1 = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter( xpath=descr_xpath, value=descr_value) input_parameters.append(input_param_1) nsr = rift.auto.descriptor.create_nsr( cloud_account_name, nsd.name, nsd, input_param_list=input_parameters) logger.info("Instantiating the Network Service") rwnsr_proxy.create_config( '/rw-project:project[rw-project:name="default"]/ns-instance-config/nsr', nsr) nsr_opdata = rwnsr_proxy.get( '/rw-project:project[rw-project:name="default"]/ns-instance-opdata/nsr[ns-instance-config-ref={}]' .format(quoted_key(nsr.id))) assert nsr_opdata is not None # Verify the input parameter configuration running_config = rwnsr_proxy.get_config( "/rw-project:project[rw-project:name='default']/ns-instance-config/nsr[id=%s]" % quoted_key(nsr.id)) for input_param in input_parameters: verify_input_parameters(running_config, input_param)
def test_null_arguments(self): """ If None is passed to the substitutor for either the NSD or the NSR config, no exception should be raised. """ nsd = NsdYang.YangData_Nsd_NsdCatalog_Nsd() nsr_config = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr() self.substitute_input_parameters(None, None) self.substitute_input_parameters(nsd, None) self.substitute_input_parameters(None, nsr_config)
def test_illegal_input_parameter(self): """ In the NSD there is a list of the parameters that are allowed to be sbustituted by input parameters. This test checks that when an input parameter is provided in the NSR config that is not in the NSD, it is not applied. """ # Define the original NSD nsd = ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd() nsd.name = "robert" nsd.short_name = "bob" # Define which parameters may be modified nsd.input_parameter_xpath.append( ProjectNsdYang.YangData_RwProject_Project_NsdCatalog_Nsd_InputParameterXpath( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name", label="NSD Name", ) ) # Define the input parameters that are intended to be modified nsr_config = NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr() nsr_config.input_parameter.extend([ NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:name", value="alice", ), NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr_InputParameter( xpath="/nsd:nsd-catalog/nsd:nsd/nsd:short-name", value="alice", ), ]) self.substitute_input_parameters(nsd, nsr_config) # Verify that only the parameter in the input_parameter_xpath list is # modified after the input parameters have been applied. self.assertEqual("alice", nsd.name) self.assertEqual("bob", nsd.short_name)
def create_record_msg(self): msg = NsrYang.YangData_RwProject_Project_NsInstanceOpdata_Nsr_ScalingGroupRecord_Instance( instance_id=self._instance_id, create_time=self._create_time, op_status=self._op_status, config_status=self._config_status, error_msg=self._config_err_msg, is_default=self._is_default) for vnfr in self.vnfrs: msg.vnfrs.append(vnfr.id) return msg
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 test_instantiate_nsr(self, logger, nsd_proxy, rwnsr_proxy, base_proxy, cloud_account_name): def verify_input_parameters(running_config, config_param): """ Verify the configured parameter set against the running configuration """ for run_input_param in running_config.input_parameter: if (run_input_param.xpath == config_param.xpath and run_input_param.value == config_param.value): return True assert False, ("Verification of configured input parameters: { xpath:%s, value:%s} " "is unsuccessful.\nRunning configuration: %s" % (config_param.xpath, config_param.value, running_config.input_parameter)) catalog = nsd_proxy.get_config('/nsd-catalog') nsd = catalog.nsd[0] input_parameters = [] descr_xpath = "/nsd:nsd-catalog/nsd:nsd[nsd:id='%s']/nsd:description" % nsd.id descr_value = "New NSD Description" in_param_id = str(uuid.uuid4()) input_param_1 = NsrYang.YangData_Nsr_NsInstanceConfig_Nsr_InputParameter( xpath=descr_xpath, value=descr_value) input_parameters.append(input_param_1) nsr = create_nsr(nsd.id, input_parameters, cloud_account_name) logger.info("Instantiating the Network Service") rwnsr_proxy.create_config('/ns-instance-config/nsr', nsr) nsr_opdata = rwnsr_proxy.get('/ns-instance-opdata/nsr[ns-instance-config-ref="{}"]'.format(nsr.id)) assert nsr_opdata is not None # Verify the input parameter configuration running_config = rwnsr_proxy.get_config("/ns-instance-config/nsr[id='%s']" % nsr.id) for input_param in input_parameters: verify_input_parameters(running_config, input_param)
def on_prepare(dts, acg, xact, xact_info, ks_path, msg): """ Prepare calllback from DTS for NSR """ xpath = ks_path.to_xpath(NsrYang.get_schema()) action = xact_info.query_action self._log.debug( "Got Nsr prepare callback (xact: %s) (action: %s) (info: %s), %s:%s)", xact, action, xact_info, xpath, msg ) fref = ProtobufC.FieldReference.alloc() fref.goto_whole_message(msg.to_pbcm()) if action in [rwdts.QueryAction.CREATE, rwdts.QueryAction.UPDATE]: pass # Ensure the Cloud account has been specified if this is an NSR create #if msg.id not in self._nsm.nsrs: # if not msg.has_field("cloud_account"): # raise NsrInstantiationFailed("Cloud account not specified in NSR") # We do not allow scaling actions to occur if the NS is not in running state #elif msg.has_field("scaling_group"): # nsr = self._nsm.nsrs[msg.id] # if nsr.state != NetworkServiceRecordState.RUNNING: # raise ScalingOperationError("Unable to perform scaling action when NS is not in running state") # if len(msg.scaling_group) > 1: # raise ScalingOperationError("Only a single scaling group can be configured at a time") # for group_msg in msg.scaling_group: # num_new_group_instances = len(group_msg.instance) # if num_new_group_instances > 1: # raise ScalingOperationError("Only a single scaling instance can be created at a time") # elif num_new_group_instances == 1: # scale_group = nsr.scaling_groups[group_msg.scaling_group_name_ref] # if len(scale_group.instances) == scale_group.max_instance_count: # raise ScalingOperationError("Max instances for %s reached" % scale_group) acg.handle.prepare_complete_ok(xact_info.handle)
def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch): """ Prepare calllback from DTS for NSR """ xpath = ks_path.to_xpath(NsrYang.get_schema()) action = xact_info.query_action self._log.debug( "Got Nsr prepare callback (xact: %s) (action: %s) (info: %s), %s:%s)", xact, action, xact_info, xpath, msg) fref = ProtobufC.FieldReference.alloc() fref.goto_whole_message(msg.to_pbcm()) if action in [rwdts.QueryAction.CREATE, rwdts.QueryAction.UPDATE]: pass # Ensure the Cloud account has been specified if this is an NSR create #if msg.id not in self._nsm.nsrs: # if not msg.has_field("cloud_account"): # raise NsrInstantiationFailed("Cloud account not specified in NSR") # We do not allow scaling actions to occur if the NS is not in running state #elif msg.has_field("scaling_group"): # nsr = self._nsm.nsrs[msg.id] # if nsr.state != NetworkServiceRecordState.RUNNING: # raise ScalingOperationError("Unable to perform scaling action when NS is not in running state") # if len(msg.scaling_group) > 1: # raise ScalingOperationError("Only a single scaling group can be configured at a time") # for group_msg in msg.scaling_group: # num_new_group_instances = len(group_msg.instance) # if num_new_group_instances > 1: # raise ScalingOperationError("Only a single scaling instance can be created at a time") # elif num_new_group_instances == 1: # scale_group = nsr.scaling_groups[group_msg.scaling_group_name_ref] # if len(scale_group.instances) == scale_group.max_instance_count: # raise ScalingOperationError("Max instances for %s reached" % scale_group) acg.handle.prepare_complete_ok(xact_info.handle)
def configure_schema(cls): return NsrYang.get_schema()
def on_get_ns_config_values_prepare(xact_info, action, ks_path, msg): assert action == rwdts.QueryAction.RPC if not self._project.rpc_check(msg, xact_info): return nsr_id = msg.nsr_id_ref cfg_prim_name = msg.name try: nsr = self._nsm.nsrs[nsr_id] rpc_op = NsrYang.YangOutput_Nsr_GetNsServicePrimitiveValues() ns_cfg_prim_msg = yield from self._get_ns_cfg_primitive( nsr_id, cfg_prim_name) # Get pool values for NS-level parameters for ns_param in ns_cfg_prim_msg.parameter: if not ns_param.has_field("parameter_pool"): continue try: nsr_param_pool = nsr.param_pools[ ns_param.parameter_pool] except KeyError: raise ValueError( "Parameter pool %s does not exist in nsr" % ns_param.parameter_pool) new_ns_param = rpc_op.ns_parameter.add() new_ns_param.name = ns_param.name new_ns_param.value = str( nsr_param_pool.get_next_unused_value()) # Get pool values for NS-level parameters for vnf_prim_group in ns_cfg_prim_msg.vnf_primitive_group: rsp_prim_group = rpc_op.vnf_primitive_group.add() rsp_prim_group.member_vnf_index_ref = vnf_prim_group.member_vnf_index_ref if vnf_prim_group.has_field("vnfd_id_ref"): rsp_prim_group.vnfd_id_ref = vnf_prim_group.vnfd_id_ref for index, vnf_prim in enumerate(vnf_prim_group.primitive): rsp_prim = rsp_prim_group.primitive.add() rsp_prim.name = vnf_prim.name rsp_prim.index = index vnf_primitive = yield from self._get_vnf_primitive( vnf_prim_group.vnfd_id_ref, nsr_id, vnf_prim.name) for param in vnf_primitive.parameter: if not param.has_field("parameter_pool"): continue # Get pool values for NS-level parameters for ns_param in ns_cfg_prim_msg.parameter: if not ns_param.has_field("parameter_pool"): continue try: nsr_param_pool = nsr.param_pools[ ns_param.parameter_pool] except KeyError: raise ValueError( "Parameter pool %s does not exist in nsr" % ns_param.parameter_pool) new_ns_param = rpc_op.ns_parameter.add() new_ns_param.name = ns_param.name new_ns_param.value = str( nsr_param_pool.get_next_unused_value()) # Get pool values for NS-level parameters for vnf_prim_group in ns_cfg_prim_msg.vnf_primitive_group: rsp_prim_group = rpc_op.vnf_primitive_group.add() rsp_prim_group.member_vnf_index_ref = vnf_prim_group.member_vnf_index_ref if vnf_prim_group.has_field("vnfd_id_ref"): rsp_prim_group.vnfd_id_ref = vnf_prim_group.vnfd_id_ref for index, vnf_prim in enumerate(vnf_prim_group.primitive): rsp_prim = rsp_prim_group.primitive.add() rsp_prim.name = vnf_prim.name rsp_prim.index = index vnf_primitive = yield from self._get_vnf_primitive( nsr_id, vnf_prim_group.member_vnf_index_ref, vnf_prim.name) for param in vnf_primitive.parameter: if not param.has_field("parameter_pool"): continue try: nsr_param_pool = nsr.param_pools[ param.parameter_pool] except KeyError: raise ValueError( "Parameter pool %s does not exist in nsr" % vnf_prim.parameter_pool) vnf_param = rsp_prim.parameter.add() vnf_param.name = param.name vnf_param.value = str( nsr_param_pool.get_next_unused_value()) self._log.debug("RPC output: {}".format(rpc_op)) xact_info.respond_xpath(rwdts.XactRspCode.ACK, RiftCMRPCHandler.GET_NS_CONF_O_XPATH, rpc_op) except Exception as e: self._log.error( "Exception processing the " "get-ns-service-primitive-values: {}".format(e)) self._log.exception(e) xact_info.respond_xpath(rwdts.XactRspCode.NACK, RiftCMRPCHandler.GET_NS_CONF_O_XPATH)
def test_add_delete_ns(self): nsr1_uuid = "nsr1_uuid" # str(uuid.uuid4()) nsr2_uuid = "nsr2_uuid" # str(uuid.uuid4()) assert nsr1_uuid != nsr2_uuid yield from self.handler.register() yield from asyncio.sleep(.5, loop=self.loop) self.log.debug("Creating NSR") with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_update( XPaths.nsr_config(nsr1_uuid), NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr( id=nsr1_uuid, name="fu"), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_update( XPaths.scaling_group_instance(nsr1_uuid, "group", 1234), NsrYang. YangData_RwProject_Project_NsInstanceConfig_Nsr_ScalingGroup_Instance( id=1234), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_delete( XPaths.scaling_group_instance(nsr1_uuid, "group", 1234), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_create( XPaths.scaling_group_instance(nsr1_uuid, "group", 12345), NsrYang. YangData_RwProject_Project_NsInstanceConfig_Nsr_ScalingGroup_Instance( id=12345), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) group_ids = self.handler.get_scale_group_instances(nsr2_uuid, "group") self.log.debug("Got group ids in nsr2 after adding 12345 to nsr1: %s", group_ids) group_ids = self.handler.get_scale_group_instances(nsr1_uuid, "group") self.log.debug("Got group ids in nsr1 after adding 12345 to nsr1: %s", group_ids) assert group_ids == {12345} self.log.debug("\n\nADD A COMPLETELY DIFFERENT NSR\n") with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_update( XPaths.nsr_config(nsr2_uuid), NsrYang.YangData_RwProject_Project_NsInstanceConfig_Nsr( id=nsr2_uuid, name="fu2"), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) group_ids = self.handler.get_scale_group_instances(nsr2_uuid, "group") self.log.debug("Got group ids in nsr2 after adding new nsr: %s", group_ids) group_ids = self.handler.get_scale_group_instances(nsr1_uuid, "group") self.log.debug("Got group ids in nsr1 after adding new nsr: %s", group_ids) assert group_ids == {12345} self.log.debug("\n\nDELETE A COMPLETELY DIFFERENT NSR\n") with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_delete( XPaths.nsr_config(nsr2_uuid), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(.5, loop=self.loop) group_ids = self.handler.get_scale_group_instances(nsr2_uuid, "group") self.log.debug("Got group ids in nsr2 after deleting nsr2: %s", group_ids) group_ids = self.handler.get_scale_group_instances(nsr1_uuid, "group") self.log.debug("Got group ids in nsr1 after deleting nsr2: %s", group_ids) assert group_ids == {12345} with self.dts_c.transaction() as xact: block = xact.block_create() block.add_query_delete( XPaths.scaling_group_instance(nsr1_uuid, "group", 12345), flags=rwdts.XactFlag.ADVISE | rwdts.XactFlag.TRACE, ) yield from block.execute(now=True) yield from asyncio.sleep(2, loop=self.loop)
def on_ns_config_prepare(xact_info, action, ks_path, msg): """ prepare callback from dts exec-ns-config-primitive""" assert action == rwdts.QueryAction.RPC rpc_ip = msg rpc_op = NsrYang.YangOutput_Nsr_ExecNsConfigPrimitive() try: ns_cfg_prim_name = rpc_ip.name nsr_id = rpc_ip.nsr_id_ref nsr = self._nsm.nsrs[nsr_id] nsd_cfg_prim_msg = yield from self._get_ns_cfg_primitive( nsr_id, ns_cfg_prim_name) def find_nsd_vnf_prim_param_pool(vnf_index, vnf_prim_name, param_name): for vnf_prim_group in nsd_cfg_prim_msg.vnf_primitive_group: if vnf_prim_group.member_vnf_index_ref != vnf_index: continue for vnf_prim in vnf_prim_group.primitive: if vnf_prim.name != vnf_prim_name: continue try: nsr_param_pool = nsr.param_pools[ pool_param.parameter_pool] except KeyError: raise ValueError( "Parameter pool %s does not exist in nsr" % vnf_prim.parameter_pool) self._log.debug( "Found parameter pool %s for vnf index(%s), vnf_prim_name(%s), param_name(%s)", nsr_param_pool, vnf_index, vnf_prim_name, param_name) return nsr_param_pool self._log.debug( "Could not find parameter pool for vnf index(%s), vnf_prim_name(%s), param_name(%s)", vnf_index, vnf_prim_name, param_name) return None rpc_op.nsr_id_ref = nsr_id rpc_op.name = ns_cfg_prim_name nsr, vnfrs = self.prepare_meta(rpc_ip) rpc_op.job_id = nsr.job_id # Give preference to user defined script. if nsd_cfg_prim_msg and nsd_cfg_prim_msg.has_field( "user_defined_script"): rpc_ip.user_defined_script = nsd_cfg_prim_msg.user_defined_script tasks = [] for config_plugin in self.nsm.config_agent_plugins: task = yield from config_plugin.apply_ns_config( nsr, vnfrs, rpc_ip) tasks.append(task) self.job_manager.add_job(rpc_op, tasks) else: for vnf in rpc_ip.vnf_list: vnf_op = rpc_op.vnf_out_list.add() vnf_member_idx = vnf.member_vnf_index_ref vnfr_id = vnf.vnfr_id_ref vnf_op.vnfr_id_ref = vnfr_id vnf_op.member_vnf_index_ref = vnf_member_idx for primitive in vnf.vnf_primitive: op_primitive = vnf_op.vnf_out_primitive.add() op_primitive.name = primitive.name op_primitive.execution_id = '' op_primitive.execution_status = 'completed' self._log.debug("%s:%s Got primitive %s:%s", nsr_id, vnf.member_vnf_index_ref, primitive.name, primitive.parameter) nsd_vnf_primitive = yield from self._get_vnf_primitive( vnfr_id, nsr_id, primitive.name) for param in nsd_vnf_primitive.parameter: if not param.has_field("parameter_pool"): continue try: nsr_param_pool = nsr.param_pools[ param.parameter_pool] except KeyError: raise ValueError( "Parameter pool %s does not exist in nsr" % param.parameter_pool) nsr_param_pool.add_used_value(param.value) for config_plugin in self.nsm.config_agent_plugins: yield from config_plugin.vnf_config_primitive( nsr_id, vnfr_id, primitive, op_primitive) self.job_manager.add_job(rpc_op) # Get NSD # Find Config Primitive # For each vnf-primitive with parameter pool # Find parameter pool # Add used value to the pool self._log.debug("RPC output: {}".format(rpc_op)) xact_info.respond_xpath(rwdts.XactRspCode.ACK, RiftCMRPCHandler.EXEC_NS_CONF_O_XPATH, rpc_op) except Exception as e: self._log.error("Exception processing the " "exec-ns-config-primitive: {}".format(e)) self._log.exception(e) xact_info.respond_xpath(rwdts.XactRspCode.NACK, RiftCMRPCHandler.EXEC_NS_CONF_O_XPATH)
def make_nsr(ns_instance_config_ref=str(uuid.uuid4())): nsr = NsrYang.YangData_Nsr_NsInstanceOpdata_Nsr() nsr.ns_instance_config_ref = ns_instance_config_ref return nsr