From: peusterm Date: Wed, 30 Mar 2016 17:55:01 +0000 (+0200) Subject: made package POST endpoint compatible with original GK endpoint. X-Git-Tag: v3.1~153^2~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=593ca58d734362b0ddc7ca6ac23631d11f94d57e;p=osm%2Fvim-emu.git made package POST endpoint compatible with original GK endpoint. --- diff --git a/src/emuvim/api/sonata/README.md b/src/emuvim/api/sonata/README.md index a1708d4..30586e7 100644 --- a/src/emuvim/api/sonata/README.md +++ b/src/emuvim/api/sonata/README.md @@ -22,20 +22,20 @@ The example starts a small network with two data centers. To upload the file `sonata-demo.son` (from son-schema repo) do: -* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:5000/api/packages` +* `curl -i -X POST -F package=@sonata-demo.son http://127.0.0.1:5000/packages` To list all uploaded packages do: -* `curl http://127.0.0.1:5000/api/packages` +* `curl http://127.0.0.1:5000/packages` To instantiate (start) a service do: -* Specific service: `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"` -* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{}"` +* Specific service: `curl -X POST http://127.0.0.1:5000/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"` +* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/instantiations -d "{}"` To list all running services do: -* `curl http://127.0.0.1:5000/api/instantiations` +* `curl http://127.0.0.1:5000/instantiations` ## API definition @@ -56,28 +56,28 @@ _Note: This API should converge to the API of the original GK as much as possibl Response: -/api/packages +/packages POST - {file-content} as "content-type": "multipart/form-data" {"service_uuid": "c880aaab-f3b9-43ac-ac6b-3d27b46146b7", size=456, sha1=49ee6468dfa4ecbad440d669b249d523a38651be, error: null} -/api/packages +/packages GET - {service_uuid_list: ["c880aaab-f3b9-43ac-ac6b-3d27b46146b7", "c880aaab-f3b9-43ac-ac6b-3d27b46146b8", "c880aaab-f3b9-43ac-ac6b-3d27b46146b9"]} -/api/instantiations +/instantiations POST - {service_uuid: "c880aaab-f3b9-43ac-ac6b-3d27b46146b7"} {service_instance_uuid: "de4567-f3b9-43ac-ac6b-3d27b461123"} -/api/instantiations +/instantiations GET - diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index c69fd9a..6475044 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -272,7 +272,13 @@ class Packages(fr.Resource): try: # get file contents print(request.files) - son_file = request.files['file'] + # lets search for the package in the request + if "package" in request.files: + son_file = request.files["package"] + # elif "file" in request.files: + # son_file = request.files["file"] + else: + return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed. file not found."}, 500 # generate a uuid to reference this package service_uuid = str(uuid.uuid4()) file_hash = hashlib.sha1(str(son_file)).hexdigest() @@ -289,7 +295,7 @@ class Packages(fr.Resource): return {"service_uuid": service_uuid, "size": size, "sha1": file_hash, "error": None} except Exception as ex: LOG.exception("Service package upload failed:") - return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed"} + return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed"}, 500 def get(self): """ @@ -338,8 +344,8 @@ app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 512 * 1024 * 1024 # 512 MB max upload api = fr.Api(app) # define endpoints -api.add_resource(Packages, '/api/packages') -api.add_resource(Instantiations, '/api/instantiations') +api.add_resource(Packages, '/packages') +api.add_resource(Instantiations, '/instantiations') def start_rest_api(host, port, datacenters=dict()):