From c9a3f9a87f0dde283341ba13ea6d430aff5b9634 Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 21 Jan 2019 14:57:13 +0000 Subject: [PATCH] adding SOL005 additionalParams to ns/nsi creation Change-Id: Ia871bd316a94af03acec1863dd2b8acfe43b3505 Signed-off-by: tierno --- osmclient/scripts/osm.py | 8 +++++--- osmclient/sol005/ns.py | 20 +++++++++++++++++++- osmclient/sol005/nsi.py | 20 +++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 2c151ff..0a4c465 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -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]' ) diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index 9d1fe95..bd72d42 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -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, diff --git a/osmclient/sol005/nsi.py b/osmclient/sol005/nsi.py index f6009dd..cb87b85 100644 --- a/osmclient/sol005/nsi.py +++ b/osmclient/sol005/nsi.py @@ -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, -- 2.25.1