Skip to content

Commit

Permalink
Add/update API for region(s) infrastrucure
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Maretskiy committed Dec 28, 2016
1 parent 7ff38bf commit a43a3f9
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 89 deletions.
19 changes: 16 additions & 3 deletions ceagle/api/v1/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,29 @@
import flask

from ceagle.api_fake_data import fake_infra
from ceagle import config


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


@bp.route("/<region>/infra")
@bp.route("/region/<region>/infra")
@fake_infra.get_region_infra
def get_region_infra(region):
return flask.jsonify("fixme!")
infra = config.get_config()["services"].get("infra", {}).get(region)
if not infra:
flask.abort(404)
return flask.jsonify({"region": region, "infra": infra})


@bp.route("/regions/infra")
@fake_infra.get_regions_infra
def get_regions_infra():
infra = config.get_config()["services"].get("infra", {})
if not infra:
flask.abort(404)
return flask.jsonify({"infra": infra})


def get_blueprints():
return [["/region", bp]]
return [["", bp]]
62 changes: 43 additions & 19 deletions ceagle/api_fake_data/fake_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,58 @@
# License for the specific language governing permissions and limitations
# under the License.

import itertools

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"
}]
INFRAS = [
[{"id": "horizon",
"title": "Horizon",
"description": "Web UI that manages OpenStack resources",
"urls": [["http://none"]]},
{"id": "git",
"title": "Git Source Control",
"description": ("Gitlab with Git repositories with all "
"projects source code"),
"urls": [["http://none"]]},
{"id": "packages",
"title": "JFrog Artifactory Packages",
"description": ("JFrog Artifactory service that contains "
"all cloud packages & images"),
"urls": [["http://none"]]},
{"id": "stacklight",
"title": "Stacklight",
"description": "Cloud Logging, Metering and Alerting services",
"urls": [["http://none"]]}],
[{"id": "horizon",
"title": "Horizon",
"description": "Web UI that manages OpenStack resources",
"urls": [["http://none"]]},
{"id": "baremetal",
"title": "Baremetal Provisioning",
"description": "MaaS service that manages baremetal infrastructure",
"urls": [["http://none"]]},
{"id": "jenkins",
"title": "Jenkins CI/CD",
"description": "Cloud Continues Integration and Deployment.",
"urls": [["http://none"]]}]]


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

if not data:
regions = fake_regions.regions()
if region not in regions:
return flask.jsonify({"error": "Region '%s' not found" % region}), 404
infra_idx = regions.index(region) % len(INFRAS)
return flask.jsonify({"region": region, "infra": INFRAS[infra_idx]})

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

@base.api_handler
def get_regions_infra():
infras = itertools.cycle(INFRAS)
infra = {region: next(infras) for region in fake_regions.regions()}
return flask.jsonify({"infra": infra})
103 changes: 59 additions & 44 deletions etc/eagle_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,65 @@
"optimization": "http://dummy.example.org/api/optimization",
"security": "http://dummy.example.org/api/security",
"infra": {
"pages": [
{
"title": "Horizon",
"full_title": "Horizon",
"menu": "horzion",
"description": "Web UI that manages OpenStack resources",
"iframe": "http://nan"
},
{
"title": "Baremetal",
"full_title": "Baremetal Provisioning",
"menu": "baremetal",
"description": "MaaS service that manages baremetal infrastructure",
"iframe": "http://nan"
},
{
"title": "Jenkins CI/CD",
"full_title": "Jenkins CI/CD",
"menu": "jenkins",
"description": "Cloud Continues Integration and Deployment.",
"iframe": "http://nan"

},
{
"title": "Source Control",
"full_title": "Git Source Control",
"menu": "git",
"description": "Gitlab with Git repositories with all projects source code",
"iframe": "http://nan"
},
{
"title": "Packages",
"full_title": "JFrog Artifactory Packages",
"menu": "packages",
"description": "JFrog Artifactory service that contains all cloud packages & images",
"iframe": "http://nan"
},
{
"title": "Stacklight",
"full_title": "Stacklight",
"menu": "stacklight",
"description": "Cloud Logging, Metering and Alerting services",
"iframe": "http://nan"
}
"foo_region": [
{
"id": "horizon",
"title": "Horizon",
"description": "Web UI that manages OpenStack resources",
"urls": [
["http://nan"]
]
},
{
"id": "git",
"title": "Git Source Control",
"description": "Gitlab with Git repositories with all projects source code",
"urls": [
["http://nan"]
]
},
{
"id": "packages",
"title": "JFrog Artifactory Packages",
"description": "JFrog Artifactory service that contains all cloud packages & images",
"urls": [
["http://nan"]
]
},
{
"id": "stacklight",
"title": "Stacklight",
"description": "Cloud Logging, Metering and Alerting services",
"urls": [
["http://nan"]
]
}
],
"bar_region": [
{
"id": "horizon",
"title": "Horizon",
"description": "Web UI that manages OpenStack resources",
"urls": [
["http://nan"]
]
},
{
"id": "baremetal",
"title": "Baremetal Provisioning",
"description": "MaaS service that manages baremetal infrastructure",
"urls": [
["http://nan"]
]
},
{
"id": "jenkins",
"title": "Jenkins CI/CD",
"description": "Cloud Continues Integration and Deployment.",
"urls": [
["http://nan"]
]
}
]
}
}
Expand Down
5 changes: 5 additions & 0 deletions raml/abao_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ hooks.before('GET /api/{version}/region/{region}/infra -> 404', function (test,
done();
});

hooks.before('GET /api/{version}/regions/infra -> 200', function (test, done) {
test.request.params = params;
done();
});

hooks.before('GET /api/{version}/security/issues/{period} -> 200', function (test, done) {
test.request.params = params;
done();
Expand Down
15 changes: 14 additions & 1 deletion raml/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ mediaType: application/json
schema: !include schemas/200.json
example: !include response_examples/200/regions_detailed.json

/regions/infra:
get:
description: "Information about infrastructure services for all regions"
responses:
200:
body:
schema: !include schemas/200.json
example: !include response_examples/200/infra.json
404:
body:
schema: !include schemas/404.json
example: !include response_examples/404/region.json

/security/issues/{period}:
uriParameters:
period:
Expand Down Expand Up @@ -144,7 +157,7 @@ mediaType: application/json
200:
body:
schema: !include schemas/200.json
example: !include response_examples/200/infra.json
example: !include response_examples/200/infra_region.json
404:
body:
schema: !include schemas/404.json
Expand Down
71 changes: 56 additions & 15 deletions raml/response_examples/200/infra.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
{
"region": "west-1.hooli.net",
"services": [
{
"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"
}
]
"infra": {
"east-3.hooli.net": [
{
"description": "Web UI that manages OpenStack resources",
"id": "horizon",
"title": "Horizon",
"urls": [
[
"http://none"
]
]
},
{
"description": "Gitlab with Git repositories with all projects source code",
"id": "git",
"title": "Git Source Control",
"urls": [
[
"http://none"
]
]
},
{
"description": "JFrog Artifactory service that contains all cloud packages & images",
"id": "packages",
"title": "JFrog Artifactory Packages",
"urls": [
[
"http://none"
]
]
}
],
"north-2.piedpiper.net": [
{
"description": "Web UI that manages OpenStack resources",
"id": "horizon",
"title": "Horizon",
"urls": [
[
"http://none"
]
]
},
{
"description": "Cloud Continues Integration and Deployment.",
"id": "jenkins",
"title": "Jenkins CI/CD",
"urls": [
[
"http://none"
]
]
}
]
}
}
35 changes: 35 additions & 0 deletions raml/response_examples/200/infra_region.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"infra": [
{
"description": "Web UI that manages OpenStack resources",
"id": "horizon",
"title": "Horizon",
"urls": [
[
"http://none"
]
]
},
{
"description": "MaaS service that manages baremetal infrastructure",
"id": "baremetal",
"title": "Baremetal Provisioning",
"urls": [
[
"http://none"
]
]
},
{
"description": "Cloud Continues Integration and Deployment.",
"id": "jenkins",
"title": "Jenkins CI/CD",
"urls": [
[
"http://none"
]
]
}
],
"region": "north-2.piedpiper.net"
}
20 changes: 13 additions & 7 deletions tests/unit/api/v1/test_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@

class ApiTestCase(test.TestCase):

def test_api_response_code(self):
def test_region_api_response_ok(self):
region = "north-2.piedpiper.net"
urlpath = "/api/v1/region/%s/infra" % region
code, resp = self.get(urlpath)
self.assertEqual(code, 200, urlpath)
path = "/api/v1/region/%s/infra" % region
code, resp = self.get(path)
self.assertEqual(code, 200, path)

urlpath = "/api/v1/region/unexpected_region/infra"
code, resp = self.get(urlpath)
self.assertEqual(404, code, urlpath)
def test_region_api_response_not_found(self):
path = "/api/v1/region/unexpected_region/infra"
code, resp = self.get(path)
self.assertEqual(404, code, path)

def test_regions_api_response_ok(self):
path = "/api/v1/regions/infra"
code, resp = self.get(path)
self.assertEqual(code, 200, path)

0 comments on commit a43a3f9

Please sign in to comment.