adding SOL005 additionalParams to ns/nsi creation 19/7119/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 21 Jan 2019 14:57:13 +0000 (14:57 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 30 Jan 2019 10:31:22 +0000 (10:31 +0000)
Change-Id: Ia871bd316a94af03acec1863dd2b8acfe43b3505
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/ns.py
osmclient/sol005/nsi.py

index 2c151ff..0a4c465 100755 (executable)
@@ -1207,9 +1207,9 @@ def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_fi
             with open(config_file, 'r') as cf:
                 config=cf.read()
         ctx.obj.nsi.create(nst_name, nsi_name, config=config, ssh_keys=ssh_keys,
-            account=vim_account)
+                           account=vim_account)
     except ClientException as inst:
-        print((inst.message))
+        print(inst.message)
         exit(1)
 
 
@@ -1224,7 +1224,9 @@ def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_fi
               'netslice_subnet: [\n'
                 'id: TEXT, vim_account: TEXT,\n'
                 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
-                'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
+                'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
+                'additionalParamsForNsi: {param: value, ...}\n'
+                'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
               '],\n'
               'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
               )
index 9d1fe95..bd72d42 100644 (file)
@@ -147,7 +147,25 @@ class Ns(object):
                         vnf["vimAccountId"] = get_vim_account_id(vnf.pop("vim_account"))
                 ns["vnf"] = ns_config["vnf"]
 
-        #print yaml.safe_dump(ns)
+            if "additionalParamsForNs" in ns_config:
+                ns["additionalParamsForNs"] = ns_config.pop("additionalParamsForNs")
+                if not isinstance(ns["additionalParamsForNs"], dict):
+                    raise ValueError("Error at --config 'additionalParamsForNs' must be a dictionary")
+            if "additionalParamsForVnf" in ns_config:
+                ns["additionalParamsForVnf"] = ns_config.pop("additionalParamsForVnf")
+                if not isinstance(ns["additionalParamsForVnf"], list):
+                    raise ValueError("Error at --config 'additionalParamsForVnf' must be a list")
+                for additional_param_vnf in ns["additionalParamsForVnf"]:
+                    if not isinstance(additional_param_vnf, dict):
+                        raise ValueError("Error at --config 'additionalParamsForVnf' items must be dictionaries")
+                    if not additional_param_vnf.get("member-vnf-index"):
+                        raise ValueError("Error at --config 'additionalParamsForVnf' items must contain "
+                                         "'member-vnf-index'")
+                    if not additional_param_vnf.get("additionalParams"):
+                        raise ValueError("Error at --config 'additionalParamsForVnf' items must contain "
+                                         "'additionalParams'")
+
+        # print yaml.safe_dump(ns)
         try:
             self._apiResource = '/ns_instances_content'
             self._apiBase = '{}{}{}'.format(self._apiName,
index f6009dd..cb87b85 100644 (file)
@@ -161,7 +161,25 @@ class Nsi(object):
                                 vnf["vimAccountId"] = get_vim_account_id(vnf.pop("vim_account"))
                 nsi["netslice-subnet"] = nsi_config["netslice-subnet"]
 
-        #print yaml.safe_dump(nsi)
+            if "additionalParamsForNsi" in nsi_config:
+                nsi["additionalParamsForNsi"] = nsi_config.pop("additionalParamsForNsi")
+                if not isinstance(nsi["additionalParamsForNsi"], dict):
+                    raise ValueError("Error at --config 'additionalParamsForNsi' must be a dictionary")
+            if "additionalParamsForSubnet" in nsi_config:
+                nsi["additionalParamsForSubnet"] = nsi_config.pop("additionalParamsForSubnet")
+                if not isinstance(nsi["additionalParamsForSubnet"], list):
+                    raise ValueError("Error at --config 'additionalParamsForSubnet' must be a list")
+                for additional_param_subnet in nsi["additionalParamsForSubnet"]:
+                    if not isinstance(additional_param_subnet, dict):
+                        raise ValueError("Error at --config 'additionalParamsForSubnet' items must be dictionaries")
+                    if not additional_param_subnet.get("id"):
+                        raise ValueError("Error at --config 'additionalParamsForSubnet' items must contain subnet 'id'")
+                    if not additional_param_subnet.get("additionalParamsForNs") and\
+                            not additional_param_subnet.get("additionalParamsForVnf"):
+                        raise ValueError("Error at --config 'additionalParamsForSubnet' items must contain "
+                                         "'additionalParamsForNs' and/or 'additionalParamsForVnf'")
+
+        # print yaml.safe_dump(nsi)
         try:
             self._apiResource = '/netslice_instances_content'
             self._apiBase = '{}{}{}'.format(self._apiName,