+ nsi_data["ssh_keys"].append(request.POST.get('ssh_key'))
+ ssh_key_files = request.FILES.getlist('ssh_key_files')
+ for ssh_key_file in ssh_key_files:
+ ssh_key = ''
+ for line in ssh_key_file:
+ ssh_key = ssh_key + line.decode()
+ nsi_data["ssh_keys"].append(ssh_key)
+ nsi_data["ssh_keys"] = ','.join(nsi_data["ssh_keys"])
+
+ config_file = request.FILES.get('config_file')
+
+ if config_file is not None:
+ config = ''
+ for line in config_file:
+ config = config + line.decode()
+ nsi_config = yaml.load(config)
+ elif 'config' in request.POST and request.POST.get('config') != '':
+ nsi_config = yaml.load(request.POST.get('config'))
+ else:
+ nsi_config = None
+
+ if nsi_config is not None:
+ if "netslice-vld" in nsi_config:
+ for vld in nsi_config["netslice-vld"]:
+ if vld.get("vim-network-name"):
+ if isinstance(vld["vim-network-name"], dict):
+ vim_network_name_dict = {}
+ for vim_account, vim_net in list(vld["vim-network-name"].items()):
+ vim_network_name_dict[get_vim_account_id(vim_account)] = vim_net
+ vld["vim-network-name"] = vim_network_name_dict
+ nsi_data["netslice-vld"] = nsi_config["netslice-vld"]
+ if "netslice-subnet" in nsi_config:
+ for nssubnet in nsi_config["netslice-subnet"]:
+ if "vld" in nssubnet:
+ for vld in nssubnet["vld"]:
+ if vld.get("vim-network-name"):
+ if isinstance(vld["vim-network-name"], dict):
+ vim_network_name_dict = {}
+ for vim_account, vim_net in list(vld["vim-network-name"].items()):
+ vim_network_name_dict[get_vim_account_id(vim_account)] = vim_net
+ vld["vim-network-name"] = vim_network_name_dict
+ if "vnf" in nssubnet:
+ for vnf in nsi_config["vnf"]:
+ if vnf.get("vim_account"):
+ vnf["vimAccountId"] = get_vim_account_id(vnf.pop("vim_account"))
+ nsi_data["netslice-subnet"] = nsi_config["netslice-subnet"]
+ if "additionalParamsForNsi" in nsi_config:
+ nsi_data["additionalParamsForNsi"] = nsi_config.pop("additionalParamsForNsi")
+ if not isinstance(nsi_data["additionalParamsForNsi"], dict):
+ raise ValueError("Error at 'additionalParamsForNsi' must be a dictionary")
+ if "additionalParamsForSubnet" in nsi_config:
+ nsi_data["additionalParamsForSubnet"] = nsi_config.pop("additionalParamsForSubnet")
+ if not isinstance(nsi_data["additionalParamsForSubnet"], list):
+ raise ValueError("Error 'additionalParamsForSubnet' must be a list")
+ for additional_param_subnet in nsi_data["additionalParamsForSubnet"]:
+ if not isinstance(additional_param_subnet, dict):
+ raise ValueError("Error 'additionalParamsForSubnet' items must be dictionaries")
+ if not additional_param_subnet.get("id"):
+ raise ValueError("Error 'additionalParamsForSubnet' items must contain subnet 'id'")
+ if not additional_param_subnet.get("additionalParamsForNs") and\
+ not additional_param_subnet.get("additionalParamsForVnf"):
+ raise ValueError("Error 'additionalParamsForSubnet' items must contain "
+ "'additionalParamsForNs' and/or 'additionalParamsForVnf'")