{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to develop a MEC application using the MEC Sandbox HTTP REST API\n", "\n", "## Table of contents\n", "\r\n", "1. What is a MEC applicationn](what_is_a_mec_applicationn)\r\n", "2. The basics of developing a MEC applicationh](the_basics_of_developing_a_mec_application)\n", "3. [Use the MEC Sandbox HTTP REST API models and code](#use_the_mec_sandbox_http_rest_api_models_and_code)\n", "4. [Create our first MEC application](#create_our_first_mec_application)\n", " 4.1. [The login function](#the_login_function)\n", " 4.2. [The logout function](#the_logout_function)\n", "5. [Second step: Retrieve the list of network scenarios](#second_step_retrieve_the_list_of_network_scenarios)\n", "6. [Third step: Activate and deactivate a network scenario](#third_step_activate_and_deactivate_a_network_scenario)\n", " 6.1. [The activate function](#the_activate_function)\n", " 6.2. [The deactivate function](#thedeactivate_function)\n", "7. [Fourth step: Create and delete an appliction instance id](#fourth_step_create_and_delete_an_appliction_instance_id)\n", "8. [MEC Registration and the READY indication](#mec_registration_and_the_ready_indication)\n", "9. [Annexes](#annexes)\n", "10. [Bibliography](#bibliograp)t\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is a MEC application\n", "\n", "See [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The basics of developing a MEC application\n", "\n", "The developement of a MEC application follows a strict process in order to access the ETSI MEC services and provides valueable services to the customers.\n", "Mainly, this process can be split in several steps:\n", "1. Global initializations (constant, variables...)\n", "2. Create of a new instance of a MEC Sandbox (Note that using an existing one could be a solution too (see Annex A)\n", "3. Activate a network scenario in order to access the ETSI MEC services\n", "4. Create a new application identifier\n", "5. Register our MEC application and subscribe to service termination (see MEC 011)\n", "6. Use MEC services in order to provide valueable services to the customers\n", " 6.1. Apply MEC services required subscriptions (e.g. MEC 013 location subscription)\n", "7. Terminate the MEC application\n", " 7.1. Remove MEC services subscriptions\n", " 7.2. Deactivate the current network scenario\n", " 7.3. Delete the instance of the MEC Sandbox\n", "8. Release all the MEC application resources\n", "\n", "## Use the MEC Sandbox HTTP REST API models and code\n", "\n", "The MEC sandbox provides a piece of code (the python sub) that shall be used to develop the MEC applicationand interact with the MEC Sandbox. This piece of code mainly contains swagger models to serialize/deserialize JSON data structures and HTTP REST API call functions.\n", "The openApi file is availabe [here](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml) and the [Swagger editor](https://editor-next.swagger.io/) is used to generate the python sub.\n", "\n", "The project architecture is describe [here](images/project_arch.jpg).\n", "\n", "The api folder contains the python implementation of the HTTP REST API definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml).\n", "The model folder contains the python implementation of the data type definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml).\n", "irectory:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before to create our MEC ap[plication skeleton, the following steps shall be done:\n", "1) Change the working directory (see the project architecture)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/yann/dev/jupyter/Sandbox/mecapp\n" ] } ], "source": [ "import os\n", "os.chdir(os.path.join(os.getcwd(), '../mecapp'))\n", "print(os.getcwd())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2) Do the python import" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from __future__ import division # Import floating-point division (1/4=0.25) instead of Euclidian division (1/4=0)\n", "\n", "import os\n", "import sys\n", "import logging\n", "import time\n", "import json\n", "import uuid\n", "\n", "from pprint import pprint\n", "\n", "import swagger_client\n", "from swagger_client.rest import ApiException\n", "\n", "from http import HTTPStatus\n", "from http.server import BaseHTTPRequestHandler, HTTPServer\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3) to initialize the global constants (cell 3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "MEC_SANDBOX_URL = 'https://mec-platform.etsi.org' # MEC Sandbox host/base URL\n", "MEC_SANDBOX_API_URL = 'https://mec-platform.etsi.org/sandbox-api/v1' # MEC Sandbox API host/base URL\n", "PROVIDER = 'gitlab' # Login provider value\n", "MEC_PLTF = 'mep1' # MEC plateform name. Linked to the network scenario\n", "LOGGER_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' # Logging format\n", "STABLE_TIME_OUT = 6 # Timer to wait for MEC Sndbox reaches its stable state (K8S pods in running state)\n", "LISTENER_IP = '0.0.0.0' # Listener IPv4 address for notification callback calls\n", "LISTENER_PORT = 32100 # Listener IPv4 port for notification callback calls\n", "CALLBACK_URI = \"/jupyter/sandbox/demo6/v1/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4) to setup a logger instance and initialize the global variables (cell 4)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Initialize the logger\n", "logger = logging.getLogger(__name__)\n", "logger.setLevel(logging.DEBUG)\n", "logging.basicConfig(filename='/tmp/' + time.strftime(\"%Y%m%d-%H%M%S\") + '.log')\n", "l = logging.StreamHandler()\n", "l.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))\n", "logger.addHandler(l)\n", "\n", "# Setup the HTTP REST API configuration\n", "configuration = swagger_client.Configuration()\n", "configuration.host = MEC_SANDBOX_API_URL\n", "configuration.verify_ssl = False\n", "configuration.debug = True\n", "configuration.logger_format = LOGGER_FORMAT\n", "\n", "# Create an instance of ApiClient to be used before each request\n", "api = swagger_client.ApiClient(configuration, 'Content-Type', 'application/json')\n", "\n", "# Initialize the global variables\n", "nw_scenarios = [] # The list of available network scenarios\n", "nw_scenario_idx = -1 # The network scenario idx to activate (deactivate)\n", "app_inst_id = None # The requested application instance identifier\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create our first MEC application\n", "\n", "The first step to develop a MEC application is to create the application skeleton which contains the minimum steps below:\n", " \n", "- Login to instanciate a MEC Sandbox\n", "- Logout to delete a existing MEC Sandbox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### First steps: the login/logout\n", "\n", "Here is the first squeleton with the following sequence:\n", "- Login\n", "- Print sandbox identifier\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The login function\n", "\n", "It uses the HTTP POST request with the URL 'POST /sandbox-api/v1/login?provide=gitlab' (see PROVIDER constant).\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Login\n", "def process_login() -> swagger_client.Sandbox:\n", " \"\"\"\n", " Authenticate and create a new MEC Sandbox instance.\n", "\n", " :return: The swagger_client.Sandbox instance on success, None otherwise\n", " \"\"\" \n", "\n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n", "\n", " logger.debug(\">>> process_login\")\n", "\n", " try:\n", " auth = swagger_client.AuthorizationApi(api)\n", " result = auth.login(PROVIDER, async_req = False) # noqa: E501\n", " logger.debug(\"process_login: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling AuthorizationApi->login: %s\\n\" % e)\n", "\n", " return None\n", " # End of function process_login\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The logout function\n", "\n", "It uses the HTTP POST request with the URL 'POST /sandbox-api/v1/logout?sandbox_name={sandbox_name}'.\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Logout\n", "def process_logout(sandbox: swagger_client.Sandbox) -> int:\n", " \"\"\"\n", " Delete the specified MEC Sandbox instance.\n", "\n", " :param sandbox: The MEC Sandbox to delete\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n", "\n", " logger.debug(\">>> process_logout: sandbox.name=\" + sandbox.name)\n", "\n", " try:\n", " auth = swagger_client.AuthorizationApi(api)\n", " result = auth.logout(sandbox.name, async_req = False) # noqa: E501\n", " return 0\n", " except ApiException as e:\n", " logger.error(\"Exception when calling AuthorizationApi->logout: %s\\n\" % e)\n", " return -1\n", " # End of function process_logout\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let put in action our Login/Logout functions:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:24:31,897 - __main__ - DEBUG - Starting at 20240522-082431\n", "2024-05-22 08:24:31,898 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "2024-05-22 08:24:31,899 - __main__ - DEBUG - >>> process_login\n", "2024-05-22 08:24:31,900 DEBUG Starting new HTTPS connection (1): mec-platform.etsi.org:443\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=gitlab HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:24:32,266 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/login?provider=gitlab HTTP/1.1\" 201 21\n", "2024-05-22 08:24:32,269 DEBUG response body: b'{\"name\":\"sbxeyrp8ww\"}'\n", "2024-05-22 08:24:32,272 - __main__ - DEBUG - process_login: result: {'name': 'sbxeyrp8ww'}\n", "2024-05-22 08:24:32,275 - __main__ - INFO - Sandbox created: sbxeyrp8ww\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:24:31 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 21\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:24:38,279 - __main__ - DEBUG - >>> process_logout: sandbox.name=sbxeyrp8ww\n", "2024-05-22 08:24:38,282 DEBUG Resetting dropped connection: mec-platform.etsi.org\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n", "2024-05-22 08:24:38,397 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbxeyrp8ww HTTP/1.1\" 204 0\n", "2024-05-22 08:24:38,398 DEBUG response body: b''\n", "2024-05-22 08:24:38,399 - __main__ - DEBUG - To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\n", "2024-05-22 08:24:38,399 - __main__ - DEBUG - Stopped at 20240522-082438\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbxeyrp8ww HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:24:37 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Logout\n", " - Check that logout is effective\n", " This skeleton will be the bas of the next sprint in order to achieve a full implementation of a MEC application\n", " \"\"\" \n", "\n", " global PROVIDER, MEC_SANDBOX_API_URL, logger\n", "\n", " logger.debug(\"Starting at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " logger.debug(\"\\t pwd= \" + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info(\"Sandbox created: \" + sandbox.name)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug(\"To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\")\n", " \n", " logger.debug(\"Stopped at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Second step: Retrieve the list of network scenarios\n", "\n", "Let's go futhur and see how we can retrieve the list of the network scenarios available in order to activate one of them and access the MEC services exposed such as MEC 013 or MEC 030.\n", "\n", "The sequence will be:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Logout\n", "- Check that logout is effective\n", "\n", "The login and logout functions are described in cell 3 and 4.\n", "\n", "To retrieve the list of the network scenarios, let's create a new function called 'get_network_scenarios'. It uses the HTTP GET request with the URL '/sandbox-api/v1/sandboxNetworkScenarios?sandbox_name={sandbox_name}'." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def get_network_scenarios(sandbox: swagger_client.Sandbox) -> list:\n", " \"\"\"\n", " Retrieve the list of the available network scenarios.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: The list of the available network scenarios on success, None otherwise\n", " \"\"\"\n", "\n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n", "\n", " logger.debug(\">>> get_network_scenarios: sandbox.name=\" + sandbox.name)\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(api)\n", " result = nw.sandbox_network_scenarios_get(sandbox.name, async_req = False) # noqa: E501\n", " logger.debug(\"get_network_scenarios: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling SandboxNetworkScenariosApi->sandbox_network_scenarios_get: %s\\n\" % e)\n", "\n", " return None\n", " # End of function get_network_scenarios\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Putting everything together:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the first sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios \n", "\n", " logger.debug(\"Starting at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " logger.debug(\"\\t pwd= \" + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error(\"Failed to instanciate a MEC Sandbox\")\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info(\"Sandbox created: \" + sandbox.name)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error(\"Failed to retrieve the list of network scenarios\")\n", " elif len(nw_scenarios) != 0:\n", " logger.info(\"nw_scenarios: %s\", str(type(nw_scenarios[0])))\n", " logger.info(\"nw_scenarios: %s\", str(nw_scenarios))\n", " else:\n", " logger.info(\"nw_scenarios: No scenario available\")\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug(\"To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\")\n", " \n", " logger.debug(\"Stopped at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Third step: Activate and deactivate a network scenario\n", "\n", "Having a list of network scenarion, the next step is to actvate (and deactivate) a network scenario. This step is mandatory to create a new application instance id and access the MEC services.\n", "\n", "In this section, we will arbitrary activate the network scenario called '4g-5g-macro-v2x', which is at the index 0 of the nw_scenarios. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def select_network_scenario_based_on_criteria(criterias_list: list) -> int:\n", " \"\"\"\n", " Select the network scenario to activate based of the provided list of criterias.\n", "\n", " :param criterias_list: The list of criterias to select the correct network scenario\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", " return 0 # The index of the '4g-5g-macro-v2x' network scenario - Hard coded" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The activate function\n", "\n", "The process to activate a scenario is based on an HTTP POST request with the URL '/sandboxNetworkScenarios/{sandbox_name}?network_scenario_id={network_scenario_id}'.\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def activate_network_scenario(sandbox: swagger_client.Sandbox) -> int:\n", " \"\"\"\n", " Activate the specified network scenario.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration, nw_scenarios, nw_scenario_idx\n", "\n", " logger.debug(\">>> activate_network_scenario: \" + sandbox.name)\n", "\n", " nw_scenario_idx = select_network_scenario_based_on_criteria([])\n", " if nw_scenario_idx == -1:\n", " logger.error(\"activate_network_scenario: Failed to select a network scenarion\")\n", " return -1\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(api)\n", " result = nw.sandbox_network_scenario_post(sandbox.name, nw_scenarios[nw_scenario_idx].id, async_req = False) # noqa: E501\n", " logger.debug(\"activate_network_scenario: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling SandboxNetworkScenariosApi->activate_network_scenario: %s\\n\" % e)\n", "\n", " return -1\n", " # End of function activate_network_scenario\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The deactivate function\n", "\n", "The process to deactivate a scenario is based on an HTTP DELETE request with the URL '/sandboxNetworkScenarios/{sandbox_name}?network_scenario_id={network_scenario_id}'.\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def deactivate_network_scenario(sandbox: swagger_client.Sandbox) -> int:\n", " \"\"\"\n", " Deactivate the current network scenario.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration, nw_scenarios, nw_scenario_idx\n", "\n", " logger.debug(\">>> deactivate_network_scenario: \" + sandbox.name)\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(api)\n", " result = nw.sandbox_network_scenario_delete(sandbox.name, nw_scenarios[nw_scenario_idx].id, async_req = False) # noqa: E501\n", " logger.debug(\"deactivate_network_scenario: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling SandboxNetworkScenariosApi->deactivate_network_scenario: %s\\n\" % e)\n", "\n", " return -1\n", " # End of function deactivate_network_scenario\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, it is time to create the second iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Check that the network scenario is activated and the MEC services are running\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Check that the network scenario is activated and the MEC services are running\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios \n", "\n", " logger.debug(\"Starting at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " logger.debug(\"\\t pwd= \" + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error(\"Failed to instanciate a MEC Sandbox\")\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info(\"Sandbox created: \" + sandbox.name)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error(\"Failed to retrieve the list of network scenarios\")\n", " elif len(nw_scenarios) != 0:\n", " logger.info(\"nw_scenarios: %s\", str(type(nw_scenarios[0])))\n", " logger.info(\"nw_scenarios: %s\", str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info(\"nw_scenarios: No scenario available\")\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to activate network scenario\")\n", " else:\n", " logger.info(\"Network scenario activated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Check that the network scenario is activated and the MEC services are running \n", " logger.info(\"To check that the network scenario is activated, verify on the MEC Sandbox server that the MEC services are running (kubectl get pods -A\")\n", " time.sleep(60) # Sleep for 3 seconds\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to deactivate network scenario\")\n", " else:\n", " logger.info(\"Network scenario deactivated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug(\"To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\")\n", " \n", " logger.debug(\"Stopped at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fourth step: Create and delete an appliction instance id\n", "\n", "To enable our MEC application to be part of the activated network scenario, we need to request the MEC sandbox to create a new application instance identifer. Our MEC application will use this identifier to register to the MEC Sandbox according to MEC 011.\n", "\n", "#### The appliction instance id creation function\n", "\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "def request_application_instance_id(sandbox: swagger_client.Sandbox) -> swagger_client.models.ApplicationInfo:\n", " \"\"\"\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration, app_inst_id\n", "\n", " logger.debug(\">>> request_application_instance_id: \" + sandbox.name)\n", "\n", " # Create a instance of our MEC application\n", " a = swagger_client.models.ApplicationInfo(id=str(uuid.uuid4()), name='JupyterMecApp', node_name=MEC_PLTF, type='USER') # noqa: E501\n", " print(a)\n", " \n", " try:\n", " nw = swagger_client.SandboxAppInstancesApi(api)\n", " result = nw.sandbox_app_instances_post(a, sandbox.name, async_req = False) # noqa: E501\n", " logger.debug(\"request_application_instance_id: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling SandboxAppInstancesApi->sandbox_app_instances_post: %s\\n\" % e)\n", "\n", " return None\n", " # End of function request_application_instance_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The appliction instance id deletion function\n", "\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def delete_application_instance_id(sandbox: swagger_client.Sandbox) -> int:\n", " \"\"\"\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration, app_inst_id\n", "\n", " logger.debug(\">>> deletet_application_instance_id: \" + sandbox.name)\n", "\n", " try:\n", " nw = swagger_client.SandboxAppInstancesApi(api)\n", " result = nw.sandbox_app_instances_delete(sandbox.name, app_inst_id.id, async_req = False) # noqa: E501\n", " logger.debug(\"deletet_application_instance_id: result: \" + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error(\"Exception when calling SandboxAppInstancesApi->sandbox_app_instances_delete: %s\\n\" % e)\n", "\n", " return -1\n", " # End of function deletet_application_instance_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is time now to create the our third iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Request for a new application instance identifer\n", "- Check \n", "- Delete our application instance identifer\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:43:49,986 - __main__ - DEBUG - Starting at 20240522-084349\n", "2024-05-22 08:43:49,989 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "2024-05-22 08:43:49,991 - __main__ - DEBUG - >>> process_login\n", "2024-05-22 08:43:49,994 DEBUG Resetting dropped connection: mec-platform.etsi.org\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n", "2024-05-22 08:43:50,130 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/login?provider=gitlab HTTP/1.1\" 201 21\n", "2024-05-22 08:43:50,132 DEBUG response body: b'{\"name\":\"sbx4rkzuij\"}'\n", "2024-05-22 08:43:50,134 - __main__ - DEBUG - process_login: result: {'name': 'sbx4rkzuij'}\n", "2024-05-22 08:43:50,136 - __main__ - INFO - Sandbox created: sbx4rkzuij\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=gitlab HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:43:49 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 21\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:43:56,143 - __main__ - DEBUG - >>> get_network_scenarios: sandbox.name=sbx4rkzuij\n", "2024-05-22 08:43:56,146 DEBUG Resetting dropped connection: mec-platform.etsi.org\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx4rkzuij HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:43:56,465 DEBUG https://mec-platform.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx4rkzuij HTTP/1.1\" 200 157\n", "2024-05-22 08:43:56,467 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-wifi-macro\"},{\"id\":\"4g-macro\"},{\"id\":\"4g-wifi-macro\"},{\"id\":\"dual-mep-4g-5g-wifi-macro\"},{\"id\":\"dual-mep-short-path\"}]'\n", "2024-05-22 08:43:56,469 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n", "2024-05-22 08:43:56,471 - __main__ - INFO - nw_scenarios: \n", "2024-05-22 08:43:56,473 - __main__ - INFO - nw_scenarios: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:43:55 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 157\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:44:02,479 - __main__ - DEBUG - >>> activate_network_scenario: sbx4rkzuij\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n", "2024-05-22 08:44:02,576 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbx4rkzuij?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-05-22 08:44:02,577 DEBUG response body: b''\n", "2024-05-22 08:44:02,578 - __main__ - DEBUG - activate_network_scenario: result: None\n", "2024-05-22 08:44:02,579 - __main__ - INFO - Network scenario activated: 4g-5g-macro-v2x\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbx4rkzuij?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:44:02 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-05-22 08:44:08,583 - __main__ - DEBUG - >>> request_application_instance_id: sbx4rkzuij\n", "2024-05-22 08:44:08,586 DEBUG Resetting dropped connection: mec-platform.etsi.org\n", "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", " warnings.warn(\n", "2024-05-22 08:44:08,779 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbx4rkzuij HTTP/1.1\" 201 100\n", "2024-05-22 08:44:08,781 DEBUG response body: b'{\"id\":\"e3a6ec8b-81fa-48e2-bf16-cc24a1028df9\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'id': 'e3a6ec8b-81fa-48e2-bf16-cc24a1028df9',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbx4rkzuij HTTP/1.1\\r\\nHost: mec-platform.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 107\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"id\": \"e3a6ec8b-81fa-48e2-bf16-cc24a1028df9\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Wed, 22 May 2024 06:44:08 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 100\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "ename": "ValueError", "evalue": "Invalid value for `name`, must not be `None`", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[19], line 85\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[38;5;66;03m# End of function process_main\u001b[39;00m\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m---> 85\u001b[0m \u001b[43mprocess_main\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "Cell \u001b[0;32mIn[19], line 50\u001b[0m, in \u001b[0;36mprocess_main\u001b[0;34m()\u001b[0m\n\u001b[1;32m 47\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(STABLE_TIME_OUT) \u001b[38;5;66;03m# Wait for k8s pods up and running\u001b[39;00m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;66;03m# Request for a new application instance identifer\u001b[39;00m\n\u001b[0;32m---> 50\u001b[0m app_inst_id \u001b[38;5;241m=\u001b[39m \u001b[43mrequest_application_instance_id\u001b[49m\u001b[43m(\u001b[49m\u001b[43msandbox\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 51\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m app_inst_id \u001b[38;5;241m==\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 52\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to request an application instance identifer\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", "Cell \u001b[0;32mIn[17], line 15\u001b[0m, in \u001b[0;36mrequest_application_instance_id\u001b[0;34m(sandbox)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 14\u001b[0m nw \u001b[38;5;241m=\u001b[39m swagger_client\u001b[38;5;241m.\u001b[39mSandboxAppInstancesApi(api)\n\u001b[0;32m---> 15\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mnw\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msandbox_app_instances_post\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msandbox\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43masync_req\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# noqa: E501\u001b[39;00m\n\u001b[1;32m 16\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrequest_application_instance_id: result: \u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mstr\u001b[39m(result))\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api/sandbox_app_instances_api.py:249\u001b[0m, in \u001b[0;36mSandboxAppInstancesApi.sandbox_app_instances_post\u001b[0;34m(self, body, sandbox_name, **kwargs)\u001b[0m\n\u001b[1;32m 247\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msandbox_app_instances_post_with_http_info(body, sandbox_name, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;66;03m# noqa: E501\u001b[39;00m\n\u001b[1;32m 248\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 249\u001b[0m (data) \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msandbox_app_instances_post_with_http_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msandbox_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# noqa: E501\u001b[39;00m\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m data\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api/sandbox_app_instances_api.py:320\u001b[0m, in \u001b[0;36mSandboxAppInstancesApi.sandbox_app_instances_post_with_http_info\u001b[0;34m(self, body, sandbox_name, **kwargs)\u001b[0m\n\u001b[1;32m 317\u001b[0m \u001b[38;5;66;03m# Authentication setting\u001b[39;00m\n\u001b[1;32m 318\u001b[0m auth_settings \u001b[38;5;241m=\u001b[39m [] \u001b[38;5;66;03m# noqa: E501\u001b[39;00m\n\u001b[0;32m--> 320\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 321\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/sandboxAppInstances/\u001b[39;49m\u001b[38;5;132;43;01m{sandbox_name}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mPOST\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 322\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 323\u001b[0m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 324\u001b[0m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 325\u001b[0m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbody_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 326\u001b[0m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mform_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 327\u001b[0m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_var_files\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 328\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mlist[ApplicationInfo]\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# noqa: E501\u001b[39;49;00m\n\u001b[1;32m 329\u001b[0m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mauth_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 330\u001b[0m \u001b[43m \u001b[49m\u001b[43masync_req\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43masync_req\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 331\u001b[0m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_return_http_data_only\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 332\u001b[0m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_preload_content\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 333\u001b[0m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_request_timeout\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 334\u001b[0m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcollection_formats\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:316\u001b[0m, in \u001b[0;36mApiClient.call_api\u001b[0;34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, _return_http_data_only, collection_formats, _preload_content, _request_timeout)\u001b[0m\n\u001b[1;32m 279\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Makes the HTTP request (synchronous) and returns deserialized data.\u001b[39;00m\n\u001b[1;32m 280\u001b[0m \n\u001b[1;32m 281\u001b[0m \u001b[38;5;124;03mTo make an async request, set the async_req parameter.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 313\u001b[0m \u001b[38;5;124;03m then the method will return the response directly.\u001b[39;00m\n\u001b[1;32m 314\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 315\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m async_req:\n\u001b[0;32m--> 316\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__call_api\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresource_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 317\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 318\u001b[0m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 319\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 320\u001b[0m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 321\u001b[0m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 323\u001b[0m thread \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpool\u001b[38;5;241m.\u001b[39mapply_async(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__call_api, (resource_path,\n\u001b[1;32m 324\u001b[0m method, path_params, query_params,\n\u001b[1;32m 325\u001b[0m header_params, body,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 329\u001b[0m collection_formats,\n\u001b[1;32m 330\u001b[0m _preload_content, _request_timeout))\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:160\u001b[0m, in \u001b[0;36mApiClient.__call_api\u001b[0;34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout)\u001b[0m\n\u001b[1;32m 157\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m _preload_content:\n\u001b[1;32m 158\u001b[0m \u001b[38;5;66;03m# deserialize response data\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response_type:\n\u001b[0;32m--> 160\u001b[0m return_data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdeserialize\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse_data\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 161\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 162\u001b[0m return_data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:232\u001b[0m, in \u001b[0;36mApiClient.deserialize\u001b[0;34m(self, response, response_type)\u001b[0m\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m:\n\u001b[1;32m 230\u001b[0m data \u001b[38;5;241m=\u001b[39m response\u001b[38;5;241m.\u001b[39mdata\n\u001b[0;32m--> 232\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__deserialize\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:248\u001b[0m, in \u001b[0;36mApiClient.__deserialize\u001b[0;34m(self, data, klass)\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m klass\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlist[\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 247\u001b[0m sub_kls \u001b[38;5;241m=\u001b[39m re\u001b[38;5;241m.\u001b[39mmatch(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlist\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m[(.*)\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m]\u001b[39m\u001b[38;5;124m'\u001b[39m, klass)\u001b[38;5;241m.\u001b[39mgroup(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m--> 248\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m [\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__deserialize(sub_data, sub_kls)\n\u001b[1;32m 249\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m sub_data \u001b[38;5;129;01min\u001b[39;00m data]\n\u001b[1;32m 251\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m klass\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdict(\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 252\u001b[0m sub_kls \u001b[38;5;241m=\u001b[39m re\u001b[38;5;241m.\u001b[39mmatch(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdict\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m(([^,]*), (.*)\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m'\u001b[39m, klass)\u001b[38;5;241m.\u001b[39mgroup(\u001b[38;5;241m2\u001b[39m)\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:248\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m klass\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlist[\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 247\u001b[0m sub_kls \u001b[38;5;241m=\u001b[39m re\u001b[38;5;241m.\u001b[39mmatch(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlist\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m[(.*)\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m]\u001b[39m\u001b[38;5;124m'\u001b[39m, klass)\u001b[38;5;241m.\u001b[39mgroup(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m--> 248\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m [\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__deserialize\u001b[49m\u001b[43m(\u001b[49m\u001b[43msub_data\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msub_kls\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 249\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m sub_data \u001b[38;5;129;01min\u001b[39;00m data]\n\u001b[1;32m 251\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m klass\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdict(\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 252\u001b[0m sub_kls \u001b[38;5;241m=\u001b[39m re\u001b[38;5;241m.\u001b[39mmatch(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdict\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m(([^,]*), (.*)\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m'\u001b[39m, klass)\u001b[38;5;241m.\u001b[39mgroup(\u001b[38;5;241m2\u001b[39m)\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:271\u001b[0m, in \u001b[0;36mApiClient.__deserialize\u001b[0;34m(self, data, klass)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__deserialize_datatime(data)\n\u001b[1;32m 270\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 271\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__deserialize_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mklass\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/api_client.py:620\u001b[0m, in \u001b[0;36mApiClient.__deserialize_model\u001b[0;34m(self, data, klass)\u001b[0m\n\u001b[1;32m 617\u001b[0m value \u001b[38;5;241m=\u001b[39m data[klass\u001b[38;5;241m.\u001b[39mattribute_map[attr]]\n\u001b[1;32m 618\u001b[0m kwargs[attr] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__deserialize(value, attr_type)\n\u001b[0;32m--> 620\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[43mklass\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 622\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28misinstance\u001b[39m(instance, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m 623\u001b[0m klass\u001b[38;5;241m.\u001b[39mswagger_types \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m 624\u001b[0m \u001b[38;5;28misinstance\u001b[39m(data, \u001b[38;5;28mdict\u001b[39m)):\n\u001b[1;32m 625\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key, value \u001b[38;5;129;01min\u001b[39;00m data\u001b[38;5;241m.\u001b[39mitems():\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/models/application_info.py:56\u001b[0m, in \u001b[0;36mApplicationInfo.__init__\u001b[0;34m(self, id, name, node_name, type, persist)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mid\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 55\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mid \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mid\u001b[39m\n\u001b[0;32m---> 56\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m \u001b[38;5;241m=\u001b[39m name\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnode_name \u001b[38;5;241m=\u001b[39m node_name\n\u001b[1;32m 58\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mtype\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", "File \u001b[0;32m~/dev/jupyter/Sandbox/mecapp/swagger_client/models/application_info.py:107\u001b[0m, in \u001b[0;36mApplicationInfo.name\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Sets the name of this ApplicationInfo.\u001b[39;00m\n\u001b[1;32m 100\u001b[0m \n\u001b[1;32m 101\u001b[0m \u001b[38;5;124;03mApplication name # noqa: E501\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124;03m:type: str\u001b[39;00m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 106\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 107\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid value for `name`, must not be `None`\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# noqa: E501\u001b[39;00m\n\u001b[1;32m 109\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_name \u001b[38;5;241m=\u001b[39m name\n", "\u001b[0;31mValueError\u001b[0m: Invalid value for `name`, must not be `None`" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Check that the network scenario is activated and the MEC services are running\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios\n", "\n", " logger.debug(\"Starting at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " logger.debug(\"\\t pwd= \" + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error(\"Failed to instanciate a MEC Sandbox\")\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info(\"Sandbox created: \" + sandbox.name)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error(\"Failed to retrieve the list of network scenarios\")\n", " elif len(nw_scenarios) != 0:\n", " logger.info(\"nw_scenarios: %s\", str(type(nw_scenarios[0])))\n", " logger.info(\"nw_scenarios: %s\", str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info(\"nw_scenarios: No scenario available\")\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to activate network scenario\")\n", " else:\n", " logger.info(\"Network scenario activated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Request for a new application instance identifer\n", " app_inst_id = request_application_instance_id(sandbox)\n", " if app_inst_id == None:\n", " logger.error(\"Failed to request an application instance identifer\")\n", " else:\n", " logger.info(\"app_inst_id: %s\", str(type(app_inst_id)))\n", " logger.info(\"app_inst_id: %s\", str(app_inst_id))\n", "\n", " # Check that the network scenario is activated and the MEC services are running \n", " logger.info(\"To check that the app_inst_id is created, verify on the MEC Sandbox server that the MEC services are running (kubectl get pods -A\")\n", " time.sleep(3) # Sleep for 3 seconds\n", "\n", " # Delete the application instance identifer\n", " if delete_application_instance_id(sandbox) == -1:\n", " logger.error(\"Failed to delete the application instance identifer\")\n", " else:\n", " logger.info(\"app_inst_id deleted: \" + app_inst_id.id)\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to deactivate network scenario\")\n", " else:\n", " logger.info(\"Network scenario deactivated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug(\"To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\")\n", " \n", " logger.debug(\"Stopped at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MEC Registration and the READY confirmation\n", "\n", "Having an application instance identifier allows us to register to the MEC Sandbox and interacts with it (e.g. to send service queries, to subscribe to events and to recieve notifications...).\n", "\n", "The standard MEC 011 Clause 5.2.2 MEC application start-up describes the start up process. Basically, our MEC application has to:\n", "1. Indicates that it is running by sending a Confirm Ready message\n", "2. Retrieve the list of MEC services \n", "\n", "To do so, a MEC application need to be able to send request but also to recieve notifications (POST requests) and to reply to them." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fifth step: Send the READY confirmation\n", "\n", "Sending READY confirmation is described by MEC 011 Clause 5.2.2 MEC application start-up.\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def send_ready_confirmation(app_inst_id: str) -> int:\n", " global MEC_SANDBOX_URL, MEC_PLTF, logger\n", "\n", " try:\n", " url = MEC_SANDBOX_URL + '/' + MEC_PLTF + '/mec_app_support/v2/applications/' + app_inst_id + '/confirm_ready'\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = self.api_client.select_header_accept(['application/json']) # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = self.api_client.select_header_accept(['application/json']) # noqa: E501\n", " body = '{\\\"indication\\\":\\\"READY\\\"}'\n", " result = api.call_api(url, 'POST', header_params=header_params, body=body, async_req=False)\n", " return 0\n", " except ApiException as e:\n", " logger.error(\"Exception when calling AuthorizationApi->logout: %s\\n\" % e)\n", " return -1\n", " # End of function send_ready_confirmation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def send_termination() -> int:\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is time now to create the our third iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Request for a new application instance identifer\n", "- Send READY confirmation\n", "- Get MEC services\n", "- Check list of services \n", "- Delete our application instance identifer\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Request for a new application instance identifer\n", " - Send READY confirmation\n", " - Get MEC services\n", " - Send Termination\n", " - Delete our application instance identifer\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios\n", "\n", " logger.debug(\"Starting at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " logger.debug(\"\\t pwd= \" + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error(\"Failed to instanciate a MEC Sandbox\")\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info(\"Sandbox created: \" + sandbox.name)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error(\"Failed to retrieve the list of network scenarios\")\n", " elif len(nw_scenarios) != 0:\n", " logger.info(\"nw_scenarios: %s\", str(type(nw_scenarios[0])))\n", " logger.info(\"nw_scenarios: %s\", str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info(\"nw_scenarios: No scenario available\")\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to activate network scenario\")\n", " else:\n", " logger.info(\"Network scenario activated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Request for a new application instance identifer\n", " app_inst_id = request_application_instance_id(sandbox)\n", " if app_inst_id == None:\n", " logger.error(\"Failed to request an application instance identifer\")\n", " else:\n", " logger.info(\"app_inst_id: %s\", str(type(app_inst_id)))\n", " logger.info(\"app_inst_id: %s\", str(app_inst_id))\n", "\n", " # Send READY confirmation\n", " send_ready_confirmation(app_inst_id)\n", "\n", " # Check list of services\n", "\n", " # Delete the application instance identifer\n", " if delete_application_instance_id(sandbox) == -1:\n", " logger.error(\"Failed to delete the application instance identifer\")\n", " else:\n", " logger.info(\"app_inst_id deleted: \" + app_inst_id.id)\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error(\"Failed to deactivate network scenario\")\n", " else:\n", " logger.info(\"Network scenario deactivated: \" + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug(\"To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A\")\n", " \n", " logger.debug(\"Stopped at \" + time.strftime(\"%Y%m%d-%H%M%S\"))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notification support\n", "\n", "To recieve notifcation, our MEC application is required to support an HTTP listenener to recieve POST request from the MEC Sandbox and replto repry to them: this is the notification mechanism.\n", "\n", "The class HTTPRequestHandler (see cell below) provides the suport of such mechanism.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class HTTPRequestHandler(BaseHTTPRequestHandler):\n", "\n", " def do_POST(self):\n", " if re.search(CALLBACK_URI, self.path):\n", " ctype, pdict = _parse_header(self.headers.get(\"content-type\"))\n", " if ctype == \"application/json\":\n", " length = int(self.headers.get(\"content-length\"))\n", " rfile_str = self.rfile.read(length).decode(\"utf8\")\n", " data = parse.parse_qs(rfile_str, keep_blank_values=True)\n", " record_id = self.path.split(\"/\")[-1]\n", " LocalData.records[record_id] = data\n", " print(\"addrecord %s: %s\" % (record_id, data))\n", " self.send_response(HTTPStatus.OK)\n", " else:\n", " self.send_response(HTTPStatus.BAD_REQUEST, 'Only application/json is supported')\n", " else:\n", " self.send_response(HTTPStatus.BAD_REQUEST, 'Unsupported URI')\n", " self.end_headers()\n", "\n", " def do_GET(self):\n", " self.send_response(HTTPStatus.BAD_REQUEST)\n", " self.end_headers()\n", " # End of class HTTPRequestHandler\n", "\n", "class LocalData(object):\n", " records = {}\n", " # End of class LocalData" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process():\n", " # Start notification server in a daemonized thread\n", " notification_server = threading.Thread(name='notification_server', target=start_server, args=(LISTENER_IP, LISTENER_PORT))\n", " notification_server.setDaemon(True) # Set as a daemon so it will be killed once the main thread is dead.\n", " notification_server.start()\n", " # Continue\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Annexes\n", "\n", "## Annex A: How to use an existing MEC sandbox instance\n", "\n", "TODO\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Bibliography\n", "\n", "1. ETSI GS MEC 002 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Phase 2: Use Cases and Requirements\".\n", "2. ETSI GS MEC 010-1 (V1.1.1) (10-2017): \"Mobile Edge Computing (MEC); Mobile Edge Management; Part 1: System, host and platform management\".\n", "3. ETSI GS MEC 010-2 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); MEC Management; Part 2: Application lifecycle, rules and requirements management\".\n", "4. ETSI GS MEC 011 (V3.1.1) (09-2022): \"Multi-access Edge Computing (MEC); Edge Platform Application Enablement\".\n", "5. ETSI GS MEC 012 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Radio Network Information API\".\n", "6. ETSI GS MEC 013 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Location API\".\n", "7. ETSI GS MEC 014 (V2.1.1) (03-2021): \"Multi-access Edge Computing (MEC); UE Identity API\".\n", "8. ETSI GS MEC 015 (V2.1.1) (06-2020): \"Multi-Access Edge Computing (MEC); Traffic Management APIs\".\n", "9. ETSI GS MEC 016 (V2.2.1) (04-2020): \"Multi-access Edge Computing (MEC); Device application interface\".\n", "10. ETSI GS MEC 021 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Application Mobility Service API\".\n", "11. ETSI GS MEC 028 (V2.3.1) (07-2022): \"Multi-access Edge Computing (MEC); WLAN Access Information API\".\n", "12. ETSI GS MEC 029 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Fixed Access Information API\".\n", "13. ETSI GS MEC 030 (V2.2.1) (05-2022): \"Multi-access Edge Computing (MEC); V2X Information Service API\".\n", "14. ETSI GR MEC-DEC 025 (V2.1.1) (06-2019): \"Multi-access Edge Computing (MEC); MEC Testing Framework\".\n", "15. ETSI GR MEC 001 (V3.1.1) (01-2022): \"Multi-access Edge Computing (MEC); Terminology\".\n", "16. [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n", "17. " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }