Move diagnostics API resource under /v1/ and split out the sync methods.

Change-Id: Id984989f61ceec1d750b14084377f7d103547b14
This commit is contained in:
Kiall Mac Innes 2013-02-22 00:32:48 +00:00
parent 5d9bcfb9a3
commit 4db7a68ad6
5 changed files with 114 additions and 97 deletions

View File

@ -1,20 +1,11 @@
[composite:osapi_dns]
use = egg:Paste#urlmap
/: osapi_dns_app_versions
/diagnostics: osapi_dns_diagnostics
/v1: osapi_dns_v1
[app:osapi_dns_app_versions]
paste.app_factory = moniker.api.versions:factory
[composite:osapi_dns_diagnostics]
use = call:moniker.api.auth:pipeline_factory
noauth = noauthcontext osapi_dns_app_diagnostics
keystone = authtoken keystonecontext osapi_dns_app_diagnostics
[app:osapi_dns_app_diagnostics]
paste.app_factory = moniker.api.diagnostics:factory
[composite:osapi_dns_v1]
use = call:moniker.api.auth:pipeline_factory
noauth = noauthcontext osapi_dns_app_v1

View File

@ -1,88 +0,0 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. All Rights Reserved.
#
# Author: Kiall Mac Innes <kiall@hp.com>
#
# 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 moniker.openstack.common import rpc
from moniker.openstack.common.rpc import common as rpc_common
from moniker import exceptions
from moniker.central import api as central_api
def factory(global_config, **local_conf):
app = flask.Flask('moniker.api.diagnostics')
@app.route('/ping/<topic>/<host>', methods=['GET'])
def ping_host(topic, host):
context = flask.request.environ.get('context')
queue = rpc.queue_get_for(context, topic, host)
msg = {
'method': 'ping',
'args': {},
}
try:
pong = rpc.call(context, queue, msg, timeout=10)
except rpc_common.Timeout:
return flask.Response(status=504)
except:
return flask.Response(status=500)
else:
return flask.jsonify(pong)
@app.route('/sync/all', methods=['POST'])
def sync_all():
context = flask.request.environ.get('context')
try:
central_api.sync_all(context)
except exceptions.Forbidden:
return flask.Response(status=401)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)
@app.route('/sync/domain/<domain_id>', methods=['POST'])
def sync_domain(domain_id):
context = flask.request.environ.get('context')
try:
central_api.sync_domain(context, domain_id)
except exceptions.Forbidden:
return flask.Response(status=401)
except exceptions.DomainNotFound:
return flask.Response(status=404)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)
@app.route('/sync/record/<domain_id>/<record_id>', methods=['POST'])
def sync_record(domain_id, record_id):
context = flask.request.environ.get('context')
try:
central_api.sync_record(context, domain_id, record_id)
except exceptions.Forbidden:
return flask.Response(status=401)
except exceptions.RecordNotFound:
return flask.Response(status=404)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)
return app

View File

@ -0,0 +1,42 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. All Rights Reserved.
#
# Author: Kiall Mac Innes <kiall@hp.com>
#
# 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 moniker.openstack.common import log as logging
from moniker.openstack.common import rpc
from moniker.openstack.common.rpc import common as rpc_common
LOG = logging.getLogger(__name__)
blueprint = flask.Blueprint('diagnostics', __name__)
@blueprint.route('/diagnostics/ping/<topic>/<host>', methods=['GET'])
def ping_host(topic, host):
context = flask.request.environ.get('context')
queue = rpc.queue_get_for(context, topic, host)
msg = {
'method': 'ping',
'args': {},
}
try:
pong = rpc.call(context, queue, msg, timeout=10)
except rpc_common.Timeout:
return flask.Response(status=504)
except:
return flask.Response(status=500)
else:
return flask.jsonify(pong)

70
moniker/api/v1/sync.py Normal file
View File

@ -0,0 +1,70 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. All Rights Reserved.
#
# Author: Kiall Mac Innes <kiall@hp.com>
#
# 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 moniker.openstack.common import log as logging
from moniker.openstack.common.rpc import common as rpc_common
from moniker import exceptions
from moniker.central import api as central_api
LOG = logging.getLogger(__name__)
blueprint = flask.Blueprint('sync', __name__)
@blueprint.route('/sync', methods=['POST'])
def sync_all():
context = flask.request.environ.get('context')
try:
central_api.sync_all(context)
except exceptions.Forbidden:
return flask.Response(status=401)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)
@blueprint.route('/domains/<domain_id>/sync', methods=['POST'])
def sync_domain(domain_id):
context = flask.request.environ.get('context')
try:
central_api.sync_domain(context, domain_id)
except exceptions.Forbidden:
return flask.Response(status=401)
except exceptions.DomainNotFound:
return flask.Response(status=404)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)
@blueprint.route('/domains/<domain_id>/records/<record_id>/sync',
methods=['POST'])
def sync_record(domain_id, record_id):
context = flask.request.environ.get('context')
try:
central_api.sync_record(context, domain_id, record_id)
except exceptions.Forbidden:
return flask.Response(status=401)
except exceptions.RecordNotFound:
return flask.Response(status=404)
except rpc_common.Timeout:
return flask.Response(status=504)
else:
return flask.Response(status=200)

View File

@ -61,6 +61,8 @@ setup(
records = moniker.api.v1.records:blueprint
servers = moniker.api.v1.servers:blueprint
tsigkeys = moniker.api.v1.tsigkeys:blueprint
diagnostics = moniker.api.v1.diagnostics:blueprint
sync = moniker.api.v1.sync:blueprint
[moniker.storage]
sqlalchemy = moniker.storage.impl_sqlalchemy:SQLAlchemyStorage