Skip to content

Commit

Permalink
Fake API implementation (according to raml/api.raml) (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
maretskiy authored and boris-42 committed Nov 23, 2016
1 parent fd3e9d6 commit c749cf1
Show file tree
Hide file tree
Showing 14 changed files with 474 additions and 199 deletions.
51 changes: 0 additions & 51 deletions ceagle/api/v1/cloud_status.py

This file was deleted.

16 changes: 7 additions & 9 deletions ceagle/api/v1/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

import flask

from ceagle.api_fake_data import fake_infra

infra = flask.Blueprint("infra", __name__)

bp_region = flask.Blueprint("infra", __name__)

@infra.route("/")
def get_infrastructure():
return flask.jsonify({"result": {"infrastructure": "dummy"}})


@infra.route("/<page>")
def get_infrastructure_page(page):
return flask.jsonify({"result": {"infrastructure": page}})
@bp_region.route("/<region>/infra")
@fake_infra.get_region_infra
def get_region_infra(region):
return flask.jsonify("fixme!")


def get_blueprints():
return [["/infra", infra]]
return [["/region", bp_region]]
32 changes: 32 additions & 0 deletions ceagle/api/v1/regions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2016: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import flask

from ceagle.api_fake_data import fake_regions


bp = flask.Blueprint("regions", __name__)


@bp.route("/", defaults={"detailed": False})
@bp.route("/detailed", defaults={"detailed": True})
@fake_regions.get_regions
def get_regions(detailed):
return flask.jsonify({"fixme"})


def get_blueprints():
return [["/regions", bp]]
77 changes: 77 additions & 0 deletions ceagle/api/v1/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2016: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import flask

from ceagle.api_fake_data import fake_status


bp_status = flask.Blueprint("status", __name__)
bp_region_status = flask.Blueprint("region", __name__)


@bp_status.route("/<period>")
@fake_status.get_status
def get_status(period):
return flask.jsonify("fixme!")


@bp_status.route("/health/<period>")
@fake_status.get_status_health
def get_status_health(period):
return flask.jsonify("fixme!")


@bp_status.route("/performance/<period>")
@fake_status.get_status_performance
def get_status_performance(period):
return flask.jsonify("fixme!")


@bp_status.route("/availability/<period>")
@fake_status.get_status_availability
def get_status_availability(period):
return flask.jsonify("fixme!")


@bp_region_status.route("/<region>/status/<period>")
@fake_status.get_region_status
def get_region_status(region, period):
return flask.jsonify("fixme!")


@bp_region_status.route("/<region>/status/health/<period>")
@fake_status.get_region_status_health
def get_region_status_health(region, period):
return flask.jsonify("fixme!")


@bp_region_status.route("/<region>/status/performance/<period>")
@fake_status.get_region_status_performance
def get_region_status_performance(region, period):
return flask.jsonify("fixme!")


@bp_region_status.route("/<region>/status/availability/<period>")
@fake_status.get_region_status_availability
def get_region_status_availability(region, period):
return flask.jsonify("fixme!")


def get_blueprints():
return [
["/status", bp_status],
["/region", bp_region_status]
]
121 changes: 0 additions & 121 deletions ceagle/api_fake_data/cloud_status_data.py

This file was deleted.

46 changes: 46 additions & 0 deletions ceagle/api_fake_data/fake_infra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2016: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import flask

from ceagle.api_fake_data import base
from ceagle.api_fake_data import fake_regions


def generate_infra_services():
return [
{
"menu": "Jenkins",
"title": "Jenkins CI/CD system",
"description": "Some description about this service",
"url": "https://1.2.3.4:12345"
},
{
"menu": "Stacklight",
"title": "Logging, Metering and Alerting systems",
"description": "Some description about this service",
"url": "https://1.2.3.4:12345"
}]


@base.api_handler
def get_region_infra(region):
data = fake_regions.regions(True).get(region)

if not data:
return flask.jsonify({"error": "Region '%s' not found" % region}), 404

services = generate_infra_services()
return flask.jsonify({"region": region, "services": services})

0 comments on commit c749cf1

Please sign in to comment.