def instantiate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}/instantiate".format( self._base_path, nsId) _url = self._build_url_query(_url, args) instantiate_payload = {} ns_res, ns_head = self.get_ns(nsId, skip_sol=True) instantiate_payload.update(ns_res['instantiate_params']) args_payload = args['payload'] if args_payload and 'additionalParamsForNs' in args_payload: instantiate_payload.update(args_payload['additionalParamsForNs']) if 'vnf' in instantiate_payload: mapping = { v: str(i + 1) for i, v in enumerate(ns_res['constituent-vnfr-ref']) } for vnf in instantiate_payload['vnf']: if vnf.get('vnfInstanceId'): vnf['member-vnf-index'] = mapping[vnf.pop( 'vnfInstanceId')] if 'wim_account' not in instantiate_payload: instantiate_payload['wimAccountId'] = False try: empty_body, osm_headers = self._exec_post(_url, json=instantiate_payload, headers=self._headers) except ResourceNotFound as e: print(e) raise NsNotFound(ns_id=nsId) headers = self._build_headers(osm_headers) return None, headers
def instantiate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = '{0}/instantiate/{1}'.format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: empty_body, resp_headers = self._exec_post(_url, headers={}) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return None, headers
def scale_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}/scale".format( self._base_path, nsId) _url = self._build_url_query(_url, args) try: empty_body, osm_headers = self._exec_post(_url, json=args['payload'], headers=self._headers) except ResourceNotFound: raise NsNotFound(ns_id=id) headers = self._build_headers(osm_headers) return None, headers
def terminate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = '{0}/terminate/{1}'.format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: emtpy_body, resp_headers = self._exec_post( _url, json=args['payload'], headers={"Content-Type": "application/json"}) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return None, headers
def get_ns(self, nsId: str, args=None, skip_sol=False) \ -> Tuple[Body, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}".format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: osm_ns, osm_headers = self._exec_get(_url, headers=self._headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(osm_headers) if skip_sol: return osm_ns, headers sol_ns = self._ns_im_converter(osm_ns) return sol_ns, headers
def get_ns(self, nsId: str, args=None, skip_sol=False) -> Tuple[Body, Headers]: _url = '{0}/instances/{1}'.format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: ns_instance, resp_headers = self._exec_get(_url, headers=self._headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return ns_instance, headers
def delete_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}".format(self._base_path, nsId) _url = self._build_url_query(_url, args) req_headers = copy.deepcopy(self._headers) del req_headers["Content-Type"] del req_headers["Accept"] try: empty_body, osm_headers = self._exec_delete(_url, params=None, headers=req_headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(osm_headers) return None, headers
def get_op_list(self, args: Dict = None) -> Tuple[BodyList, Headers]: nsId = args['args']['nsInstanceId'] if args[ 'args'] and 'nsInstanceId' in args['args'] else None if nsId is None: _url = "{0}/ns_lcm_op_occs".format(self._base_path) _url = self._build_url_query(_url, args) op_list, resp_headers = self._exec_get(_url, headers=self._headers) else: _url = "{0}/ns_lcm_op_occs/ns_id/{1}".format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: op_list, resp_headers = self._exec_get(_url, headers=self._headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return op_list, headers
def instantiate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}/instantiate".format( self._base_path, nsId) _url = self._build_url_query(_url, args) instantiate_payload = {} ns_res, ns_head = self.get_ns(nsId, skip_sol=True) instantiate_payload.update(ns_res['instantiate_params']) additional_params = None try: additional_params = args['payload']['additionalParamsForNs'] except (TypeError, KeyError): logger.info('no additionalParamsForNs') if additional_params: if 'vld' in additional_params: instantiate_payload['vld'] = additional_params['vld'] if 'vnf' in additional_params: mapping = { v: str(i + 1) for i, v in enumerate(ns_res['constituent-vnfr-ref']) } try: for vnf in additional_params['vnf']: vnf['member-vnf-index'] = mapping[vnf.pop( 'vnfInstanceId')] instantiate_payload['vnf'] = additional_params['vnf'] except KeyError as e: logger.warning('cannot map vnf. KeyError on {}'.format(e)) if 'wim_account' in additional_params: instantiate_payload['wimAccountId'] = additional_params[ 'wimAccountId'] else: instantiate_payload['wimAccountId'] = False try: empty_body, osm_headers = self._request(post, _url, json=instantiate_payload, headers=self._headers) except ResourceNotFound as e: print(e) raise NsNotFound(ns_id=nsId) headers = self._build_headers(osm_headers) return None, headers