- if "vld" in ns_config:
- for vld in ns_config["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
- ns["vld"] = ns_config["vld"]
- if "vnf" in ns_config:
- for vnf in ns_config["vnf"]:
- if vnf.get("vim_account"):
- vnf["vimAccountId"] = get_vim_account_id(vnf.pop("vim_account"))
- ns["vnf"] = ns_config["vnf"]
-
- #print yaml.safe_dump(ns)
+
+ ns_config = self._update_vld_in_ns_config(
+ ns_config, vim_account_dict, wim_account_dict
+ )
+ ns_config = self._update_vnf_in_ns_config(ns_config, vim_account_dict)
+ self._validate_additional_params_in_ns_config(ns_config)
+ ns = self._update_wim_account_in_ns(ns_config, vim_account_dict, ns)
+ ns.update(ns_config)
+
+ return ns
+
+ def process_ns_create_with_paas_account(
+ self,
+ paas_account: str,
+ nsd: dict,
+ nsr_name: str,
+ description: str,
+ config: dict = None,
+ timeout: int = None,
+ ) -> dict:
+ """Process NS create request which includes PaaS Account.
+ Args:
+ paas_account (str): PaaS Account id as string
+ nsd (dict): A dictionary which includes network service description
+ nsr_name (str): Network service record name
+ description (str): Service description
+ config (dict): Placeholder for additional configuration
+ timeout (int): Max time to wait (seconds)
+
+ Returns:
+ ns (dict): Payload for ns create request
+
+ Raises:
+ ClientException
+ """
+ paas_id = self._get_paas_account_id(paas_account)
+ ns = {
+ "nsdId": nsd["_id"],
+ "nsName": nsr_name,
+ "nsDescription": description,
+ "paasAccountId": paas_id,
+ }
+
+ if timeout:
+ ns["timeout_ns_deploy"] = timeout
+
+ if config:
+ ns_config = yaml.safe_load(config)
+ self._validate_additional_params_in_ns_config(ns_config)
+ ns.update(ns_config)
+
+ return ns
+
+ def create(
+ self,
+ nsd_name: dict,
+ nsr_name: str,
+ vim_account: str = None,
+ paas_account: str = None,
+ config: dict = None,
+ ssh_keys: str = None,
+ description: str = "default description",
+ admin_status: str = "ENABLED",
+ wait: bool = False,
+ timeout: int = None,
+ ) -> str:
+ """NS create request which includes PaaS Account or VIM account.
+ Args:
+ nsd_name (dict): A dictionary which includes network service description
+ nsr_name (str): Network service record name
+ vim_account (str): VIM account ID as string
+ paas_account (str): PaaS Account id as string
+ config (dict): Placeholder for additional configuration
+ ssh_keys (str): ssh-key file
+ description (str): Service description
+ admin_status (str): Administration Status
+ wait (Boolean): True or False
+ timeout (int): Max time to wait (seconds)
+
+ Returns:
+ response id (str): Response ID
+
+ Raises:
+ ClientException
+ """
+ self._logger.debug("")
+
+ if not (vim_account or paas_account):
+ raise ClientException(
+ "Both of vim_account and paas_account options are empty."
+ )
+
+ if vim_account and paas_account:
+ raise ClientException(
+ "Both of vim_account and paas_account options are set."
+ )
+
+ self._client.get_token()
+ nsd = self._client.nsd.get(nsd_name)
+
+ if vim_account:
+ # VIM account is provided as input parameter.
+ ns = self.process_ns_create_with_vim_account(
+ vim_account,
+ nsd,
+ nsr_name,
+ description,
+ config=config,
+ ssh_keys=ssh_keys,
+ timeout=timeout,
+ )
+
+ elif paas_account:
+ # PaaS account is provided as input parameter.
+ ns = self.process_ns_create_with_paas_account(
+ paas_account, nsd, nsr_name, description, config=config, timeout=timeout
+ )
+