self._apiName, self._apiVersion, self._apiResource
)
- def create(self, name, k8s_cluster):
- def get_vim_account_id(vim_account):
- vim = self._client.vim.get(vim_account)
- if vim is None:
- raise NotFound("cannot find vim account '{}'".format(vim_account))
- return vim["_id"]
+ def _get_vim_account(self, vim_account):
+ vim = self._client.vim.get(vim_account)
+ if vim is None:
+ raise NotFound("cannot find vim account '{}'".format(vim_account))
+ return vim
+ def create(self, name, k8s_cluster):
self._client.get_token()
- k8s_cluster["vim_account"] = get_vim_account_id(k8s_cluster["vim_account"])
+ vim_account = self._get_vim_account(k8s_cluster["vim_account"])
+ k8s_cluster["vim_account"] = vim_account["_id"]
+ if "vca" in vim_account:
+ k8s_cluster["vca_id"] = vim_account["vca"]
http_code, resp = self._http.post_cmd(
endpoint=self._apiBase, postfields_dict=k8s_cluster
)
def update(self, name, k8s_cluster):
self._client.get_token()
cluster = self.get(name)
+ if "vim_account" in k8s_cluster:
+ vim_account = self._get_vim_account(k8s_cluster["vim_account"])
+ k8s_cluster["vim_account"] = vim_account["_id"]
+ if "vca" in vim_account:
+ k8s_cluster["vca_id"] = vim_account["vca"]
http_code, resp = self._http.put_cmd(
endpoint="{}/{}".format(self._apiBase, cluster["_id"]),
postfields_dict=k8s_cluster,