+ if vim_account_dict.get(vim_account):
+ return vim_account_dict[vim_account]
+ vim = self._client.vim.get(vim_account)
+ if vim is None:
+ raise NotFound("cannot find vim account '{}'".format(vim_account))
+ vim_account_dict[vim_account] = vim["_id"]
+ return vim["_id"]
+
+ def _get_wim_account_id(self, wim_account: str, wim_account_dict: dict) -> str:
+ """Get WIM account ID.
+ Args:
+ wim_account (str): WIM account id as string
+ wim_account_dict (dict): A dictionary which includes wim account id
+
+ Returns:
+ wim_id (str): WIM account id as string
+
+ Raises:
+ NotFound Exception
+ """
+ self._logger.debug("")
+ # wim_account can be False (boolean) to indicate not use wim account
+ if not isinstance(wim_account, str):
+ return wim_account
+ if wim_account_dict.get(wim_account):
+ return wim_account_dict[wim_account]
+ wim = self._client.wim.get(wim_account)
+ if wim is None:
+ raise NotFound("cannot find wim account '{}'".format(wim_account))
+ wim_account_dict[wim_account] = wim["_id"]
+ return wim["_id"]
+
+ def _get_paas_account_id(self, paas_account: str) -> str:
+ """Get PaaS account ID.
+ Args:
+ paas_account (str): PaaS account id as string
+
+ Returns:
+ paas_id (str): PaaS account id as string
+
+ Raises:
+ NotFound Exception
+ """
+ self._logger.debug("")
+ paas = self._client.paas.get(paas_account)
+ if paas is None:
+ raise NotFound("cannot find PaaS account '{}'".format(paas_account))
+ return paas["_id"]
+
+ def _update_vnf_in_ns_config(self, ns_config: dict, vim_account_dict: dict) -> dict:
+ """Update vnf field in ns_config.
+ Args:
+ ns_config (dict): NS config dictionary which includes additional params
+ vim_account_dict (dict): A dictionary which includes vim account id
+
+ Returns:
+ ns (dict): NS dictionary
+ """
+ if "vnf" in ns_config:
+ for vnf in ns_config["vnf"]:
+ if vnf.get("vim_account"):
+ vnf["vimAccountId"] = self._get_vim_account_id(
+ vnf.pop("vim_account"), vim_account_dict
+ )
+ return ns_config
+
+ def _update_wim_account_in_ns(
+ self, ns_config: dict, wim_account_dict: dict, ns: dict
+ ) -> dict:
+ """Update WIM_account in NS dictionary.
+ Args:
+ ns_config (dict): NS config dictionary which includes additional params
+ wim_account_dict (dict): A dictionary which includes wim account id
+ ns (dict): NS dictionary which includes ns_id, ns_name, description etc.
+
+ Returns:
+ ns (dict): NS dictionary
+ """
+ if "wim_account" in ns_config:
+ wim_account = ns_config.pop("wim_account")
+ if wim_account is not None:
+ ns["wimAccountId"] = self._get_wim_account_id(
+ wim_account, wim_account_dict
+ )
+ return ns
+
+ def _update_vld_in_ns_config(
+ self, ns_config: dict, vim_account_dict: dict, wim_account_dict: dict
+ ) -> dict:
+ """Validating the additionalParamsForNs and additionalParamsForVnf in ns_config.
+
+ Args:
+ ns_config (dict): NS config dictionary which includes additional params
+ vim_account_dict (dict): A dictionary which includes vim account id
+ wim_account_dict (dict): A dictionary which includes wim account id
+
+ Returns:
+ ns_config (dict): NS config dictionary which includes additional params
+
+ Raises:
+ ClientException
+ """
+ if "vld" in ns_config:
+ if not isinstance(ns_config["vld"], list):
+ raise ClientException(
+ "Error at --config 'vld' must be a list of dictionaries"
+ )
+ for vld in ns_config["vld"]:
+ if not isinstance(vld, dict):
+ raise ClientException(
+ "Error at --config 'vld' must be a list of dictionaries"
+ )
+ if vld.get("vim-network-name"):
+ if isinstance(vld["vim-network-name"], dict):
+ vim_network_name_dict = {}
+ for vim_account, vim_net in vld["vim-network-name"].items():
+ vim_network_name_dict[
+ self._get_vim_account_id(vim_account, vim_account_dict)
+ ] = vim_net
+ vld["vim-network-name"] = vim_network_name_dict
+ if "wim_account" in vld and vld["wim_account"] is not None:
+ vld["wimAccountId"] = self._get_wim_account_id(
+ vld.pop("wim_account"), wim_account_dict
+ )
+ return ns_config
+
+ def _validate_additional_params_in_ns_config(self, ns_config: dict) -> None:
+ """Validating the additionalParamsForNs and additionalParamsForVnf in ns_config.
+ Args:
+ ns_config (dict): NS config dictionary which includes additional params
+
+ Raises:
+ ClientException
+ """
+ if "additionalParamsForNs" in ns_config:
+ if not isinstance(ns_config["additionalParamsForNs"], dict):
+ raise ClientException(
+ "Error at --config 'additionalParamsForNs' must be a dictionary"
+ )
+ if "additionalParamsForVnf" in ns_config:
+ if not isinstance(ns_config["additionalParamsForVnf"], list):
+ raise ClientException(
+ "Error at --config 'additionalParamsForVnf' must be a list"
+ )
+ for additional_param_vnf in ns_config["additionalParamsForVnf"]:
+ if not isinstance(additional_param_vnf, dict):
+ raise ClientException(
+ "Error at --config 'additionalParamsForVnf' items must be dictionaries"
+ )
+ if not additional_param_vnf.get("member-vnf-index"):
+ raise ClientException(
+ "Error at --config 'additionalParamsForVnf' items must contain "
+ "'member-vnf-index'"
+ )