+ def get_vca_id(vca):
+ vca = self._client.vca.get(vca)
+ if vca is None:
+ raise NotFound("cannot find vca '{}'".format(vca))
+ return vca["_id"]
+
+ self._logger.debug("")
+ self._client.get_token()
+ if "vca" in vim_access:
+ vca_id = get_vca_id(vim_access["vca"])
+ if "vim-type" not in vim_access:
+ # 'openstack' not in vim_access['vim-type']):
+ raise Exception("vim type not provided")
+ vim_account = {}
+ vim_account["name"] = name
+ vim_account = self.update_vim_account_dict(vim_account, vim_access)
+ if vca_id:
+ vim_account["vca"] = vca_id
+ vim_config = config
+ if sdn_controller:
+ sdnc = self._client.sdnc.get(sdn_controller)
+ vim_config["sdn-controller"] = sdnc["_id"]
+ if sdn_port_mapping:
+ with open(sdn_port_mapping, "r") as f:
+ vim_config["sdn-port-mapping"] = yaml.safe_load(f.read())
+ if vim_config:
+ vim_account["config"] = vim_config
+ # vim_account['config'] = json.dumps(vim_config)
+
+ http_code, resp = self._http.post_cmd(
+ endpoint=self._apiBase, postfields_dict=vim_account
+ )
+ # print('HTTP CODE: {}'.format(http_code))
+ # print('RESP: {}'.format(resp))
+ # if http_code in (200, 201, 202, 204):
+ if resp:
+ resp = json.loads(resp)
+ if not resp or "id" not in resp:
+ raise ClientException("unexpected response from server - {}".format(resp))
+ if wait:
+ # Wait for status for VIM instance creation
+ self._wait(resp.get("id"), wait)
+ print(resp["id"])
+ # else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to create vim {} - {}".format(name, msg))