Skip to content

Commit

Permalink
universal command #20
Browse files Browse the repository at this point in the history
  • Loading branch information
student committed Jun 26, 2024
1 parent 4945eed commit f92a64c
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 102 deletions.
6 changes: 0 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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(.*)'
Expand Down
6 changes: 0 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
36 changes: 0 additions & 36 deletions os-base/nginx-base/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
39 changes: 7 additions & 32 deletions os-base/nginx-base/oxpoapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
60 changes: 60 additions & 0 deletions topology-conversion/controllers/operational_controller.py
Original file line number Diff line number Diff line change
@@ -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}"
18 changes: 0 additions & 18 deletions topology-conversion/controllers/topology_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
8 changes: 4 additions & 4 deletions topology-conversion/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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



Expand Down
25 changes: 25 additions & 0 deletions topology-conversion/tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f92a64c

Please sign in to comment.