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 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, headers={}) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return None, headers
def delete_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]: _url = '{0}/delete/{1}'.format(self._base_path, nsId) _url = self._build_url_query(_url, args) try: empty_body, resp_headers = self._exec_delete( _url, params=None, 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._request(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 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._request(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 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) instantiate_payload = {} try: instantiate_payload['SapData'] = args['payload']['SapData'] except (TypeError, KeyError): logger.info('no SapData') try: empty_body, resp_headers = self._exec_post( _url, json=instantiate_payload, headers={}) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return None, 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'] vnf_items = self._force_float_ip(additional_params['vld'], ns_res) self._extend_vnf_add_params(instantiate_payload, vnf_items) 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')] self._extend_vnf_add_params(instantiate_payload, 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
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 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) req_headers = copy.deepcopy(self._headers) try: del req_headers["Content-Type"] except KeyError: pass try: del req_headers["Accept"] except KeyError: pass try: emtpy_body, resp_headers = self._exec_post(_url, headers=req_headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(resp_headers) return None, headers
def terminate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]: _url = "{0}/nslcm/v1/ns_instances/{1}/terminate".format( self._base_path, nsId) _url = self._build_url_query(_url, args) req_headers = copy.deepcopy(self._headers) try: del req_headers["Content-Type"] except KeyError: pass try: del req_headers["Accept"] except KeyError: pass try: emtpy_body, osm_headers = self._request(post, _url, headers=req_headers) except ResourceNotFound: raise NsNotFound(ns_id=nsId) headers = self._build_headers(osm_headers) return None, headers