Move status to /api/status
Also drops /api/v0/test, and redirects / to /api/docs/ db and schema are fixed at 0 since lorax-composer uses yum, not the bdcs metadata.db
This commit is contained in:
parent
0d7e1dacfd
commit
520439a7c4
@ -18,10 +18,11 @@ import logging
|
|||||||
log = logging.getLogger("lorax-composer")
|
log = logging.getLogger("lorax-composer")
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from flask import Flask, send_from_directory
|
from flask import Flask, jsonify, redirect, send_from_directory
|
||||||
from glob import glob
|
from glob import glob
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from pylorax import vernum
|
||||||
from pylorax.api.crossdomain import crossdomain
|
from pylorax.api.crossdomain import crossdomain
|
||||||
from pylorax.api.v0 import v0_api
|
from pylorax.api.v0 import v0_api
|
||||||
from pylorax.sysutils import joinpaths
|
from pylorax.sysutils import joinpaths
|
||||||
@ -34,9 +35,8 @@ server = Flask(__name__)
|
|||||||
__all__ = ["server", "GitLock"]
|
__all__ = ["server", "GitLock"]
|
||||||
|
|
||||||
@server.route('/')
|
@server.route('/')
|
||||||
@crossdomain(origin="*")
|
def server_root():
|
||||||
def hello_world():
|
redirect("/api/docs/")
|
||||||
return 'Hello, World!'
|
|
||||||
|
|
||||||
@server.route("/api/docs/")
|
@server.route("/api/docs/")
|
||||||
@server.route("/api/docs/<path:path>")
|
@server.route("/api/docs/<path:path>")
|
||||||
@ -52,4 +52,26 @@ def api_docs(path=None):
|
|||||||
path="index.html"
|
path="index.html"
|
||||||
return send_from_directory(docs_path, path)
|
return send_from_directory(docs_path, path)
|
||||||
|
|
||||||
|
@server.route("/api/status")
|
||||||
|
@crossdomain(origin="*")
|
||||||
|
def v0_status():
|
||||||
|
"""
|
||||||
|
`/api/v0/status`
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
Return the status of the API Server::
|
||||||
|
|
||||||
|
{ "api": "0",
|
||||||
|
"build": "devel",
|
||||||
|
"db_supported": true,
|
||||||
|
"db_version": "0",
|
||||||
|
"schema_version": "0",
|
||||||
|
"backend": "lorax-composer"}
|
||||||
|
"""
|
||||||
|
return jsonify(backend="lorax-composer",
|
||||||
|
build=vernum,
|
||||||
|
api="0",
|
||||||
|
db_version="0",
|
||||||
|
schema_version="0",
|
||||||
|
db_supported=True)
|
||||||
|
|
||||||
v0_api(server)
|
v0_api(server)
|
||||||
|
@ -49,21 +49,6 @@ used then the API will use the `master` branch for blueprints. If you want to cr
|
|||||||
a new branch use the `new` or `workspace` routes with ?branch=<branch-name> to
|
a new branch use the `new` or `workspace` routes with ?branch=<branch-name> to
|
||||||
store the new blueprint on the new branch.
|
store the new blueprint on the new branch.
|
||||||
|
|
||||||
`/api/v0/test`
|
|
||||||
^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
Return a test string. It is not JSON encoded.
|
|
||||||
|
|
||||||
`/api/v0/status`
|
|
||||||
^^^^^^^^^^^^^^^^
|
|
||||||
Return the status of the API Server::
|
|
||||||
|
|
||||||
{ "api": "0",
|
|
||||||
"build": "devel",
|
|
||||||
"db_supported": false,
|
|
||||||
"db_version": "0",
|
|
||||||
"schema_version": "0" }
|
|
||||||
|
|
||||||
`/api/v0/blueprints/list`
|
`/api/v0/blueprints/list`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
@ -930,16 +915,6 @@ def take_limits(iterable, offset, limit):
|
|||||||
|
|
||||||
def v0_api(api):
|
def v0_api(api):
|
||||||
# Note that Sphinx will not generate documentations for any of these.
|
# Note that Sphinx will not generate documentations for any of these.
|
||||||
@api.route("/api/v0/test")
|
|
||||||
@crossdomain(origin="*")
|
|
||||||
def v0_test():
|
|
||||||
return "API v0 test"
|
|
||||||
|
|
||||||
@api.route("/api/v0/status")
|
|
||||||
@crossdomain(origin="*")
|
|
||||||
def v0_status():
|
|
||||||
return jsonify(build="devel", api="0", db_version="0", schema_version="0", db_supported=False)
|
|
||||||
|
|
||||||
@api.route("/api/v0/blueprints/list")
|
@api.route("/api/v0/blueprints/list")
|
||||||
@crossdomain(origin="*")
|
@crossdomain(origin="*")
|
||||||
def v0_blueprints_list():
|
def v0_blueprints_list():
|
||||||
|
@ -69,17 +69,13 @@ class ServerTestCase(unittest.TestCase):
|
|||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
shutil.rmtree(server.config["REPO_DIR"])
|
shutil.rmtree(server.config["REPO_DIR"])
|
||||||
|
|
||||||
def test_00_hello(self):
|
|
||||||
"""Test /"""
|
|
||||||
resp = self.server.get("/")
|
|
||||||
self.assertEqual(resp.data, 'Hello, World!')
|
|
||||||
|
|
||||||
def test_01_status(self):
|
def test_01_status(self):
|
||||||
"""Test the /api/v0/status route"""
|
"""Test the /api/status route"""
|
||||||
status_dict = {"build":"devel", "api":"0", "db_version":"0", "schema_version":"0", "db_supported":False}
|
status_fields = ["build", "api", "db_version", "schema_version", "db_supported", "backend"]
|
||||||
resp = self.server.get("/api/v0/status")
|
resp = self.server.get("/api/status")
|
||||||
data = json.loads(resp.data)
|
data = json.loads(resp.data)
|
||||||
self.assertEqual(data, status_dict)
|
# Just make sure the fields are present
|
||||||
|
self.assertEqual(sorted(data.keys()), sorted(status_fields))
|
||||||
|
|
||||||
def test_02_blueprints_list(self):
|
def test_02_blueprints_list(self):
|
||||||
"""Test the /api/v0/blueprints/list route"""
|
"""Test the /api/v0/blueprints/list route"""
|
||||||
|
Loading…
Reference in New Issue
Block a user