def scale(self, ns_uuid, scaling_group_id, index): """Scale a NS record by given NS ID and scaling group ID Args: ns_uuid (str): The ID of the network service scaling_group_id (str): The ID of the scaling group as defined in the NS descriptor index (str): The ID of the triggered vnf Returns: obj: a requests object Examples: >>> from soapi.nsr import Nsr >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Nsr(token) >>> scaled_ns = ns.scale('xxx', 'scaling-group-1', '2134') >>> print(int(scaled_ns.status_code)) 200 """ endpoint = '{}/v1/api/config/project/default/ns-instance-config/nsr/{}/scaling-group/{}/instance'.format( OSM_COMPONENTS.get('SO-API'), ns_uuid, scaling_group_id) headers = { "Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({"instance": [{"id": str(index)}]}) response = self.__client.post(endpoint, headers, payload) return response
def terminate(self, ns_uuid): """Terminate a running NS Args: ns_uuid (str, uuid): The ID of the network service Returns: obj: a requests object Examples: >>> from soapi.nsr import Nsr >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Nsr(token) >>> ns_instance = ns.terminate("32798fec-b042-11e8-a05b-fa163e682738") >>> print(ns_instance.status_code) 201 >>> print(ns_instance.text) {"success":""} """ endpoint = '{}/api/config/project/default/ns-instance-config/nsr/{}'.format( OSM_COMPONENTS.get('SO-API'), ns_uuid) headers = { "Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json" } response = self.__client.delete(endpoint, headers=headers) return response
def get(self, ns_uuid): """Get details for a NS record from the SO-ub container Args: ns_uuid (str): The ID of the network service Returns: obj: a requests object Examples: >>> from soapi.nsr import Nsr >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Nsr(token) >>> ns_record = ns.get('xxx') >>> print(int(ns_record.status_code)) 200 """ endpoint = '{}/api/operational/project/default/ns-instance-opdata/nsr/{}?deep'.format( OSM_COMPONENTS.get('SO-API'), ns_uuid) headers = { "Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get(self, vnf_uuid=None): """Fetch details of a specific VNF Args: vnf_uuid (str): The UUID of the VNF to fetch details for Returns: object: A requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.vnf import Vnf >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vnf = Vnf(token) >>> response = vnf.get(vnf_uuid='a5f506e9-45c7-42fd-b12d-b5c657ed87fb') OSM Cli: $ osm vnf-show a5f506e9-45c7-42fd-b12d-b5c657ed87fb """ endpoint = '{}/osm/nslcm/v1/vnf_instances/{}'.format(OSM_COMPONENTS.get('NBI-API'), vnf_uuid) headers = {"Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json"} response = self.__client.get(endpoint, headers) logger.debug("Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, ns_uuid=None): """Fetch details of a specific NS Instance Args: ns_uuid (str): The UUID of the NS to fetch details for Returns: object: A requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.ns import Ns >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Ns(token) >>> response = ns.get(ns_uuid='07048175-660b-404f-bbc9-5be7581e74de') OSM Cli: $ osm ns-show 07048175-660b-404f-bbc9-5be7581e74de """ endpoint = '{}/osm/nslcm/v1/ns_instances/{}'.format( OSM_COMPONENTS.get('NBI-API'), ns_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, vnfd_uuid=None): """Fetch details of a specific VNF descriptor. Args: vnfd_uuid (str): The UUID of the VNFD to fetch details for. Returns: object: A requests object. Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.vnfd import Vnfd >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('password')) >>> vnfd = Vnfd(token) >>> response = vnfd.get(vnfd_uuid='89f66f1b-73b5-4dc1-8226-a473a2615627') OSM Cli: $ osm vnfd-show cirros_vnf """ endpoint = '{}/osm/vnfpkgm/v1/vnf_packages/{}'.format( OSM_COMPONENTS.get('NBI-API'), vnfd_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get_list(self): """Fetch the list of operations Returns: object: A requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.operation import NsLcmOperation >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns_operation = NsLcmOperation(token) >>> request = ns_operation.get_list() >>> print(request.status_code) 200 """ endpoint = '{}/osm/nslcm/v1/ns_lcm_op_occs'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json", "Content-Type": "application/json" } response = self.__client.list(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, vim_account_uuid=None): """Get details for a project in OSM r4 by given project ID Args: vim_account_uuid (str): The Vim Account UUID Returns: obj: a requests object Examples: >>> from nbi_api.identity import bearer_token >>> from nbi_api.vim_account import VimAccount >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vim_account = VimAccount(token) >>> entry = vim_account.get("41dab0c0-35f4-4c40-b1cd-13e4a79dab48") >>> print(entry.status_code) 200 >>> assert type(entry.json()) is dict >>> print(entry.json()) {...} """ endpoint = '{}/osm/admin/v1/vim_accounts/{}'.format( OSM_COMPONENTS.get('NBI-API'), vim_account_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get_list(self): """Get the list of the registered vim accounts in OSM r4 Returns: obj: a requests object Examples: >>> from nbi_api.identity import bearer_token >>> from nbi_api.vim_account import VimAccount >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vim_account = VimAccount(token) >>> entries = vim_account.get_list() >>> print(entries.status_code) 200 >>> assert type(entries.json()) is list >>> print(entries.json()) [] """ endpoint = '{}/osm/admin/v1/vim_accounts'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get_list_by_ns(self, ns_uuid=None): """Fetch list of VNFs for specific NS Instance. Args: ns_uuid (str): The UUID of the NS to fetch VNFs for. Returns: object: A requests object. Examples: >>> from nbi_api.identity import bearer_token >>> from nbi_api.vnf import Vnf >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vnf = Vnf(token) >>> response = vnf.get_list_by_ns(ns_uuid='790dab2d-cb18-43d1-86df-09738b60dc26') >>> print(response.status_code) 200 >>> assert type(response.json()) is list >>> print(response.json()) [...] """ endpoint = '{}/osm/nslcm/v1/vnf_instances?nsr-id-ref={}'.format( OSM_COMPONENTS.get('NBI-API'), ns_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, vim_account_uuid=None): """Get details for a project in OSM r4 by given project ID Args: vim_account_uuid (str): The Vim Account UUID Returns: obj: a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.vim_account import VimAccount >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vim_account = VimAccount(token) >>> entry = vim_account.get("66000170-7fe9-4ab0-b113-b60a92ee196c") >>> print(entry.json()) """ endpoint = '{}/osm/admin/v1/vim_accounts/{}'.format( OSM_COMPONENTS.get('NBI-API'), vim_account_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get_list(self): """Fetch a list of all NS Instances Returns: object: A list of NSs as a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.ns import Ns >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Ns(token) >>> response = ns.get_list() >>> print(response.json()) OSM Cli: $ osm ns-list """ endpoint = '{}/osm/nslcm/v1/ns_instances'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get_list(self): """Fetch a list of all VNFs. Returns: object: A requests object Examples: >>> from nbi_api.identity import bearer_token >>> from nbi_api.vnf import Vnf >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vnf = Vnf(token) >>> response = vnf.get_list() >>> print(response.status_code) 200 >>> assert type(response.json()) is list >>> print(response.json()) [...] OSM Cli: $ osm vnf-list """ endpoint = '{}/osm/nslcm/v1/vnf_instances'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get_list(self): """Fetch a list of the VNF descriptors. Returns: object: A requests object that includes the list of VNFDs Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.vnfd import Vnfd >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('password')) >>> vnfd = Vnfd(token) >>> response = vnfd.get_list() OSM Cli: $ osm vnfd-list """ endpoint = '{}/osm/vnfpkgm/v1/vnf_packages'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, nsd_uuid=None): """Fetch details of a specific NS descriptor. Args: nsd_uuid (str): The UUID of the NSD to fetch details for. Returns: object: A requests object including the NSD Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.nsd import Nsd >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> nsd = Nsd(token) >>> response = nsd.get(nsd_uuid='9c4a8f58-8317-40a1-b9fe-1db18cff6965') OSM Cli: $ osm nsd-show cirros_2vnf_ns """ endpoint = '{}/osm/nsd/v1/ns_descriptors/{}'.format( OSM_COMPONENTS.get('NBI-API'), nsd_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get_list(self): """Fetch a list of all NS descriptors. Returns: object: A requests object including the list of the NSDs Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.nsd import Nsd >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> nsd = Nsd(token) >>> response = nsd.get_list() >>> print(response.status_code) 200 OSM Cli: $ osm nsd-list """ endpoint = '{}/osm/nsd/v1/ns_descriptors'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get(self, operation_uuid=None): """Fetch details of a specific operation Args: operation_uuid (str): The UUID of the performed operation Returns: object: A requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.operation import NsLcmOperation >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns_operation = NsLcmOperation(token) >>> request = ns_operation.get(operation_uuid='7a1bd53e-af29-40d6-bbde-ee8be69ddc3e') >>> print(request.status_code) 200 """ endpoint = '{}/osm/nslcm/v1/ns_lcm_op_occs/{}'.format( OSM_COMPONENTS.get('NBI-API'), operation_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json", "Content-Type": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def instantiate(self, ns_descriptor, nsr_name, vim_account_name, admin_status="ENABLED"): """Instantiate a new NS based on NS descriptor and considering the given (by user) NS name and VIM name Args: ns_descriptor (dict): The NS descriptor nsr_name (str): The NS name vim_account_name (str): The VIM name Returns: obj: a requests object Examples: >>> from soapi.nsr import Nsr >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Nsr(token) >>> ns_descriptor = {"name": "cirros_2vnf_ns", "constituent-vnfd": [{"member-vnf-index": 1, "vnfd-id-ref": "cirros_vnfd", "start-by-default": "true"}, {"member-vnf-index": 2, "vnfd-id-ref": "cirros_vnfd", "start-by-default": "true"} ], "description": "Generated by OSM pacakage generator", "short-name": "cirros_2vnf_ns", "id": "cirros_2vnf_nsd", "version": "1.0", "vld": [{"name": "cirros_2vnf_nsd_vld1", "vnfd-connection-point-ref": [{"vnfd-connection-point-ref": "eth0", "vnfd-id-ref": "cirros_vnfd", "member-vnf-index-ref": 1 }, {"vnfd-connection-point-ref": "eth0", "vnfd-id-ref": "cirros_vnfd", "member-vnf-index-ref": 2 } ], "short-name": "cirros_2vnf_nsd_vld1", "mgmt-network": "true", "id": "cirros_2vnf_nsd_vld1", "type": "ELAN"} ], "logo": "osm_2x.png", "vendor": "OSM"} >>> ns_instance = ns.instantiate(ns_descriptor, "cirros_2vnf_ns_test", "devstack-ocata") >>> print(int(ns_instance.status_code)) >>> print(ns_instance.text) """ endpoint = '{}/api/config/project/default/ns-instance-config/nsr'.format( OSM_COMPONENTS.get('SO-API')) headers = { "Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json", "Content-Type": "application/json" } nsr_id = str(uuid.uuid1()) payload = { "nsr": [{ "short-name": nsr_name, "datacenter": vim_account_name, "description": nsr_name, "resource-orchestrator": "osmopenmano", "nsd": ns_descriptor, "admin-status": admin_status, "id": nsr_id, "name": nsr_name }] } response = self.__client.post(endpoint, headers=headers, payload=json.dumps(payload)) return response
def get(self, username=None): """Get details of a user in OSM r4 by given username Returns: obj: a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.user import User >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> user = User(token) >>> response = user.get(username="******") >>> print(response.json()) """ endpoint = '{}/osm/admin/v1/users/{}'.format(OSM_COMPONENTS.get('NBI-API'), username) headers = {"Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json"} response = self.__client.get(endpoint, headers) return response
def get(self, vim_uuid=None): """Get details for a VIM in OSM r4 by given VIM UUID Returns: obj: a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.vim import Vim >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vim = Vim(token) >>> vim_account = vim.get("41dab0c0-35f4-4c40-b1cd-13e4a79dab48") >>> print(vim_account.json()) """ endpoint = '{}/osm/admin/v1/vim_accounts/{}'.format(OSM_COMPONENTS.get('NBI-API'), vim_uuid) headers = {"Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json"} response = self.__client.get(endpoint, headers) return response
def bearer_token(username, password): """Get bearer authorization token from OSM r4 Args: username (str): The admin OSM r4 username password (str): The admin OSM r4 password Returns: token (str): An authorization token Examples: >>> from nbiapi.identity import bearer_token >>> from settings import OSM_COMPONENTS >>> token = bearer_token("admin", "admin") >>> assert type(token) is str """ if not isinstance(username, str): raise TypeError( "The given type of username is `{}`. Expected str.".format( type(username))) if not isinstance(password, str): raise TypeError( "The given type of password is `{}`. Expected str.".format( type(password))) endpoint = '{}/osm/admin/v1/tokens'.format(OSM_COMPONENTS.get('NBI-API')) params = {'username': username, 'password': password} headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' } response = requests.post(url=endpoint, params=params, headers=headers, verify=False) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) if response.status_code == 200: return response.json()['id'] return None
def get_list(self): """Get the list of the NS descriptors from the SO-ub container Returns: obj: a requests object Examples: >>> from soapi.nsd import Nsd >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> nsd = Nsd(token) >>> nsd_records = nsd.get_list() >>> print(int(nsd_records.status_code)) 200 """ endpoint = '{}/api/running/project/default/nsd-catalog/nsd'.format(OSM_COMPONENTS.get('SO-API')) headers = {"Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json"} response = self.__client.get(endpoint, headers) return response
def get_list(self): """Get the list of the registered Projects in OSM r4 Returns: obj: a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.project import Project >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> project = Project(token) >>> entries = project.get_list() >>> print(entries.json()) """ endpoint = '{}/osm/admin/v1/projects'.format( OSM_COMPONENTS.get('NBI-API')) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get(self, project_id=None): """Get details for a project in OSM r4 by given project ID Returns: obj: a requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.project import Project >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> project = Project(token) >>> entry = project.get("admin") >>> print(entry.json()) """ endpoint = '{}/osm/admin/v1/projects/{}'.format( OSM_COMPONENTS.get('NBI-API'), project_id) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def get(self, vnf_uuid=None): """Fetch details of a specific VNF Args: vnf_uuid (str): The UUID of the VNF to fetch details for Returns: object: A requests object Examples: >>> from nbi_api.identity import bearer_token >>> from nbi_api.vnf import Vnf >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vnf = Vnf(token) >>> response = vnf.get(vnf_uuid='71bd6f55-162d-408f-b498-6e182b91e5b6') >>> print(response.status_code) 200 >>> assert type(response.json()) is dict >>> print(response.json()) {...} OSM Cli: $ osm vnf-show 71bd6f55-162d-408f-b498-6e182b91e5b6 """ endpoint = '{}/osm/nslcm/v1/vnf_instances/{}'.format( OSM_COMPONENTS.get('NBI-API'), vnf_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) logger.debug( "Request `GET {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response
def get_list(self): """Get the list of the VNF records from the SO-ub container Returns: obj: a requests object Examples: >>> from soapi.vnfr import Vnfr >>> from soapi.identity import basic_token >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = basic_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> vnfr = Vnfr(token) >>> vnfrs = vnfr.get_list() >>> print(int(vnfrs.status_code)) 200 """ endpoint = '{}/v1/api/operational/project/default/vnfr-catalog/vnfr'.format( OSM_COMPONENTS.get('SO-API')) headers = { "Authorization": "Basic {}".format(self.basic_token), "Accept": "application/json" } response = self.__client.get(endpoint, headers) return response
def scale_vnf(self, ns_uuid, vnf_index, scaling_group_name, scale_out=True): """ Scale in or out in VNF level Args: ns_uuid (str): The NS uuid vnf_index (int): The VNF index to be scaled scaling_group_name (str): The name in the VNF scaling_group_descriptor scale_out (bool): Decide scale in or out action. By default, scale out is performed. Returns: object: A requests object Examples: >>> from nbiapi.identity import bearer_token >>> from nbiapi.ns import Ns >>> from settings import OSM_ADMIN_CREDENTIALS >>> token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) >>> ns = Ns(token) >>> response = ns.scale_vnf(ns_uuid="199b1fcd-eb32-4c6f-b149-34410acc2a32", vnf_index=2, scaling_group_name="scale_by_one", scale_out=False) # >>> response = ns.scale_vnf(ns_uuid="199b1fcd-eb32-4c6f-b149-34410acc2a32", vnf_index=2, scaling_group_name="scale_by_one", scale_out=False) OSM Cli: $ osm vnf-scale <ns_uuid> <vnf_index> --scale-in # scale in Scaling group: <scaling_group_name> $ osm vnf-scale <ns_uuid> <vnf_index> --scale-out # scale out (default) Scaling group: <scaling_group_name> """ endpoint = '{}/osm/nslcm/v1/ns_instances/{}/scale'.format( OSM_COMPONENTS.get('NBI-API'), ns_uuid) headers = { "Authorization": "Bearer {}".format(self.bearer_token), "Accept": "application/json" } # Set value based on scale action scale_action = "SCALE_IN" if scale_out: scale_action = "SCALE_OUT" payload = { "scaleVnfData": { "scaleVnfType": scale_action, "scaleByStepData": { "member-vnf-index": str(vnf_index), "scaling-group-descriptor": str(scaling_group_name) } }, "scaleType": "SCALE_VNF" } response = self.__client.post(endpoint, headers, payload=json.dumps(payload)) logger.debug( "Request `POST {}` returns HTTP status `{}`, headers `{}` and body `{}`." .format(response.url, response.status_code, response.headers, response.text)) return response