diff --git a/.env b/.env index 766f8f3..81d33ed 100755 --- a/.env +++ b/.env @@ -35,12 +35,6 @@ OXP_TOPOLOGY_URN="urn:sdx:topology:" FLASK_APP='swagger_server/__main__:main' OXP_PULL_INTERVAL='5' # Swagger NGINX -TOPOLOGY_1='/topology/ampath.net' -TOPOLOGY_2='/topology/sax.net' -TOPOLOGY_3='/topology/tenet.net' -CONNECTION_1='/connection/ampath.net' -CONNECTION_2='/connection/sax.net' -CONNECTION_3='/connection/tenet.ac.za' COMMAND_1='/ampath.net(.*)' COMMAND_2='/sax.net(.*)' COMMAND_3='/tenet.ac.za(.*)' diff --git a/docker-compose.yml b/docker-compose.yml index b2851cc..84570bf 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -222,12 +222,6 @@ services: - ./os-base/nginx-base:/oxpoapi environment: SWAGGER_JSON: /oxpoapi/oxpoapi.json - TOPOLOGY_1: ${TOPOLOGY_1} - TOPOLOGY_2: ${TOPOLOGY_2} - TOPOLOGY_3: ${TOPOLOGY_3} - CONNECTION_1: ${CONNECTION_1} - CONNECTION_2: ${CONNECTION_2} - CONNECTION_3: ${CONNECTION_3} COMMAND_1: ${COMMAND_1} COMMAND_2: ${COMMAND_2} COMMAND_3: ${COMMAND_3} diff --git a/os-base/nginx-base/default.conf.template b/os-base/nginx-base/default.conf.template index 7ab8354..c77e87e 100755 --- a/os-base/nginx-base/default.conf.template +++ b/os-base/nginx-base/default.conf.template @@ -42,24 +42,6 @@ include templates/embedding.conf; } - location $TOPOLOGY_1 - { - rewrite ^/topology(.*)$ /topology break; - proxy_pass $URL_1/topology; - } - - location $TOPOLOGY_2 - { - rewrite ^/topology(.*)$ /topology break; - proxy_pass $URL_2/topology; - } - - location $TOPOLOGY_3 - { - rewrite ^/topology(.*)$ /topology break; - proxy_pass $URL_3/topology; - } - location ~* $COMMAND_1 { rewrite $COMMAND_1 $1 break; @@ -78,22 +60,4 @@ proxy_pass $URL_3; } - location $CONNECTION_1 - { - rewrite ^/connection(.*)$ /connection break; - proxy_pass $URL_1/connection; - } - - location $CONNECTION_2 - { - rewrite ^/connection(.*)$ /connection break; - proxy_pass $URL_2/connection; - } - - location $CONNECTION_3 - { - rewrite ^/connection(.*)$ /connection break; - proxy_pass $URL_3/connection; - } - } diff --git a/os-base/nginx-base/oxpoapi.json b/os-base/nginx-base/oxpoapi.json index f252ca8..b641ca5 100755 --- a/os-base/nginx-base/oxpoapi.json +++ b/os-base/nginx-base/oxpoapi.json @@ -18,20 +18,20 @@ ], "tags": [ { - "name": "topology", - "description": "Everything about your domain topology", + "name": "/sdx/topology", + "description": "Get the SDX converted Topology", "externalDocs": { "description": "Find out more", "url": "https://www.atlanticwave-sdx.net" } }, { - "name": "node", - "description": "everything about a node in your domain" + "name": "/switch/operation/dpId", + "description": "operation: enable | disable, dpId: aa:00:00:00:00:00:00:01 | all" }, { - "name": "link", - "description": "everything about a link in your domain" + "name": "/link/operation/dpId", + "description": "operation: enable | disable, dpId: aa:00:00:00:00:00:00:01 | all" }, { "name": "user", @@ -43,35 +43,10 @@ } ], "paths": { - "/topology/{url}": { - "get": { - "tags": [ - "topology" - ], - "summary": "Get SDX Topology", - "description": "Get SDX topology", - "parameters": [ - { - "in": "path", - "name": "url", - "type": "string", - "required": true - } - ], - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": {} - } - } - } - } - }, "/{url}{command}": { "get": { "tags": [ - "switch" + "url: ampath.net, command: /sdx/topology" ], "summary": "Operation Command", "description": "Operation Command", diff --git a/topology-conversion/controllers/operational_controller.py b/topology-conversion/controllers/operational_controller.py new file mode 100755 index 0000000..ae14a2b --- /dev/null +++ b/topology-conversion/controllers/operational_controller.py @@ -0,0 +1,60 @@ +""" Operational events controller """ +import os +import requests +OXP_TOPOLOGY_URL = os.environ.get("OXP_TOPOLOGY_URL") + + +def get_operational_event(): + """getting operational event""" + response = requests.get(OXP_TOPOLOGY_URL, timeout=10) + if response.status_code == 200: + oxp_topology = response.json() + result = oxp_topology["topology"] + print("get_oxp_topology result: {result}") + return result + return { + "error:": "Failed to retrieve data", + "status_code:": response.status_code} + + +def get_topology_object(topology_object): + """getting topology object""" + url = OXP_TOPOLOGY_URL + topology_object + response = requests.get(url, timeout=10) + return response.json() + + +def post_topology_object(topology_object): + """getting topology object""" + url = OXP_TOPOLOGY_URL + topology_object + response = requests.post(url, timeout=10) + print(response.json()) + print(response.status_code) + return response.json() + + +def get_switch_enable(dp_id): + """getting switch enable""" + print("#####################################") + print("######### switch enable ##########") + print("######### %s ##########", dp_id) + print("#####################################") + if dp_id == "all": + switches = get_topology_object("switches") + if "switches" in switches: + for key in switches["switches"].keys(): + dp_id = switches["switches"][key]["id"] + topology_object = "switches/" + dp_id + "/enable" + switch_enable = post_topology_object(topology_object) + print(switch_enable) + + return f"switch/enable/{dp_id}" + + +def get_switch_disable(dp_id): + """getting switch disable""" + print("#####################################") + print("######### switch disable ##########") + print("######### %s ##########", dp_id) + print("#####################################") + return f"switch/disable/{dp_id}" diff --git a/topology-conversion/controllers/topology_controller.py b/topology-conversion/controllers/topology_controller.py index 073f3c5..ee5ac12 100755 --- a/topology-conversion/controllers/topology_controller.py +++ b/topology-conversion/controllers/topology_controller.py @@ -61,21 +61,3 @@ def convert_topology(): logger.info("convert_topology Error, status code 401:{err}") result = {"convert_topology Error": err, "status_code": 401} return result - - -def get_switch_enable(dp_id): - """getting switch enable""" - logger.info("#####################################") - logger.info("######### switch enable ##########") - logger.info("######### %s ##########", dp_id) - logger.info("#####################################") - return f"switch/enable/{dp_id}" - - -def get_switch_disable(dp_id): - """getting switch disable""" - logger.info("#####################################") - logger.info("######### switch disable ##########") - logger.info("######### %s ##########", dp_id) - logger.info("#####################################") - return f"switch/disable/{dp_id}" diff --git a/topology-conversion/swagger/swagger.yaml b/topology-conversion/swagger/swagger.yaml index 9ef2e86..16d083b 100755 --- a/topology-conversion/swagger/swagger.yaml +++ b/topology-conversion/swagger/swagger.yaml @@ -2,14 +2,14 @@ openapi: 3.0.0 info: title: Convert Topology API description: This API converts network topology data retrieved from a Kytos SDN controller into a format suitable for SDX (Software Defined Exchange). - version: 1.0.0 + version: 2.0.0 servers: - url: / - url: http://0.0.0.0 paths: - /topology: + /sdx/topology: get: tags: - Topology @@ -55,7 +55,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - x-openapi-router-controller: controllers.topology_controller + x-openapi-router-controller: controllers.operational_controller /switch/disable/{dpId}: get: tags: @@ -81,7 +81,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - x-openapi-router-controller: controllers.topology_controller + x-openapi-router-controller: controllers.operational_controller diff --git a/topology-conversion/tox.ini b/topology-conversion/tox.ini new file mode 100644 index 0000000..eb0331a --- /dev/null +++ b/topology-conversion/tox.ini @@ -0,0 +1,25 @@ +[tox] +setupdir = ./app +envlist = py39,coverage,lint + +[testenv] +whitelist_externals = rm +deps = + -Urrequirements/dev.txt +setenv= + PYTHONPATH = {toxworkdir}/py39/var/lib/kytos/:{envdir} + +commands = + pytest --cov + +[testenv:coverage] +skip_install = true +envdir = {toxworkdir}/py39 +commands= + python3 setup.py coverage {posargs} + + +[testenv:lint] +skip_install = true +envdir = {toxworkdir}/py39 +commands = python3 setup.py lint