Skip to content

Commit ed20c68

Browse files
committed
fix: input is now rfc 7951 compliant
Change-Id: I8ef1c7a7da382cfa51d24aff27065fd4a38d5a3a
1 parent 18181a7 commit ed20c68

17 files changed

Lines changed: 11055 additions & 5777 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: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
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+
data = json.loads(request.json)['gnpy-api:api']
21+
service = yang_to_legacy(data['gnpy-path-computation:services'])
22+
if 'gnpy-network-topology:topology' in data:
23+
topology = yang_to_legacy(data['gnpy-network-topology:topology'])
24+
else:
25+
raise TopologyError('No topology found in request')
26+
if 'gnpy-eqpt-config:equipment' in data:
27+
equipment = yang_to_legacy(data['gnpy-eqpt-config:equipment'])
28+
else:
29+
raise EquipmentError('No equipment found in request')
2030
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')
31+
data = request.json
32+
service = data['gnpy-api:service']
33+
if 'gnpy-api:topology' in data:
34+
topology = data['gnpy-api:topology']
35+
else:
36+
raise TopologyError('No topology found in request')
37+
if 'gnpy-api:equipment' in data:
38+
equipment = data['gnpy-api:equipment']
39+
else:
40+
raise EquipmentError('No equipment found in request')
2641

2742
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)