From 6380fc0aa54cc7c3700a5a1f655e619471684611 Mon Sep 17 00:00:00 2001 From: Mike Marchetti Date: Mon, 20 Nov 2017 13:24:31 -0500 Subject: [PATCH] allow ns config to set vim network name Signed-off-by: Mike Marchetti --- osmclient/scripts/osm.py | 8 ++++---- osmclient/v1/ns.py | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 3c73510..d0d78f5 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -207,9 +207,9 @@ def ns_monitoring_show(ctx, ns_name): @click.option('--ssh_keys', default=None, help='comma separated list of keys to inject to vnfs') -@click.option('--vim_network_prefix', +@click.option('--config', default=None, - help='vim network name prefix') + help='ns specific yaml configuration') @click.pass_context def ns_create(ctx, nsd_name, @@ -217,12 +217,12 @@ def ns_create(ctx, vim_account, admin_status, ssh_keys, - vim_network_prefix): + config): try: ctx.obj.ns.create( nsd_name, ns_name, - vim_network_prefix=vim_network_prefix, + config=config, ssh_keys=ssh_keys, account=vim_account) except ClientException as inst: diff --git a/osmclient/v1/ns.py b/osmclient/v1/ns.py index fe62e3d..8ea1854 100644 --- a/osmclient/v1/ns.py +++ b/osmclient/v1/ns.py @@ -22,6 +22,7 @@ from osmclient.common import utils from osmclient.common.exceptions import ClientException from osmclient.common.exceptions import NotFound import uuid +import yaml class Ns(object): @@ -68,7 +69,7 @@ class Ns(object): ns_name, resp)) - def create(self, nsd_name, nsr_name, account, vim_network_prefix=None, + def create(self, nsd_name, nsr_name, account, config=None, ssh_keys=None, description='default description', admin_status='ENABLED'): postdata = {} @@ -112,11 +113,18 @@ class Ns(object): nsr['ssh-authorized-key'] = ssh_keys_format - if vim_network_prefix is not None: - for index, vld in enumerate(nsr['nsd']['vld']): - network_name = vld['name'] - nsr['nsd']['vld'][index]['vim-network-name'] = '{}-{}'.format( - vim_network_prefix, network_name) + if config: + ns_config = yaml.load(config) + + if ns_config and 'vim-network-name' in ns_config: + for network in ns_config['vim-network-name']: + # now find this network + vld_name = network['name'] + vim_vld_name = network['vim-network-name'] + + for index, vld in enumerate(nsr['nsd']['vld']): + if vld['name'] == vld_name: + nsr['nsd']['vld'][index]['vim-network-name'] = network['vim-network-name'] postdata['nsr'].append(nsr) -- 2.25.1