X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fns.py;h=00d68d669c5d1852e6f815885acd6dc36d4bf5e0;hb=fcfed2f9c065ba92f775fb6f4563d5d4b64e7797;hp=d457cbd8774cf469fb959726f26344fbe4a94f10;hpb=95686bbc69ded243c346f94dceb0bee567572fb7;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index d457cbd..00d68d6 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() @@ -194,11 +195,12 @@ class Ns(object): wim_account_id[wim_account] = wim["_id"] return wim["_id"] + vim_id = get_vim_account_id(account) ns = {} ns["nsdId"] = nsd["_id"] ns["nsName"] = nsr_name ns["nsDescription"] = description - ns["vimAccountId"] = get_vim_account_id(account) + ns["vimAccountId"] = vim_id # ns['userdata'] = {} # ns['userdata']['key1']='value1' # ns['userdata']['key2']='value2' @@ -208,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: @@ -467,6 +471,54 @@ class Ns(object): ) raise ClientException(message) + def update(self, ns_name, data, wait=False): + """Update NS instance. + + This function calls the NBI in order to perform an update operation + on a Network Service instance. + + Args: + ns_name: (str) + data: (dict) + wait: (boolean) + + Returns: + None + + """ + self._logger.debug("") + self._client.get_token() + try: + op_data = {"updateType": data.pop("updateType")} + + # Check update parameters availability according to update type + if op_data["updateType"] == "CHANGE_VNFPKG": + if not ( + data["config"]["changeVnfPackageData"][0].get("vnfInstanceId") + and data["config"]["changeVnfPackageData"][0].get("vnfdId") + ): + raise ClientException("you must set both vnfInstanceId and vnfdId") + + # Fill up op_data + op_data["changeVnfPackageData"] = {} + op_data["changeVnfPackageData"]["vnfInstanceId"] = data["config"][ + "changeVnfPackageData" + ][0].get("vnfInstanceId") + + op_data["changeVnfPackageData"]["vnfdId"] = data["config"][ + "changeVnfPackageData" + ][0].get("vnfdId") + + if data.get("timeout"): + op_data["timeout_ns_update"] = data["timeout"] + + op_id = self.exec_op(ns_name, op_name="update", op_data=op_data, wait=wait) + print(str(op_id)) + + except ClientException as exc: + message = "failed to update ns {}:\nerror:\n{}".format(ns_name, str(exc)) + raise ClientException(message) + def create_alarm(self, alarm): self._logger.debug("") self._client.get_token() @@ -524,6 +576,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() @@ -562,3 +667,23 @@ class Ns(object): return nsr[field] raise NotFound("failed to find {} in ns {}".format(field, ns_name)) + + def heal( + self, + ns_name, + heal_dict, + wait=False, + timeout=None, + ): + """Heals a NS""" + self._logger.debug("") + self._client.get_token() + try: + op_data = heal_dict + if timeout: + op_data["timeout_ns_heal"] = timeout + op_id = self.exec_op(ns_name, op_name="heal", op_data=op_data, wait=wait) + print(str(op_id)) + except ClientException as exc: + message = "failed to heal ns {}:\nerror:\n{}".format(ns_name, str(exc)) + raise ClientException(message)