From 584d4dddac3675c1283ba8081a57601bd0efd6c1 Mon Sep 17 00:00:00 2001 From: AlexJoom Date: Wed, 2 Nov 2022 13:46:47 +0200 Subject: [PATCH 1/4] update service discovered to use the latest version of NEF --- HISTORY.rst | 4 +++ evolved5g/__init__.py | 2 +- evolved5g/sdk.py | 18 ++++++++---- .../api/session_with_qo_s_api_api.py | 10 +++---- .../service_api_description.json | 28 ++++--------------- examples/netapp_capif_connector_examples.py | 2 +- examples/qos_awereness_examples.py | 8 ++++-- setup.cfg | 2 +- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 067434a..7f97ca0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,10 @@ ======= History ======= +0.8.5 (2022-10-27) +------------------- +* Update of the SDK library to be compatible with the latest release of NEF v1.6.1 + 0.8.4 (2022-10-27) ------------------- * The SDK Library now communicates first with CAPIF server in order to discover the NEF endpoints diff --git a/evolved5g/__init__.py b/evolved5g/__init__.py index fc9881a..f9c4380 100644 --- a/evolved5g/__init__.py +++ b/evolved5g/__init__.py @@ -1,7 +1,7 @@ """Top-level package for Evolved5G_CLI.""" __author__ = "EVOLVED5G project" -__version__ = '0.8.4' +__version__ = '0.8.5' # Uncomment next lines to give direct import access to modules #from . import cli diff --git a/evolved5g/sdk.py b/evolved5g/sdk.py index caf128e..53cd419 100644 --- a/evolved5g/sdk.py +++ b/evolved5g/sdk.py @@ -29,9 +29,9 @@ def __init__(self, host: str, configuration.access_token = nef_bearer_access_token service_discoverer = ServiceDiscoverer(folder_path_for_certificates_and_capif_api_key,capif_host,capif_https_port) configuration.available_endpoints = { - "MONITORING_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", + "MONITORING_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("/nef/api/v1/3gpp-monitoring-event/", "MONITORING_SUBSCRIPTIONS"), - "MONITORING_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", + "MONITORING_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("/nef/api/v1/3gpp-monitoring-event/", "MONITORING_SUBSCRIPTION_SINGLE"), } api_client = swagger_client.ApiClient(configuration=configuration) @@ -453,8 +453,8 @@ def __init__(self, nef_url: str, configuration.access_token = nef_bearer_access_token service_discoverer = ServiceDiscoverer(folder_path_for_certificates_and_capif_api_key,capif_host,capif_https_port) configuration.available_endpoints = { - "QOS_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", "QOS_SUBSCRIPTIONS"), - "QOS_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", "QOS_SUBSCRIPTION_SINGLE") + "QOS_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("/nef/api/v1/3gpp-as-session-with-qos/", "QOS_SUBSCRIPTIONS"), + "QOS_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("/nef/api/v1/3gpp-as-session-with-qos/", "QOS_SUBSCRIPTION_SINGLE") } api_client = swagger_client.ApiClient(configuration=configuration) self.qos_api = SessionWithQoSAPIApi(api_client) @@ -1154,7 +1154,15 @@ def retrieve_specific_resource_name(self, api_name,resource_name): if len(uris)==0: raise ServiceDiscoverer.ServiceDiscovererException("Could not find resource_name: "+ resource_name + "at api_name" + api_name) else: - return uris[0]["uri"] + uri = uris[0]["uri"] + #make sure the uri starts with / + if not uri.startswith('/'): + uri = "/" + uri + #make sure the API doesn't have a trailing / + if api_name.endswith("/"): + api_name = api_name[:-1] + # construct the url + return api_name + uri diff --git a/evolved5g/swagger_client/api/session_with_qo_s_api_api.py b/evolved5g/swagger_client/api/session_with_qo_s_api_api.py index 92c1343..03c5e20 100644 --- a/evolved5g/swagger_client/api/session_with_qo_s_api_api.py +++ b/evolved5g/swagger_client/api/session_with_qo_s_api_api.py @@ -130,7 +130,7 @@ def create_subscription_api_v13gpp_as_session_with_qos_v1_scs_as_id_subscription auth_settings = ['OAuth2PasswordBearer'] # noqa: E501 return self.api_client.call_api( - self.api_client.configuration["QOS_SUBSCRIPTIONS"], 'POST', + self.api_client.configuration.available_endpoints["QOS_SUBSCRIPTIONS"], 'POST', path_params, query_params, header_params, @@ -242,7 +242,7 @@ def delete_subscription_api_v13gpp_as_session_with_qos_v1_scs_as_id_subscription auth_settings = ['OAuth2PasswordBearer'] # noqa: E501 return self.api_client.call_api( - self.api_client.configuration["QOS_SUBSCRIPTION_SINGLE"], 'DELETE', + self.api_client.configuration.available_endpoints["QOS_SUBSCRIPTION_SINGLE"], 'DELETE', path_params, query_params, header_params, @@ -344,7 +344,7 @@ def read_active_subscriptions_api_v13gpp_as_session_with_qos_v1_scs_as_id_subscr auth_settings = ['OAuth2PasswordBearer'] # noqa: E501 return self.api_client.call_api( - self.api_client.configuration["QOS_SUBSCRIPTIONS"], 'GET', + self.api_client.configuration.available_endpoints["QOS_SUBSCRIPTIONS"], 'GET', path_params, query_params, header_params, @@ -455,7 +455,7 @@ def read_subscription_api_v13gpp_as_session_with_qos_v1_scs_as_id_subscriptions_ auth_settings = ['OAuth2PasswordBearer'] # noqa: E501 return self.api_client.call_api( - self.api_client.configuration["QOS_SUBSCRIPTION_SINGLE"], 'GET', + self.api_client.configuration.available_endpoints["QOS_SUBSCRIPTION_SINGLE"], 'GET', path_params, query_params, header_params, @@ -580,7 +580,7 @@ def update_subscription_api_v13gpp_as_session_with_qos_v1_scs_as_id_subscription auth_settings = ['OAuth2PasswordBearer'] # noqa: E501 return self.api_client.call_api( - self.api_client.configuration["QOS_SUBSCRIPTION_SINGLE"], 'PUT', + self.api_client.configuration.available_endpoints["QOS_SUBSCRIPTION_SINGLE"], 'PUT', path_params, query_params, header_params, diff --git a/examples/capif_exposer_sample_files/service_api_description.json b/examples/capif_exposer_sample_files/service_api_description.json index 27f1ea4..4b79ac3 100644 --- a/examples/capif_exposer_sample_files/service_api_description.json +++ b/examples/capif_exposer_sample_files/service_api_description.json @@ -1,5 +1,5 @@ { - "apiName": "nef_emulator_endpoints", + "apiName": "/nef/api/v1/3gpp-monitoring-event/", "aefProfiles": [ { "aefId": "string", @@ -11,36 +11,19 @@ { "resourceName": "MONITORING_SUBSCRIPTIONS", "commType": " SUBSCRIBE_NOTIFY", - "uri": "/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions", + "uri": "/{scsAsId}/subscriptions", "custOpName": "http_post", - "operations": ["GET","POST","PUT","DELETE"], + "operations": ["GET","POST"], "description": "Endpoint to manage monitoring subscriptions" }, { "resourceName": "MONITORING_SUBSCRIPTION_SINGLE", "commType": " SUBSCRIBE_NOTIFY", - "uri": "/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions/{subscriptionId}", + "uri": "/{scsAsId}/subscriptions/{subscriptionId}", "custOpName": "http_get", - "operations": [ "GET","POST" ], - "description": "Endpoint to manage single subscription" - }, - { - "resourceName": "QOS_SUBSCRIPTIONS", - "commType": " SUBSCRIBE_NOTIFY", - "uri": "/nef/api/v1/3gpp-as-session-with-qos/v1/{scsAsId}/subscriptions", - "custOpName": "http_post", - "operations": ["GET","POST","PUT","DELETE"], - "description": "Endpoint to manage monitoring subscriptions" - }, - { - "resourceName": "QOS_SUBSCRIPTION_SINGLE", - "commType": " SUBSCRIBE_NOTIFY", - "uri": "/nef/api/v1/3gpp-as-session-with-qos/v1/{scsAsId}/subscriptions/{subscriptionId}", - "custOpName": "http_get", - "operations": [ "GET","POST" ], + "operations": ["GET","PUT","DELETE"], "description": "Endpoint to manage single subscription" } - ], "custOperations": [ { @@ -83,4 +66,3 @@ }, "ccfId": "string" } - diff --git a/examples/netapp_capif_connector_examples.py b/examples/netapp_capif_connector_examples.py index 6c9cb6e..449aabe 100644 --- a/examples/netapp_capif_connector_examples.py +++ b/examples/netapp_capif_connector_examples.py @@ -35,5 +35,5 @@ def showcase_service_discovery(): print(endpoints) if __name__ == "__main__": - showcase_capif_connector() + #showcase_capif_connector() showcase_service_discovery() diff --git a/examples/qos_awereness_examples.py b/examples/qos_awereness_examples.py index 7fc2d9d..4df0808 100644 --- a/examples/qos_awereness_examples.py +++ b/examples/qos_awereness_examples.py @@ -144,9 +144,11 @@ def showcase_create_non_quaranteed_bit_rate_subscription_for_live_streaming(): def read_and_delete_all_existing_subscriptions(): # How to get all subscriptions netapp_id = "myNetapp" - host = emulator_utils.get_url_of_the_nef_emulator() - token = emulator_utils.get_token_for_nef_emulator() - qos_awareness = QosAwareness(host, token.access_token) + qos_awareness = QosAwareness(nef_url=emulator_utils.get_url_of_the_nef_emulator(), + nef_bearer_access_token= emulator_utils.get_token_for_nef_emulator().access_token, + folder_path_for_certificates_and_capif_api_key=emulator_utils.get_folder_path_for_certificated_and_capif_api_key(), + capif_host=emulator_utils.get_capif_host(), + capif_https_port=emulator_utils.get_capif_https_port()) try: all_subscriptions = qos_awareness.get_all_subscriptions(netapp_id) diff --git a/setup.cfg b/setup.cfg index 7d57281..07212ae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.8.4 +current_version = 0.8.5 commit = True tag = True From a657ee393e2e86c048dbb5bc1cd19eecea8eeada Mon Sep 17 00:00:00 2001 From: AlexJoom Date: Wed, 2 Nov 2022 14:14:06 +0200 Subject: [PATCH 2/4] bug fix on constructing the endpoint from service discoverer --- evolved5g/sdk.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/evolved5g/sdk.py b/evolved5g/sdk.py index 53cd419..b0276b1 100644 --- a/evolved5g/sdk.py +++ b/evolved5g/sdk.py @@ -1149,8 +1149,11 @@ def retrieve_specific_resource_name(self, api_name,resource_name): raise ServiceDiscoverer.ServiceDiscovererException("Could not find available endpoints for api_name: " + api_name + ".Make sure that a) your NetApp is registered and onboarded to CAPIF and b) the NEF emulator has been registered and onboarded to CAPIF") else: - resources = nef_endpoints[0]["aef_profiles"][0]["versions"][0]["resources"] + version_dictionary = nef_endpoints[0]["aef_profiles"][0]["versions"][0] + version = version_dictionary["api_version"] + resources = version_dictionary["resources"] uris = (list(filter(lambda resource: resource["resource_name"] == resource_name , resources))) + if len(uris)==0: raise ServiceDiscoverer.ServiceDiscovererException("Could not find resource_name: "+ resource_name + "at api_name" + api_name) else: @@ -1162,7 +1165,7 @@ def retrieve_specific_resource_name(self, api_name,resource_name): if api_name.endswith("/"): api_name = api_name[:-1] # construct the url - return api_name + uri + return api_name + "/" + version + uri From b596ea3c02987f19b1e0b659857bf33bc65a64ca Mon Sep 17 00:00:00 2001 From: AlexJoom Date: Wed, 2 Nov 2022 14:16:52 +0200 Subject: [PATCH 3/4] bug fix on example --- examples/qos_awereness_examples.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/qos_awereness_examples.py b/examples/qos_awereness_examples.py index 4df0808..fff2095 100644 --- a/examples/qos_awereness_examples.py +++ b/examples/qos_awereness_examples.py @@ -97,9 +97,11 @@ def showcase_create_non_quaranteed_bit_rate_subscription_for_live_streaming(): # Create a subscription, that will notify us 1000 times, for the next 1 day starting from now netapp_id = "myNetapp" - host = emulator_utils.get_url_of_the_nef_emulator() - token = emulator_utils.get_token_for_nef_emulator() - qos_awereness = QosAwareness(host, token.access_token) + qos_awereness = QosAwareness(nef_url=emulator_utils.get_url_of_the_nef_emulator(), + nef_bearer_access_token= emulator_utils.get_token_for_nef_emulator().access_token, + folder_path_for_certificates_and_capif_api_key=emulator_utils.get_folder_path_for_certificated_and_capif_api_key(), + capif_host=emulator_utils.get_capif_host(), + capif_https_port=emulator_utils.get_capif_https_port()) # The following external identifier was copy pasted by the NEF emulator. Go to the Map and hover over a User icon. # There you can retrieve the id address equipment_network_identifier = "10.0.0.3" From 240772c995cc45e897a02d37060d4c08121a06ec Mon Sep 17 00:00:00 2001 From: AlexJoom Date: Thu, 3 Nov 2022 13:37:49 +0200 Subject: [PATCH 4/4] change version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fedb978..f750c34 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/EVOLVED-5G/SDK-CLI', - version='0.8.4', + version='0.8.5', zip_safe=False, )