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
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 = {}
import os
import uuid
import hashlib
+import json
from flask import Flask, request
import flask_restful as fr
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
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()