allow ns config to set vim network name
authorMike Marchetti <mmarchetti@sandvine.com>
Mon, 20 Nov 2017 18:24:31 +0000 (13:24 -0500)
committerMike Marchetti <mmarchetti@sandvine.com>
Mon, 20 Nov 2017 18:24:31 +0000 (13:24 -0500)
Signed-off-by: Mike Marchetti <mmarchetti@sandvine.com>
osmclient/scripts/osm.py
osmclient/v1/ns.py

index 3c73510..d0d78f5 100755 (executable)
@@ -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:
index fe62e3d..8ea1854 100644 (file)
@@ -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)