From 9c11d59035ff1741c5e6d935aa7c2ed23d15f485 Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Thu, 14 Sep 2017 18:56:18 +0200 Subject: Create vnffg providing the neutron_port JIRA: SFC-107 We are submitting the vnffgd with a variable for the neutron_port. Before creating the vnffg, we must provide a file with the neutron_port value Change-Id: I9994e2baa53f323df17434448d372598c0d94c72 Signed-off-by: Manuel Buil --- sfc/lib/utils.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'sfc/lib/utils.py') diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index 392f1db5..9d44b3eb 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -117,6 +117,25 @@ def create_vnf_in_av_zone( param_file=param_file) +def create_vnffg_with_param_file(tacker_client, vnffgd_name, vnffg_name, + default_param_file, neutron_port): + param_file = default_param_file + + if neutron_port is not None: + param_file = os.path.join( + '/tmp', + 'param_{0}.json'.format(neutron_port)) + data = { + 'net_src_port_id': neutron_port + } + with open(param_file, 'w+') as f: + json.dump(data, f) + os_tacker.create_vnffg(tacker_client, + vnffgd_name=vnffgd_name, + vnffg_name=vnffg_name, + param_file=param_file) + + def setup_neutron(neutron_client, net, subnet, router, subnet_cidr): n_dict = os_utils.create_network_full(neutron_client, net, @@ -647,3 +666,22 @@ def register_vim(tacker_client, vim_file=None): json.dump(json_dict, open(tmp_file, 'w')) os_tacker.create_vim(tacker_client, vim_file=tmp_file) + + +def get_neutron_interfaces(vm): + ''' + Get the interfaces of an instance + ''' + nova_client = os_utils.get_nova_client() + interfaces = nova_client.servers.interface_list(vm.id) + return interfaces + + +def get_client_port_id(vm): + ''' + Get the neutron port id of the client + ''' + interfaces = get_neutron_interfaces(vm) + if len(interfaces) > 1: + raise Exception("Client has more than one interface. Not expected!") + return interfaces[0].id -- cgit 1.2.3-korg