From 26455858b9ed9f84c2fc87a2df83ac13bbed1d09 Mon Sep 17 00:00:00 2001 From: peusterm Date: Tue, 8 Mar 2016 14:23:53 +0100 Subject: [PATCH] More documentation of the dummy gatekeeper API --- src/emuvim/api/sonata/README.md | 4 +-- src/emuvim/api/sonata/__init__.py | 7 +++++ src/emuvim/api/sonata/dummygatekeeper.py | 30 +++++++++++++++++-- .../examples/sonata_y1_demo_topology_1.py | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/emuvim/api/sonata/README.md b/src/emuvim/api/sonata/README.md index 1845489..969ba22 100644 --- a/src/emuvim/api/sonata/README.md +++ b/src/emuvim/api/sonata/README.md @@ -12,11 +12,11 @@ To list all uploaded packages do: To instantiate (start) a service do: -* `curl ...` +* `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"` To list all running services do: -* `curl ...` +* `curl http://127.0.0.1:8000/api/instantiations` ## API definition diff --git a/src/emuvim/api/sonata/__init__.py b/src/emuvim/api/sonata/__init__.py index 200337a..14182c5 100644 --- a/src/emuvim/api/sonata/__init__.py +++ b/src/emuvim/api/sonata/__init__.py @@ -11,6 +11,13 @@ import dummygatekeeper as dgk class SonataDummyGatekeeperEndpoint(object): + """ + Creates and starts a REST API based on Flask in an + additional thread. + + Can connect this API to data centers defined in an emulator + topology. + """ def __init__(self, listenip, port): self.dcs = {} diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index e89c007..f258e49 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -9,6 +9,7 @@ import logging import os import uuid import hashlib +import json from flask import Flask, request import flask_restful as fr @@ -48,7 +49,10 @@ class Packages(fr.Resource): def post(self): """ + Upload a *.son service package to the dummy gatekeeper. + We expect request with a *.son file and store it in UPLOAD_FOLDER + :return: UUID """ try: # get file contents @@ -71,18 +75,38 @@ class Packages(fr.Resource): return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed"} def get(self): + """ + Return a list of UUID's of uploaded service packages. + :return: dict/list + """ return {"service_uuid_list": list(GK.packages.iterkeys())} class Instantiations(fr.Resource): def post(self): - # TODO implement method - pass + """ + Instantiate a service specified by its UUID. + Will return a new UUID to identify the running service instance. + :return: UUID + """ + # TODO implement method (start real service) + json_data = request.get_json(force=True) + service_uuid = json_data.get("service_uuid") + if service_uuid is not None: + service_instance_uuid = str(uuid.uuid4()) + GK.instantiations[service_instance_uuid] = service_uuid + logging.info("Starting service %r" % service_uuid) + return {"service_instance_uuid": service_instance_uuid} + return None def get(self): + """ + Returns a list of UUIDs containing all running services. + :return: dict / list + """ # TODO implement method - pass + return {"service_instance_uuid_list": list(GK.instantiations.iterkeys())} # create a single, global GK object GK = Gatekeeper() diff --git a/src/emuvim/examples/sonata_y1_demo_topology_1.py b/src/emuvim/examples/sonata_y1_demo_topology_1.py index ea33e80..7731fd2 100644 --- a/src/emuvim/examples/sonata_y1_demo_topology_1.py +++ b/src/emuvim/examples/sonata_y1_demo_topology_1.py @@ -48,4 +48,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() -- 2.25.1