From 64b4550b56d1d20627e0c5f715449c665ec79c84 Mon Sep 17 00:00:00 2001 From: peusterm Date: Wed, 16 Mar 2016 21:15:14 +0100 Subject: [PATCH] Completed REST api --- src/emuvim/api/sonata/README.md | 14 ++++++++++++-- src/emuvim/api/sonata/dummygatekeeper.py | 14 +++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/emuvim/api/sonata/README.md b/src/emuvim/api/sonata/README.md index d44ed27..b867965 100644 --- a/src/emuvim/api/sonata/README.md +++ b/src/emuvim/api/sonata/README.md @@ -12,7 +12,8 @@ To list all uploaded packages do: To instantiate (start) a service do: -* `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"` +* Specific service: `curl -X POST http://127.0.0.1:8000/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:8000/api/instantiations -d "{}"` To list all running services do: @@ -62,7 +63,16 @@ _Note: This API should converge to the API of the original GK as much as possibl GET - -{service_instance_uuid_list: ["de4567-f3b9-43ac-ac6b-3d27b461123", "de4567-f3b9-43ac-ac6b-3d27b461124", "de4567-f3b9-43ac-ac6b-3d27b461125"]} + +{ + "service_instance_list": [ + [ + "9da044b3-1f7a-40e6-a9b3-9e83a9834249", + "9371df14-a595-436a-92b5-fc243b74a9d7" + ] + ] +} + diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index 495ac04..29ebc0b 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -288,9 +288,17 @@ class Instantiations(fr.Resource): Will return a new UUID to identify the running service instance. :return: UUID """ + # try to extract the service uuid from the request json_data = request.get_json(force=True) - service_uuid = list(GK.services.iterkeys())[0] #json_data.get("service_uuid") # TODO only for quick testing + service_uuid = json_data.get("service_uuid") + + # lets be a bit fuzzy here to make testing easier + if service_uuid is None and len(GK.services) > 0: + # if we don't get a service uuid, we simple start the first service in the list + service_uuid = list(GK.services.iterkeys())[0] + if service_uuid in GK.services: + # ok, we have a service uuid, lets start the service service_instance_uuid = GK.services.get(service_uuid).start_service() return {"service_instance_uuid": service_instance_uuid} return "Service not found", 404 @@ -300,8 +308,8 @@ class Instantiations(fr.Resource): Returns a list of UUIDs containing all running services. :return: dict / list """ - # TODO implement method - return {"service_instance_uuid_list": list()} + return {"service_instance_list": [ + list(s.instances.iterkeys()) for s in GK.services.itervalues()]} # create a single, global GK object -- 2.25.1