Skip to content

Commit 51dd695

Browse files
committed
fix: input is now rfc 7951 compliant
Change-Id: I8ef1c7a7da382cfa51d24aff27065fd4a38d5a3a
1 parent b3409e4 commit 51dd695

15 files changed

Lines changed: 11052 additions & 5598 deletions

gnpyapi/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
from flask import Flask
66

7-
API_VERSION = "/api/v0.1"
7+
API_VERSION = "/api/v0.2"
88

99
app = Flask(__name__)
1010

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
# coding: utf-8
2+
import json
23

34
from flask import request
45

56
from gnpyapi.core import app
67
from gnpyapi.core.exception.equipment_error import EquipmentError
78
from gnpyapi.core.exception.topology_error import TopologyError
89
from gnpyapi.core.service.path_request_service import PathRequestService
10+
from gnpy.tools.convert_legacy_yang import yang_to_legacy
911
from gnpyapi.core import API_VERSION
1012

1113
PATH_REQUEST_BASE_PATH = '/path-request'
1214

1315

1416
@app.route(API_VERSION + PATH_REQUEST_BASE_PATH, methods=['POST'])
1517
def path_request(path_request_service: PathRequestService):
16-
data = request.json
17-
service = data['gnpy-api:service']
18-
if 'gnpy-api:topology' in data:
19-
topology = data['gnpy-api:topology']
18+
is_legacy = 'gnpy-api:api' not in request.json
19+
if not is_legacy:
20+
legacy_data = yang_to_legacy(json.loads(request.json))
21+
service = legacy_data['gnpy-path-computation:services']
22+
topology = legacy_data['gnpy-network-topology:topology']
23+
equipment = yang_to_legacy(json.loads(request.json)["gnpy-api:api"]['gnpy-eqpt-config:equipment'])
2024
else:
21-
raise TopologyError('No topology found in request')
22-
if 'gnpy-api:equipment' in data:
23-
equipment = data['gnpy-api:equipment']
24-
else:
25-
raise EquipmentError('No equipment found in request')
25+
data = request.json
26+
service = data['gnpy-api:service']
27+
if 'gnpy-api:topology' in data:
28+
topology = data['gnpy-api:topology']
29+
else:
30+
raise TopologyError('No topology found in request')
31+
if 'gnpy-api:equipment' in data:
32+
equipment = data['gnpy-api:equipment']
33+
else:
34+
raise EquipmentError('No equipment found in request')
2635

2736
return path_request_service.path_request(topology, equipment, service), 201

gnpyapi/core/route/status_route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
@app.route(API_VERSION + '/status', methods=['GET'])
77
def api_status():
8-
return {"version": "v0.1", "status": "ok"}, 200
8+
return {"version": "v0.2", "status": "ok"}, 200

gnpyapi/core/service/path_request_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from gnpy.tools.json_io import results_to_json, load_eqpt_topo_from_json
77
from gnpy.tools.worker_utils import designed_network, planning
88
from gnpyapi.core.exception.topology_error import TopologyError
9-
109
from gnpyapi.core.exception.equipment_error import EquipmentError
1110

1211
_logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)