aboutsummaryrefslogtreecommitdiffstats
path: root/sfc/lib
diff options
context:
space:
mode:
authorManuel Buil <mbuil@suse.com>2017-09-14 18:56:18 +0200
committerManuel Buil <mbuil@suse.com>2017-09-20 07:11:41 +0000
commit2ce3eccae3de3f97c2ad8b2041d1b068d070a6e3 (patch)
tree69f8f206735a661722b00254ad925ad78d214c64 /sfc/lib
parent3cea8f88d68e71e22be478beab8ce94a0d352392 (diff)
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 <mbuil@suse.com> (cherry picked from commit 9c11d59035ff1741c5e6d935aa7c2ed23d15f485)
Diffstat (limited to 'sfc/lib')
-rw-r--r--sfc/lib/openstack_tacker.py13
-rw-r--r--sfc/lib/utils.py38
2 files changed, 47 insertions, 4 deletions
diff --git a/sfc/lib/openstack_tacker.py b/sfc/lib/openstack_tacker.py
index 93649e32..a4077744 100644
--- a/sfc/lib/openstack_tacker.py
+++ b/sfc/lib/openstack_tacker.py
@@ -241,7 +241,7 @@ def create_vnffgd(tacker_client, tosca_file=None, vnffgd_name=None):
vnffgd_body = {}
if tosca_file is not None:
with open(tosca_file) as tosca_fd:
- vnffgd_body = yaml.load(tosca_fd)
+ vnffgd_body = yaml.safe_load(tosca_fd)
logger.info('VNFFGD template:\n{0}'.format(vnffgd_body))
return tacker_client.create_vnffgd(
body={'vnffgd': {'name': vnffgd_name,
@@ -253,10 +253,9 @@ def create_vnffgd(tacker_client, tosca_file=None, vnffgd_name=None):
def create_vnffg(tacker_client, vnffg_name=None, vnffgd_id=None,
- vnffgd_name=None):
+ vnffgd_name=None, param_file=None):
'''
- Tacker doesn't support Symmetrical chain and parameter file
- in Openstack/Ocata
+ Creates the vnffg which will provide the RSP and the classifier
'''
try:
vnffg_body = {
@@ -265,6 +264,12 @@ def create_vnffg(tacker_client, vnffg_name=None, vnffgd_id=None,
'name': vnffg_name
}
}
+ if param_file is not None:
+ params = None
+ with open(param_file) as f:
+ params = f.read()
+ params_dict = yaml.safe_load(params)
+ vnffg_body['vnffg']['attributes']['param_values'] = params_dict
if vnffgd_id is not None:
vnffg_body['vnffg']['vnffgd_id'] = vnffgd_id
else:
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