- self._apiResource = '/ns_instances'
- self._apiBase = '{}{}{}'.format(self._apiName,
- self._apiVersion, self._apiResource)
- endpoint = '{}/{}/{}'.format(self._apiBase, ns['_id'], op_name)
- #print 'OP_NAME: {}'.format(op_name)
- #print 'OP_DATA: {}'.format(json.dumps(op_data))
- http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
- #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))
- print(resp['id'])
+ ns = self.get(name)
+ self._apiResource = "/ns_instances"
+ self._apiBase = "{}{}{}".format(
+ self._apiName, self._apiVersion, self._apiResource
+ )
+ endpoint = "{}/{}/{}".format(self._apiBase, ns["_id"], op_name)
+ # print('OP_NAME: {}'.format(op_name))
+ # print('OP_DATA: {}'.format(json.dumps(op_data)))
+ http_code, resp = self._http.post_cmd(
+ endpoint=endpoint, postfields_dict=op_data
+ )
+ # 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 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 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"