X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fns.py;h=f4366b23f5e50be735d652c7c9f0d4e7af6e587b;hb=2c087a32de17a0f5f386bab6513df2e3847ba3da;hp=b6ccb9fe124ac75c94bcb2cc4590e65c694224e9;hpb=961145b6c1ab65c8cc5953aae008781e285c1461;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index b6ccb9f..f4366b2 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -163,6 +163,7 @@ class Ns(object): description="default description", admin_status="ENABLED", wait=False, + timeout=None, ): self._logger.debug("") self._client.get_token() @@ -181,10 +182,6 @@ class Ns(object): vim_account_id[vim_account] = vim["_id"] return vim["_id"] - def get_vca_id(vim_id): - vim = self._client.vim.get(vim_id) - return vim.get("vca") - def get_wim_account_id(wim_account): self._logger.debug("") # wim_account can be False (boolean) to indicate not use wim account @@ -199,14 +196,11 @@ class Ns(object): return wim["_id"] vim_id = get_vim_account_id(account) - vca_id = get_vca_id(vim_id) ns = {} ns["nsdId"] = nsd["_id"] ns["nsName"] = nsr_name ns["nsDescription"] = description ns["vimAccountId"] = vim_id - if vca_id: - ns["vcaId"] = vca_id # ns['userdata'] = {} # ns['userdata']['key1']='value1' # ns['userdata']['key2']='value2' @@ -216,6 +210,8 @@ class Ns(object): for pubkeyfile in ssh_keys.split(","): with open(pubkeyfile, "r") as f: ns["ssh_keys"].append(f.read()) + if timeout: + ns["timeout_ns_deploy"] = timeout if config: ns_config = yaml.safe_load(config) if "vim-network-name" in ns_config: @@ -532,6 +528,59 @@ class Ns(object): message = "failed to delete alarm: alarm {}\n{}".format(name, str(exc)) raise ClientException(message) + def get_alarm(self, project_name=None, ns_id=None, uuid=None): + self._client.get_token() + try: + self._apiName = "/nsfm" + self._apiResource = "/alarms" + self._apiBase = "{}{}{}".format( + self._apiName, self._apiVersion, self._apiResource + ) + if uuid: + # if request is for any uuid + http_code, resp = self._http.get2_cmd( + "{}/{}".format(self._apiBase, uuid) + ) + if not uuid: + http_code, resp = self._http.get2_cmd( + "{}/{}/{}/{}".format(self._apiBase, uuid, project_name, ns_id) + ) + if http_code == 200: + if resp: + resp = json.loads(resp) + return resp + else: + raise ClientException("unexpected response from server") + else: + msg = resp or "" + raise ClientException(msg) + except ClientException as exc: + message = "failed to get alarm :\nerror:\n{}".format(str(exc)) + raise ClientException(message) + + def update_alarm(self, uuid, threshold=None, is_enable=None, wait=None): + self._client.get_token() + try: + op_data = {} + op_data["uuid"] = uuid + op_data["threshold"] = threshold + op_data["is_enable"] = is_enable + self._apiName = "/nsfm" + self._apiResource = "/alarms" + self._apiBase = "{}{}{}".format( + self._apiName, self._apiVersion, self._apiResource + ) + http_code, resp = self._http.patch_cmd( + endpoint="{}".format(self._apiBase), postfields_dict=op_data + ) + if resp: + resp = json.loads(resp) + print(resp) + return resp + except ClientException as exc: + message = "failed to update alarm :\nerror:\n{}".format(str(exc)) + raise ClientException(message) + def export_metric(self, metric): self._logger.debug("") self._client.get_token()