def handle(self, request, data): try: # Django use blank string, OpenAPI use None for k in data: if data[k] == "": data[k] = None sfcr_spec = ni_nfvo_client.SfcrSpec( name=data['sfcr_name'], source_client=data['source_client'], destination_client=data['destination_client'], src_ip_prefix=data['src_ip_prefix'], dst_ip_prefix=data['dst_ip_prefix'], src_port_min=data['src_port_min'], src_port_max=data['src_port_max'], dst_port_min=data['dst_port_min'], dst_port_max=data['dst_port_max'], bw=data['bw'], delay=data['delay'], # duration=data['duration'], nf_chain=json.loads(data['nf_chain']), proto=data['proto']) sfcr_id = ni_nfvo_sfcr_api.add_sfcr(sfcr_spec) sfcrs = ni_nfvo_sfcr_api.get_sfcrs() for sfcr in sfcrs: if sfcr.id == sfcr_id: return sfcr raise Exception() return sfcrs except Exception as e: exceptions.handle(request, str(e))
def api_call_add_sfcr(**sfcr_spec_dict): ni_nfvo_sfcr_api = get_nfvo_sfcr_api() sfcr_spec = ni_nfvo_client.SfcrSpec( name=sfcr_spec_dict["name"], src_ip_prefix=sfcr_spec_dict["src_ip_prefix"], dst_ip_prefix=sfcr_spec_dict["dst_ip_prefix"], nf_chain=sfcr_spec_dict["nf_chain"], source_client=sfcr_spec_dict["source_client"]) api_response = ni_nfvo_sfcr_api.add_sfcr(sfcr_spec) print("### add_sfcr_api_response", api_response)
def set_flow_classifier(sfcr_name, src_ip_prefix, nf_chain, source_client): ni_nfvo_sfcr_api = get_nfvo_sfcr_api() sfcr_spec = ni_nfvo_client.SfcrSpec(name=sfcr_name, src_ip_prefix=src_ip_prefix, nf_chain=nf_chain, source_client=source_client) api_response = ni_nfvo_sfcr_api.add_sfcr(sfcr_spec) return api_response
def create_sample_sfcr(sfcr_name, source_client, destination_client=None): sfcr_spec = ni_nfvo_client.SfcrSpec(name=sfcr_name, source_client=source_client, destination_client=destination_client, src_ip_prefix="192.0.0.8/32", src_port_min=0, src_port_max=65535, dst_port_min=0, dst_port_max=65535, proto='TCP') sfcr_id = ni_nfvo_sfcr_api.add_sfcr(sfcr_spec) assert check_sfcr_exist(sfcr_id) == True return sfcr_id
def create_monitor_classifier(scaler): ni_nfvo_sfcr_api = get_nfvo_sfcr_api() name = scaler.get_scaling_name( ) + cfg["instance"]["prefix_splitter"] + "monitor" source_client = scaler.get_monitor_src_id() src_ip_prefix = get_ip_from_id(source_client) + "/32" dst_ip_prefix = get_ip_from_id(scaler.get_monitor_dst_id()) + "/32" sfcr_id = get_sfc_by_name(scaler.get_sfc_name()).sfcr_ids[-1] nf_chain = get_sfcr_by_id(sfcr_id).nf_chain sfcr_spec = ni_nfvo_client.SfcrSpec(name=name, src_ip_prefix=src_ip_prefix, dst_ip_prefix=dst_ip_prefix, nf_chain=nf_chain, source_client=source_client) api_response = ni_nfvo_sfcr_api.add_sfcr(sfcr_spec) return api_response