Skip to content
MEC application.ipynb 246 KiB
Newer Older
   "metadata": {},
   "source": [
    "#### Subscribing to application termination"
   ]
  },
Yann Garcia's avatar
Yann Garcia committed
  {
   "cell_type": "code",
   "execution_count": 16,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [],
   "source": [
Yann Garcia's avatar
Yann Garcia committed
    "def send_subscribe_termination(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo) -> object:\n",
    "    global MEC_PLTF, logger\n",
    "\n",
    "    logger.debug('>>> send_subscribe_termination: ' + app_inst_id.id)\n",
    "    try:\n",
    "        url = '/{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions'\n",
    "        logger.debug('send_subscribe_termination: url: ' + url)\n",
    "        path_params = {}\n",
    "        path_params['sandbox_name'] = sandbox_name\n",
    "        path_params['mec_pltf'] = MEC_PLTF\n",
    "        path_params['app_inst_id'] = app_inst_id.id\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = 'application/json'  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = 'application/json'  # noqa: E501\n",
    "        # Body\n",
    "        dict_body = {}\n",
    "        dict_body['subscriptionType'] = 'AppTerminationNotificationSubscription'\n",
    "        dict_body['callbackReference'] = 'http://yanngarcia.ddns.net/mec011/v2/termination' # FIXME To be parameterized\n",
    "        dict_body['appInstanceId'] = app_inst_id.id\n",
    "        (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, path_params = path_params, body=dict_body, async_req=False)\n",
Yann Garcia's avatar
Yann Garcia committed
    "        return (result, extract_sub_id(headers['Location']), headers['Location'])\n",
    "    except ApiException as e:\n",
    "        logger.error('Exception when calling call_api: %s\\n' % e)\n",
    "    return None\n",
    "    # End of function send_subscribe_termination"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Extracting subscription identifier"
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_sub_id(resource_url: str) -> str:\n",
    "    global logger\n",
    "\n",
    "    logger.debug('>>> extract_sub_id: resource_url: ' + resource_url)\n",
    "\n",
    "    res = urllib3.util.parse_url(resource_url)\n",
    "    if res is not None and res.path is not None and res.path != '':\n",
    "        id = res.path.rsplit('/', 1)[-1]\n",
    "        if id is not None:\n",
    "            return id\n",
    "\n",
    "    return None\n",
    "    # End of function extract_sub_id"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Delete subscription to application termination"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def delete_subscribe_termination(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo, sub_id: str) -> int:\n",
    "    global MEC_PLTF, logger\n",
    "    logger.debug('>>> delete_subscribe_termination: ' + app_inst_id.id)\n",
    "        url = '/{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}'\n",
    "        logger.debug('delete_subscribe_termination: url: ' + url)\n",
    "        path_params = {}\n",
    "        path_params['sandbox_name'] = sandbox_name\n",
    "        path_params['mec_pltf'] = MEC_PLTF\n",
    "        path_params['app_inst_id'] = app_inst_id.id\n",
    "        path_params['sub_id'] = sub_id\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = 'application/json'  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = 'application/json'  # noqa: E501\n",
    "        service_api.call_api(url, 'DELETE', header_params=header_params, path_params = path_params, async_req=False)\n",
    "        return 0\n",
    "    except ApiException as e:\n",
    "        logger.error('Exception when calling call_api: %s\\n' % e)\n",
    "    return -1\n",
    "    # End of function delete_subscribe_termination"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, it is time now to create the our fifth iteration of our MEC application.\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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 identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "- Send READY confirmation\n",
    "- Subscribe to AppTerminationNotificationSubscription\n",
    "- Check list of services\n",
    "- Delete AppTerminationNotification subscription\n",
    "- Delete our application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "- Deactivate a network scenario\n",
    "- Logout\n",
    "- Check that logout is effective\n"
   ]
  },
  {
   "cell_type": "code",
Yann Garcia's avatar
Yann Garcia committed
   "execution_count": 19,
   "metadata": {},
Yann Garcia's avatar
Yann Garcia committed
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:11:22,392 - __main__ - DEBUG - Starting at 20241010-151122\n",
      "2024-10-10 15:11:22,393 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n",
      "2024-10-10 15:11:22,395 - __main__ - DEBUG - >>> process_login\n",
      "2024-10-10 15:11:22,397 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n",
      "2024-10-10 15:11:22,617 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n",
      "2024-10-10 15:11:22,621 DEBUG response body: b'{\"user_code\":\"sbxbr4pfog\",\"verification_uri\":\"\"}'\n",
      "2024-10-10 15:11:22,623 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbxbr4pfog', 'verification_uri': ''}\n",
      "2024-10-10 15:11:22,625 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbxbr4pfog\n",
      "2024-10-10 15:11:22,627 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE :      \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:11:22 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": [
      "2024-10-10 15:11:25,656 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbxbr4pfog HTTP/1.1\" 200 29\n",
      "2024-10-10 15:11:25,658 DEBUG response body: b'{\"sandbox_name\":\"sbxbr4pfog\"}'\n",
      "2024-10-10 15:11:25,661 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbxbr4pfog'}\n",
      "2024-10-10 15:11:25,662 - __main__ - INFO - Sandbox created: sbxbr4pfog\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'GET /sandbox-api/v1/namespace?user_code=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:11:25 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-10-10 15:11:31,672 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbxbr4pfog\n",
      "2024-10-10 15:11:31,673 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "2024-10-10 15:11:31,870 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxbr4pfog HTTP/1.1\" 200 186\n",
      "2024-10-10 15:11:31,872 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"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-10-10 15:11:31,875 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'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-10-10 15:11:31,877 - __main__ - INFO - nw_scenarios: <class 'swagger_client.models.sandbox_network_scenario.SandboxNetworkScenario'>\n",
      "2024-10-10 15:11:31,879 - __main__ - INFO - nw_scenarios: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'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=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:11:31 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 186\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:11:37,888 - __main__ - DEBUG - >>> activate_network_scenario: sbxbr4pfog\n",
      "2024-10-10 15:11:37,970 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-10-10 15:11:37,972 DEBUG response body: b''\n",
      "2024-10-10 15:11:37,974 - __main__ - INFO - Network scenario activated: 4g-5g-macro-v2x\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:11: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"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:11:49,979 - __main__ - DEBUG - >>> request_application_instance_id: sbxbr4pfog\n",
      "2024-10-10 15:11:49,983 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.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\": \"8cbaee38-3c41-467d-b915-65887dd6f686\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:11:50,215 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog HTTP/1.1\" 201 100\n",
      "2024-10-10 15:11:50,217 DEBUG response body: b'{\"id\":\"8cbaee38-3c41-467d-b915-65887dd6f686\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n",
      "2024-10-10 15:11:50,222 - __main__ - DEBUG - request_application_instance_id: result: {'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "2024-10-10 15:11:50,225 - __main__ - INFO - app_inst_id: {'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:11:50 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-10-10 15:11:56,234 - __main__ - DEBUG - >>> send_ready_confirmation: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:11:56,236 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n",
      "2024-10-10 15:11:56,240 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n",
      "2024-10-10 15:11:56,389 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/confirm_ready HTTP/1.1\" 204 0\n",
      "2024-10-10 15:11:56,391 DEBUG response body: b''\n",
      "2024-10-10 15:11:56,393 - __main__ - DEBUG - >>> send_subscribe_termination: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:11:56,394 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n",
      "2024-10-10 15:11:56,417 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions HTTP/1.1\" 201 367\n",
      "2024-10-10 15:11:56,421 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\"}},\"appInstanceId\":\"8cbaee38-3c41-467d-b915-65887dd6f686\"}'\n",
      "2024-10-10 15:11:56,424 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\n",
      "2024-10-10 15:11:56,427 - __main__ - INFO - result: <swagger_client.rest.RESTResponse object at 0x7e5a763372b0>\n",
      "2024-10-10 15:11:56,430 - __main__ - INFO - sub_id: sub-C2pdhFbqIHzPTuiy\n",
      "2024-10-10 15:11:56,432 - __main__ - INFO - data: {'subscriptionType': 'AppTerminationNotificationSubscription', 'callbackReference': 'http://yanngarcia.ddns.net/mec011/v2/termination', '_links': {'self': {'href': 'https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy'}}, 'appInstanceId': '8cbaee38-3c41-467d-b915-65887dd6f686'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\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'{\"indication\": \"READY\"}'\n",
      "reply: 'HTTP/1.1 204 No Content\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:11:56 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'POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\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'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"8cbaee38-3c41-467d-b915-65887dd6f686\"}'\n",
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:11:56 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 367\n",
      "header: Connection: keep-alive\n",
      "header: Location: https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:12:02,442 - __main__ - DEBUG - >>> delete_subscribe_termination: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:12:02,445 - __main__ - DEBUG - delete_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}\n",
      "2024-10-10 15:12:02,471 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy HTTP/1.1\" 204 0\n",
      "2024-10-10 15:12:02,473 DEBUG response body: b''\n",
      "2024-10-10 15:12:02,475 - __main__ - INFO - app_inst_id deleted: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:12:02,479 - __main__ - DEBUG - >>> delete_application_instance_id: sbxbr4pfog\n",
      "2024-10-10 15:12:02,482 - __main__ - DEBUG - >>> delete_application_instance_id: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:12:02,485 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'DELETE /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy HTTP/1.1\\r\\nHost: mec-platform2.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 204 No Content\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:12: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",
      "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog/8cbaee38-3c41-467d-b915-65887dd6f686 HTTP/1.1\\r\\nHost: mec-platform2.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-10-10 15:12:02,673 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog/8cbaee38-3c41-467d-b915-65887dd6f686 HTTP/1.1\" 204 0\n",
      "2024-10-10 15:12:02,676 DEBUG response body: b''\n",
      "2024-10-10 15:12:02,679 - __main__ - INFO - app_inst_id deleted: 8cbaee38-3c41-467d-b915-65887dd6f686\n",
      "2024-10-10 15:12:02,680 - __main__ - DEBUG - >>> deactivate_network_scenario: sbxbr4pfog\n",
      "2024-10-10 15:12:02,733 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog/4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-10-10 15:12:02,735 DEBUG response body: b''\n",
      "2024-10-10 15:12:02,737 - __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: Thu, 10 Oct 2024 13:12: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",
      "send: b'DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog/4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:12: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-10-10 15:12:14,751 - __main__ - DEBUG - >>> process_logout: sandbox=sbxbr4pfog\n",
      "2024-10-10 15:12:14,754 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "2024-10-10 15:12:14,904 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbxbr4pfog HTTP/1.1\" 204 0\n",
      "2024-10-10 15:12:14,905 DEBUG response body: b''\n",
      "2024-10-10 15:12:14,906 - __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-10-10 15:12:14,907 - __main__ - DEBUG - Stopped at 20241010-151214\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:12:14 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"
     ]
    }
   ],
Yann Garcia's avatar
Yann Garcia committed
   "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 identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "        - Send READY confirmation\n",
    "        \n",
    "        - Subscribe to AppTermination Notification\n",
Yann Garcia's avatar
Yann Garcia committed
    "        - Send Termination\n",
    "        - Delete AppTerminationNotification subscription\n",
    "        - Delete our application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "        - Deactivate a network scenario\n",
    "        - Logout\n",
    "        - Check that logout is effective\n",
    "    \"\"\" \n",
    "    global 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",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Login\n",
    "    sandbox = process_login()\n",
    "    if sandbox is None:\n",
    "        logger.error('Failed to instanciate a MEC Sandbox')\n",
Yann Garcia's avatar
Yann Garcia committed
    "        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",
    "    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",
Yann Garcia's avatar
Yann Garcia committed
    "    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",
Yann Garcia's avatar
Yann Garcia committed
    "        # 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",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "        # Wait for the MEC services are running\n",
    "        time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Request for a new application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "    app_inst_id = request_application_instance_id(sandbox)\n",
    "    if app_inst_id == None:\n",
    "        logger.error('Failed to request an application instance identifier')\n",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('app_inst_id: %s', str(app_inst_id))\n",
    "        time.sleep(STABLE_TIME_OUT)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Send READY confirmation\n",
    "    sub_id = None\n",
    "    if send_ready_confirmation(sandbox, app_inst_id) == -1:\n",
    "        logger.error('Failed to send confirm_ready')\n",
    "    else:\n",
    "        # Subscribe to AppTerminationNotificationSubscription\n",
Yann Garcia's avatar
Yann Garcia committed
    "        result, sub_id, res_url = send_subscribe_termination(sandbox, app_inst_id)\n",
    "        if sub_id == None:\n",
    "            logger.error('Failed to do the subscription')\n",
    "        else:\n",
Yann Garcia's avatar
Yann Garcia committed
    "            logger.info('result: ' + str(result))\n",
    "            logger.info('sub_id: %s', sub_id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "            data = json.loads(result.data)\n",
    "            logger.info('data: ' + str(data))\n",
    "\n",
    "    # Any processing here\n",
    "    time.sleep(STABLE_TIME_OUT)\n",
    "\n",
    "    # Delete AppTerminationNotification subscription\n",
    "    if sub_id is not None:\n",
    "        if delete_subscribe_termination(sandbox, app_inst_id, sub_id) == -1:\n",
    "            logger.error('Failed to delete the application instance identifier')\n",
    "        else:\n",
    "            logger.info('app_inst_id deleted: ' + app_inst_id.id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Delete the application instance identifier\n",
    "    if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n",
    "        logger.error('Failed to delete the application instance identifier')\n",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('app_inst_id deleted: ' + app_inst_id.id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(2 * STABLE_TIME_OUT)\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",
Yann Garcia's avatar
Yann Garcia committed
    "  \n",
    "    logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # End of function process_main\n",
    "\n",
    "if __name__ == '__main__':\n",
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conclusion: Create two procedures for the setup and the termination of our MEC application\n"
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The procedure for the setup of a MEC application\n",
    "This function provides the steps to setup a MEC application and to be ready to use the MEC service exposed by the created MEC Sandbox.\n"
Yann Garcia's avatar
Yann Garcia committed
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mec_app_setup():\n",
    "    This function provides the steps to setup a 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 identifier\n",
    "        - Send READY confirmation\n",
    "        - Subscribe to AppTermination Notification\n",
    "    \"\"\"\n",
    "    global logger, nw_scenarios\n",
    "\n",
    "    # Login\n",
    "    sandbox = process_login()\n",
    "    if sandbox is None:\n",
    "        logger.error('Failed to instanciate a MEC Sandbox')\n",
    "        return\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",
    "        # 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",
    "        # Wait for the MEC services are running\n",
    "        time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
    "\n",
    "    # Request for a new application instance identifier\n",
    "    app_inst_id = request_application_instance_id(sandbox)\n",
    "    if app_inst_id == None:\n",
    "        logger.error('Failed to request an application instance identifier')\n",
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(STABLE_TIME_OUT)\n",
    "    # Send READY confirmation\n",
    "    sub_id = None\n",
    "    if send_ready_confirmation(sandbox, app_inst_id) == -1:\n",
    "        logger.error('Failed to send confirm_ready')\n",
    "    else:\n",
    "        # Subscribe to AppTerminationNotificationSubscription\n",
Yann Garcia's avatar
Yann Garcia committed
    "        result, sub_id, res_url = send_subscribe_termination(sandbox, app_inst_id)\n",
    "        if sub_id == None:\n",
    "            logger.error('Failed to do the subscription')\n",
    "\n",
    "    return (sandbox, app_inst_id, sub_id)\n",
    "    # End of function mec_app_setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The procedure for the termination of a MEC application\n",
    "\n",
    "This function provides the steps to terminate a MEC application.\n",
    "NOTE: All subscriptions done outside of the mec_app_setup function are not deleted."
Yann Garcia's avatar
Yann Garcia committed
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mec_app_termination(sandbox: str, app_inst_id:swagger_client.models.ApplicationInfo, sub_id: str):\n",
    "    \"\"\"\n",
    "    This function provides the steps to setup a 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 identifier\n",
    "        - Send READY confirmation\n",
    "        - Subscribe to AppTermination Notification\n",
    "    \"\"\"\n",
    "    # Delete AppTerminationNotification subscription\n",
    "    if sub_id is not None:\n",
    "        if delete_subscribe_termination(sandbox, app_inst_id, sub_id) == -1:\n",
    "            logger.error('Failed to delete the application instance identifier')\n",
    "\n",
    "    # Delete the application instance identifier\n",
    "    if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n",
    "        logger.error('Failed to delete the application instance identifier')\n",
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(STABLE_TIME_OUT)\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",
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(2 * STABLE_TIME_OUT)\n",
    "\n",
    "    # Logout\n",
    "    process_logout(sandbox)\n",
    "\n",
    "    # End of function mec_app_termination"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following cell descrbes the new basic MEC application architecture. It will be used in the rest of this titorial."
   ]
  },
  {
   "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",
    "        - Mec application setup\n",
    "        - Get UU unicast provisioning information\n",
    "        - Mec application termination\n",
    "    \"\"\" \n",
    "    global 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",
    "    # Setup the MEC application\n",
    "    (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n",
    "\n",
    "    # Any processing here\n",
    "    logger.info('sandbox_name: ' + sandbox_name)\n",
    "    logger.info('app_inst_id: ' + app_inst_id.id)\n",
    "    if sub_id is not None:\n",
    "        logger.info('sub_id: ' + sub_id)\n",
    "    time.sleep(STABLE_TIME_OUT)\n",
    "\n",
    "    # Terminate the MEC application\n",
    "    mec_app_termination(sandbox_name, app_inst_id, sub_id)\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()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create our second MEC application: how to use MEC Services\n",
    "\n",
    "After doing the logging, network scenario activation, MEC application instance creation steps, we are ready to exploit the MEC services exposed by the MEC Sandbox.\n",
    "\n",
    "In this clause, we use the following functionalities provided by MEC-030:\n",
    "- Getting UU unicast provisioning information (ETSI GS MEC 030 Clause 5.5.1)\n",
    "- Subscribe to the V2X message distribution server (ETSI GS MEC 030 Clause 5.5.7)\n",
    "- Delete subscription\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Getting UU unicast provisioning information\n",
    "\n",
    "The purpose is to query provisioning information for V2X communication over Uu unicast."
   ]
  },
  {
   "cell_type": "code",
Yann Garcia's avatar
Yann Garcia committed
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
Yann Garcia's avatar
Yann Garcia committed
    "def send_uu_unicast_provisioning_info(sandbox_name: str, ecgi: str) -> object:\n",
    "    global MEC_PLTF, logger\n",
    "    logger.debug('>>> send_uu_unicast_provisioning_info: ' + ecgi)\n",
    "        url = '/{sandbox_name}/{mec_pltf}/vis/v2/queries/uu_unicast_provisioning_info'\n",
    "        logger.debug('send_uu_unicast_provisioning_info: url: ' + url)\n",
    "        path_params = {}\n",
    "        path_params['sandbox_name'] = sandbox_name\n",
    "        path_params['mec_pltf'] = MEC_PLTF\n",
    "        query_params = []\n",
    "        query_params.append(('location_info', 'ecgi,' + ecgi))\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = 'application/json'  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = 'application/json'  # noqa: E501\n",
Yann Garcia's avatar
Yann Garcia committed
    "        (result, status, header) = service_api.call_api(url, 'GET', header_params=header_params, path_params=path_params, query_params=query_params, async_req=False)\n",
    "        return (result, status, header)\n",
    "    except ApiException as e:\n",
    "        logger.error('Exception when calling call_api: %s\\n' % e)\n",
    "    # End of function send_uu_unicast_provisioning_info"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's create the our second MEC application.\n",
    "The sequence is the following:\n",
    "- Mec application setup\n",
    "- Get UU unicast provisioning information\n",
    "- Mec application termination\n",
    "\n",
    "Note that the UU unicast provisioning information is returned as a JSON string. To de-serialized it into a Python data structure, please refer to clause [Subscribing to V2X message distribution server](#subscribing_to_v2x_message_distribution_server)."
   "cell_type": "code",
Yann Garcia's avatar
Yann Garcia committed
   "execution_count": 25,
Yann Garcia's avatar
Yann Garcia committed
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:20:57,640 - __main__ - DEBUG - Starting at 20241010-152057\n",
      "2024-10-10 15:20:57,643 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n",
      "2024-10-10 15:20:57,645 - __main__ - DEBUG - >>> process_login\n",
      "2024-10-10 15:20:57,649 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "2024-10-10 15:20:57,847 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n",
      "2024-10-10 15:20:57,848 DEBUG response body: b'{\"user_code\":\"sbxizaazi8\",\"verification_uri\":\"\"}'\n",
      "2024-10-10 15:20:57,850 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbxizaazi8', 'verification_uri': ''}\n",
      "2024-10-10 15:20:57,851 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbxizaazi8\n",
      "2024-10-10 15:20:57,852 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE :      \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:20:57 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": [
      "2024-10-10 15:21:00,880 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbxizaazi8 HTTP/1.1\" 200 29\n",
      "2024-10-10 15:21:00,883 DEBUG response body: b'{\"sandbox_name\":\"sbxizaazi8\"}'\n",
      "2024-10-10 15:21:00,886 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbxizaazi8'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'GET /sandbox-api/v1/namespace?user_code=sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:21:00 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-10-10 15:21:06,893 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbxizaazi8\n",
      "2024-10-10 15:21:06,897 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "2024-10-10 15:21:07,050 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxizaazi8 HTTP/1.1\" 200 186\n",
      "2024-10-10 15:21:07,053 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"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-10-10 15:21:07,056 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'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=sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:21:06 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 186\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:21:13,059 - __main__ - DEBUG - >>> activate_network_scenario: sbxizaazi8\n",
      "2024-10-10 15:21:13,152 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbxizaazi8?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-10-10 15:21:13,154 DEBUG response body: b''\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbxizaazi8?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.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: Thu, 10 Oct 2024 13:21:13 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-10-10 15:21:25,169 - __main__ - DEBUG - >>> request_application_instance_id: sbxizaazi8\n",
      "2024-10-10 15:21:25,172 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': '54e0e8fc-efb0-4bff-a9e1-0a1365077934',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.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\": \"54e0e8fc-efb0-4bff-a9e1-0a1365077934\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-10 15:21:25,392 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbxizaazi8 HTTP/1.1\" 201 100\n",
      "2024-10-10 15:21:25,395 DEBUG response body: b'{\"id\":\"54e0e8fc-efb0-4bff-a9e1-0a1365077934\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n",
      "2024-10-10 15:21:25,397 - __main__ - DEBUG - request_application_instance_id: result: {'id': '54e0e8fc-efb0-4bff-a9e1-0a1365077934',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:21:25 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-10-10 15:21:31,404 - __main__ - DEBUG - >>> send_ready_confirmation: 54e0e8fc-efb0-4bff-a9e1-0a1365077934\n",
      "2024-10-10 15:21:31,406 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n",
      "2024-10-10 15:21:31,410 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "2024-10-10 15:21:31,538 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/confirm_ready HTTP/1.1\" 204 0\n",
      "2024-10-10 15:21:31,538 DEBUG response body: b''\n",
      "2024-10-10 15:21:31,539 - __main__ - DEBUG - >>> send_subscribe_termination: 54e0e8fc-efb0-4bff-a9e1-0a1365077934\n",
      "2024-10-10 15:21:31,540 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n",
      "2024-10-10 15:21:31,558 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions HTTP/1.1\" 201 367\n",
      "2024-10-10 15:21:31,558 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\"}},\"appInstanceId\":\"54e0e8fc-efb0-4bff-a9e1-0a1365077934\"}'\n",
      "2024-10-10 15:21:31,559 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\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'{\"indication\": \"READY\"}'\n",
      "reply: 'HTTP/1.1 204 No Content\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:21:31 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'POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\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'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"54e0e8fc-efb0-4bff-a9e1-0a1365077934\"}'\n",
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Thu, 10 Oct 2024 13:21:31 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 367\n",
      "header: Connection: keep-alive\n",
      "header: Location: https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "not enough values to unpack (expected 4, got 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[25], line 37\u001b[0m\n\u001b[1;32m     34\u001b[0m     \u001b[38;5;66;03m# End of function process_main\u001b[39;00m\n\u001b[1;32m     36\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---> 37\u001b[0m     \u001b[43mprocess_main\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "Cell \u001b[0;32mIn[25], line 14\u001b[0m, in \u001b[0;36mprocess_main\u001b[0;34m()\u001b[0m\n\u001b[1;32m     11\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m pwd= \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m os\u001b[38;5;241m.\u001b[39mgetcwd())\n\u001b[1;32m     13\u001b[0m \u001b[38;5;66;03m# Setup the MEC application\u001b[39;00m\n\u001b[0;32m---> 14\u001b[0m (sandbox_name, app_inst_id, sub_id) \u001b[38;5;241m=\u001b[39m \u001b[43mmec_app_setup\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     16\u001b[0m \u001b[38;5;66;03m# Get UU unicast provisioning information\u001b[39;00m\n\u001b[1;32m     17\u001b[0m ecgi \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m268708941961,268711972264\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;66;03m# List of ecgi spearated by a ','\u001b[39;00m\n",
      "Cell \u001b[0;32mIn[24], line 53\u001b[0m, in \u001b[0;36mmec_app_setup\u001b[0;34m()\u001b[0m\n\u001b[1;32m     50\u001b[0m     logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFailed to send confirm_ready\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m     51\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m     52\u001b[0m     \u001b[38;5;66;03m# Subscribe to AppTerminationNotificationSubscription\u001b[39;00m\n\u001b[0;32m---> 53\u001b[0m     result, status, sub_id, res_url \u001b[38;5;241m=\u001b[39m send_subscribe_termination(sandbox, app_inst_id)\n\u001b[1;32m     54\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m sub_id \u001b[38;5;241m==\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m     55\u001b[0m         logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFailed to do the subscription\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 4, got 3)"
     ]
    }
   ],
   "source": [
    "def process_main():\n",
    "    \"\"\"\n",
    "    This is the second sprint of our skeleton of our MEC application:\n",
    "        - Mec application setup\n",
    "        - Get UU unicast provisioning information\n",
    "        - Mec application termination\n",
    "    \"\"\" \n",
    "    global 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",
    "    # Setup the MEC application\n",
    "    (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n",
    "\n",
    "    # Get UU unicast provisioning information\n",
    "    ecgi = \"268708941961,268711972264\" # List of ecgi spearated by a ','\n",
    "    result, status, header = send_uu_unicast_provisioning_info(sandbox_name, ecgi)\n",
    "    logger.info('UU unicast provisioning information: status: %s', str(status))\n",
    "    if status != 200:\n",
    "        logger.error('Failed to get UU unicast provisioning information')\n",
    "    else:\n",
    "        logger.info('UU unicast provisioning information: %s', str(result.data))\n",
    "\n",
    "    # Any processing comes here\n",