+ if not resp or "id" not in resp:
+ raise ClientException(
+ "unexpected response from server - {}".format(resp)
+ )
+ if wait:
+ # Wait for status for NS instance action
+ # For the 'action' operation, 'id' is used
+ self._wait(resp.get("id"), wait)
+ return resp["id"]
+ # else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException(msg)
+ except ClientException as exc:
+ message = "failed to exec operation {}:\nerror:\n{}".format(name, str(exc))
+ raise ClientException(message)
+
+ def cancel_op(self, operation_id, cancel_mode, wait=False):
+ """Cancels an LCM operation"""
+ self._client.get_token()
+ self._apiResource = "/ns_lcm_op_occs"
+ self._apiBase = "{}{}{}".format(
+ self._apiName, self._apiVersion, self._apiResource
+ )
+ endpoint = "{}/{}/cancel".format(self._apiBase, operation_id)
+ op_data = {"cancelMode": cancel_mode}
+ try:
+ http_code, resp = self._http.post_cmd(
+ endpoint=endpoint, postfields_dict=op_data
+ )
+ if http_code == 202:
+ if wait:
+ self._wait(operation_id, wait, deleteFlag=True, entity="OPCANCEL")
+ else:
+ print("Cancellation in progress")
+ else:
+ msg = resp or ""
+ raise ClientException(msg)
+ except ClientException as exc:
+ message = "failed to exec operation {}:\nerror:\n{}".format(
+ operation_id, str(exc)
+ )
+ raise ClientException(message)
+
+ def scale_vnf(
+ self,
+ ns_name,
+ vnf_name,
+ scaling_group,
+ scale_in,
+ scale_out,
+ wait=False,
+ timeout=None,
+ ):
+ """Scales a VNF by adding/removing VDUs"""
+ self._logger.debug("")
+ self._client.get_token()
+ try:
+ op_data = {}
+ op_data["scaleType"] = "SCALE_VNF"
+ op_data["scaleVnfData"] = {}
+ if scale_in and not scale_out:
+ op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_IN"
+ elif not scale_in and scale_out:
+ op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_OUT"