Skip to content
MEC application.ipynb 62.8 KiB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
{
 "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",
    " .[ What is a MEC applicationn](what_is_a_mec_applicationn)2\n",
    ".[ The basics of developing a MEC applicationh](the_basics_of_developing_a_mec_application)\n",
Yann Garcia's avatar
Yann Garcia committed
    "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](#bibliograhypt\n"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "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",
Yann Garcia's avatar
Yann Garcia committed
    "The project architecture is describe [here](images/project_arch.jpg).\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "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:"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "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": 1,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {
    "scrolled": true
   },
Yann Garcia's avatar
Yann Garcia committed
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/yann/dev/jupyter/Sandbox/mecapp\n"
     ]
    }
   ],
Yann Garcia's avatar
Yann Garcia committed
   "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": 2,
Yann Garcia's avatar
Yann Garcia committed
   "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",
Yann Garcia's avatar
Yann Garcia committed
    "from swagger_client.rest import ApiException\n",
    "\n",
    "from http import HTTPStatus\n",
    "from http.server import BaseHTTPRequestHandler, HTTPServer\n"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3) to initialize the global constants (cell 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
Yann Garcia's avatar
Yann Garcia committed
    "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            = 'Jupyter2024'                                         # Login provider value\n",
Yann Garcia's avatar
Yann Garcia committed
    "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",
    "LOGIN_TIMEOUT       = 3 #30                                                     # Timer to wait for user to authorize from GITHUB\n",
Yann Garcia's avatar
Yann Garcia committed
    "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/\""
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4) to setup a logger instance and initialize the global variables  (cell 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
Yann Garcia's avatar
Yann Garcia committed
   "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",
Yann Garcia's avatar
Yann Garcia committed
    "configuration.host          = MEC_SANDBOX_API_URL\n",
Yann Garcia's avatar
Yann Garcia committed
    "configuration.verify_ssl    = False\n",
    "configuration.debug         = True\n",
    "configuration.logger_format = LOGGER_FORMAT\n",
    "\n",
Yann Garcia's avatar
Yann Garcia committed
    "# Create an instance of ApiClient to be used before each request\n",
    "api = swagger_client.ApiClient(configuration, 'Content-Type', 'application/json')\n",
    "\n",
Yann Garcia's avatar
Yann Garcia committed
    "# 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",
Yann Garcia's avatar
Yann Garcia committed
   "source": [
    "#### The login function\n",
    "\n",
    "To log to the MEC Sandbox, \n",
    "The login process is done in two step. In step 1, a user code is requested to GITHUB. In step 2, the user has to enter this user code to https://github.com/login/device and proceed to the authorization.\n",
    "Please, pay attention to the log '=======================> DO AUTHORIZATION WITH CODE :' which indicate you the user code to use for the authorization.\n",
    "\n",
    "It uses the HTTP POST request with the URL 'POST /sandbox-api/v1/login?provide=github' (see PROVIDER constant).\n"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Login\n",
    "def process_login() -> str:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\n",
    "    Authenticate and create a new MEC Sandbox instance.\n",
    "\n",
    "    :return: The sandbox instance identifier on success, None otherwise\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\" \n",
    "\n",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> process_login\")\n",
    "\n",
    "    try:\n",
    "        auth = swagger_client.AuthorizationApi(api)\n",
    "        oauth = auth.login(PROVIDER, async_req = False)\n",
    "        logger.debug(\"process_login (step1): oauth: \" + str(oauth))\n",
    "        # Wait for the MEC Sandbox is running\n",
    "        logger.debug(\"=======================> DO AUTHORIZATION WITH CODE : \" + oauth.user_code)\n",
    "        time.sleep(LOGIN_TIMEOUT) # Wait for Authirization from user side\n",
    "        namespace = auth.get_namespace(oauth.user_code)\n",
    "        logger.debug(\"process_login (step2): result: \" + str(namespace))\n",
    "        return namespace.sandbox_name\n",
Yann Garcia's avatar
Yann Garcia committed
    "    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": 6,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Logout\n",
    "def process_logout(sandbox: str) -> int:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\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",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> process_logout: sandbox=\" + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    try:\n",
    "        auth = swagger_client.AuthorizationApi(api)\n",
    "        result = auth.logout(sandbox, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
Yann Garcia's avatar
Yann Garcia committed
   "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",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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)\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # Wait for the MEC Sandbox is running\n",
Yann Garcia's avatar
Yann Garcia committed
    "    time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_network_scenarios(sandbox: str) -> list:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\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",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger, configuration\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> get_network_scenarios: sandbox=\" + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    try:\n",
    "        nw = swagger_client.SandboxNetworkScenariosApi(api)\n",
    "        result = nw.sandbox_network_scenarios_get(sandbox, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios \n",
Yann Garcia's avatar
Yann Garcia committed
    "\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)\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # Wait for the MEC Sandbox is running\n",
Yann Garcia's avatar
Yann Garcia committed
    "    time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
   "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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "def activate_network_scenario(sandbox: str) -> int:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\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",
Yann Garcia's avatar
Yann Garcia committed
    "    global MEC_SANDBOX_API_URL, logger, configuration, nw_scenarios, nw_scenario_idx\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> activate_network_scenario: \" + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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, nw_scenarios[nw_scenario_idx].id, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "def deactivate_network_scenario(sandbox: str) -> int:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\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",
Yann Garcia's avatar
Yann Garcia committed
    "    global MEC_SANDBOX_API_URL, logger, configuration, nw_scenarios, nw_scenario_idx\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> deactivate_network_scenario: \" + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    try:\n",
    "        nw = swagger_client.SandboxNetworkScenariosApi(api)\n",
    "        result = nw.sandbox_network_scenario_delete(sandbox, nw_scenarios[nw_scenario_idx].id, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
    "    global PROVIDER, MEC_SANDBOX_API_URL, logger, nw_scenarios \n",
Yann Garcia's avatar
Yann Garcia committed
    "\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)\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # Wait for the MEC Sandbox is running\n",
Yann Garcia's avatar
Yann Garcia committed
    "    time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "        time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "    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",
Yann Garcia's avatar
Yann Garcia committed
    "        time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "def request_application_instance_id(sandbox: str) -> swagger_client.models.ApplicationInfo:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\n",
    "    \"\"\"\n",
    "\n",
    "    global MEC_SANDBOX_API_URL, MEC_PLTF, logger, configuration\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> request_application_instance_id: \" + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Create a instance of our MEC application\n",
Yann Garcia's avatar
Yann Garcia committed
    "    a = swagger_client.models.ApplicationInfo(id=str(uuid.uuid4()), name='JupyterMecApp', node_name=MEC_PLTF, type='USER')  # noqa: E501\n",
    "    print(a)\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \n",
    "    try:\n",
    "        nw = swagger_client.SandboxAppInstancesApi(api)\n",
    "        result = nw.sandbox_app_instances_post(a, sandbox, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
    "def delete_application_instance_id(sandbox: str, id: str) -> int:\n",
Yann Garcia's avatar
Yann Garcia committed
    "    \"\"\"\n",
    "    \"\"\"\n",
    "\n",
    "    global MEC_SANDBOX_API_URL, logger, configuration\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug(\">>> deletet_application_instance_id: \" + sandbox)\n",
    "    logger.debug(\">>> deletet_application_instance_id: \" + id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    try:\n",
    "        nw = swagger_client.SandboxAppInstancesApi(api)\n",
    "        result = nw.sandbox_app_instances_delete(sandbox, id, async_req = False)  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 08:33:18,020 - __main__ - DEBUG - Starting at 20240619-083318\n",
      "2024-06-19 08:33:18,021 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n",
      "2024-06-19 08:33:18,023 - __main__ - DEBUG - >>> process_login\n",
      "2024-06-19 08:33:18,024 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-06-19 08:33:18,285 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n",
      "2024-06-19 08:33:18,287 DEBUG response body: b'{\"user_code\":\"sbx0rphiwx\",\"verification_uri\":\"\"}'\n",
      "2024-06-19 08:33:18,291 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbx0rphiwx', 'verification_uri': ''}\n",
      "2024-06-19 08:33:18,293 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbx0rphiwx\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 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, 19 Jun 2024 06:33:17 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 48\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/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-06-19 08:33:21,333 DEBUG https://mec-platform.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbx0rphiwx HTTP/1.1\" 200 29\n",
      "2024-06-19 08:33:21,335 DEBUG response body: b'{\"sandbox_name\":\"sbx0rphiwx\"}'\n",
      "2024-06-19 08:33:21,338 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbx0rphiwx'}\n",
      "2024-06-19 08:33:21,339 - __main__ - INFO - Sandbox created: sbx0rphiwx\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'GET /sandbox-api/v1/namespace?user_code=sbx0rphiwx 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",
      "reply: 'HTTP/1.1 200 OK\\r\\n'\n",
      "header: Date: Wed, 19 Jun 2024 06:33:20 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 29\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 08:33:27,346 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbx0rphiwx\n",
      "2024-06-19 08:33:27,349 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-06-19 08:33:27,526 DEBUG https://mec-platform.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx0rphiwx HTTP/1.1\" 200 157\n",
      "2024-06-19 08:33:27,528 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-06-19 08:33:27,531 - __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-06-19 08:33:27,533 - __main__ - INFO - nw_scenarios: <class 'swagger_client.models.sandbox_network_scenario.SandboxNetworkScenario'>\n",
      "2024-06-19 08:33:27,535 - __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": [
      "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx0rphiwx 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",
      "reply: 'HTTP/1.1 200 OK\\r\\n'\n",
      "header: Date: Wed, 19 Jun 2024 06:33:27 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-06-19 08:33:33,542 - __main__ - DEBUG - >>> activate_network_scenario: sbx0rphiwx\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/sandboxNetworkScenarios/sbx0rphiwx?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"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 08:33:33,760 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbx0rphiwx?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-06-19 08:33:33,763 DEBUG response body: b''\n",
      "2024-06-19 08:33:33,765 - __main__ - DEBUG - activate_network_scenario: result: None\n",
      "2024-06-19 08:33:33,766 - __main__ - INFO - Network scenario activated: 4g-5g-macro-v2x\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reply: 'HTTP/1.1 204 No Content\\r\\n'\n",
      "header: Date: Wed, 19 Jun 2024 06:33:33 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-06-19 08:33:39,774 - __main__ - DEBUG - >>> request_application_instance_id: sbx0rphiwx\n",
      "2024-06-19 08:33:39,778 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-06-19 08:33:39,945 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx HTTP/1.1\" 201 100\n",
      "2024-06-19 08:33:39,947 DEBUG response body: b'{\"id\":\"102da481-2524-4e40-b9b0-8dfc5c7a20f9\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n",
      "2024-06-19 08:33:39,950 - __main__ - DEBUG - request_application_instance_id: result: {'id': '102da481-2524-4e40-b9b0-8dfc5c7a20f9',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "2024-06-19 08:33:39,952 - __main__ - INFO - app_inst_id: <class 'swagger_client.models.application_info.ApplicationInfo'>\n",
      "2024-06-19 08:33:39,954 - __main__ - INFO - app_inst_id: {'id': '102da481-2524-4e40-b9b0-8dfc5c7a20f9',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "2024-06-19 08:33:39,956 - __main__ - 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"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': '102da481-2524-4e40-b9b0-8dfc5c7a20f9',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx 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\": \"102da481-2524-4e40-b9b0-8dfc5c7a20f9\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n",
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Wed, 19 Jun 2024 06:33:39 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"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 08:33:42,961 - __main__ - DEBUG - >>> deletet_application_instance_id: sbx0rphiwx\n",
      "2024-06-19 08:33:42,963 - __main__ - DEBUG - >>> deletet_application_instance_id: 102da481-2524-4e40-b9b0-8dfc5c7a20f9\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-06-19 08:33:42,971 DEBUG Incremented Retry for (url='/sandbox-api/v1/sandboxAppInstances/sbx0rphiwx/102da481-2524-4e40-b9b0-8dfc5c7a20f9'): Retry(total=2, connect=None, read=None, redirect=None, status=None)\n",
      "2024-06-19 08:33:42,971 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx/102da481-2524-4e40-b9b0-8dfc5c7a20f9\n",
      "2024-06-19 08:33:42,972 DEBUG Starting new HTTPS connection (2): 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",
      "2024-06-19 08:33:43,127 DEBUG https://mec-platform.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx/102da481-2524-4e40-b9b0-8dfc5c7a20f9 HTTP/1.1\" 204 0\n",
      "2024-06-19 08:33:43,128 DEBUG response body: b''\n",
      "2024-06-19 08:33:43,129 - __main__ - DEBUG - deletet_application_instance_id: result: None\n",
      "2024-06-19 08:33:43,130 - __main__ - INFO - app_inst_id deleted: 102da481-2524-4e40-b9b0-8dfc5c7a20f9\n",
      "2024-06-19 08:33:43,131 - __main__ - DEBUG - >>> deactivate_network_scenario: sbx0rphiwx\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'DELETE /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx/102da481-2524-4e40-b9b0-8dfc5c7a20f9 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: ''\n",
      "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbx0rphiwx/102da481-2524-4e40-b9b0-8dfc5c7a20f9 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, 19 Jun 2024 06:33:42 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",
      "send: b'DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbx0rphiwx/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"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 08:33:43,246 DEBUG https://mec-platform.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbx0rphiwx/4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-06-19 08:33:43,248 DEBUG response body: b''\n",
      "2024-06-19 08:33:43,250 - __main__ - DEBUG - deactivate_network_scenario: result: None\n",
      "2024-06-19 08:33:43,254 - __main__ - INFO - Network scenario deactivated: 4g-5g-macro-v2x\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reply: 'HTTP/1.1 204 No Content\\r\\n'\n",
      "header: Date: Wed, 19 Jun 2024 06:33:42 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": [