Merge "Add Enhanced Logging to APIs"

This commit is contained in:
Jenkins 2016-04-12 07:37:27 +00:00 committed by Gerrit Code Review
commit 48d36b05b7
18 changed files with 297 additions and 96 deletions

View File

@ -19,6 +19,7 @@ from oslo_log import log as logging
from designate import schema from designate import schema
from designate.api.v1 import load_values from designate.api.v1 import load_values
from designate.central import rpcapi as central_rpcapi from designate.central import rpcapi as central_rpcapi
from designate.i18n import _LI
from designate import objects from designate import objects
@ -67,6 +68,8 @@ def create_domain():
domain = central_api.create_zone(context, objects.Zone(**values)) domain = central_api.create_zone(context, objects.Zone(**values))
LOG.info(_LI("Created %(zone)s"), {'zone': domain})
response = flask.jsonify(domain_schema.filter(domain)) response = flask.jsonify(domain_schema.filter(domain))
response.status_int = 201 response.status_int = 201
response.location = flask.url_for('.get_domain', domain_id=domain['id']) response.location = flask.url_for('.get_domain', domain_id=domain['id'])
@ -85,6 +88,8 @@ def get_domains():
domains = central_api.find_zones(context, criterion={"type": "PRIMARY", domains = central_api.find_zones(context, criterion={"type": "PRIMARY",
"action": "!DELETE"}) "action": "!DELETE"})
LOG.info(_LI("Retrieved %(zones)s"), {'zones': domains})
return flask.jsonify(domains_schema.filter({'domains': domains})) return flask.jsonify(domains_schema.filter({'domains': domains}))
@ -99,6 +104,8 @@ def get_domain(domain_id):
criterion = {"id": domain_id, "type": "PRIMARY", "action": "!DELETE"} criterion = {"id": domain_id, "type": "PRIMARY", "action": "!DELETE"}
domain = central_api.find_zone(context, criterion=criterion) domain = central_api.find_zone(context, criterion=criterion)
LOG.info(_LI("Retrieved %(zone)s"), {'zone': domain})
return flask.jsonify(domain_schema.filter(domain)) return flask.jsonify(domain_schema.filter(domain))
@ -124,6 +131,8 @@ def update_domain(domain_id):
domain.update(values) domain.update(values)
domain = central_api.update_zone(context, domain) domain = central_api.update_zone(context, domain)
LOG.info(_LI("Updated %(zone)s"), {'zone': domain})
return flask.jsonify(domain_schema.filter(domain)) return flask.jsonify(domain_schema.filter(domain))
@ -137,7 +146,9 @@ def delete_domain(domain_id):
criterion = {"id": domain_id, "type": "PRIMARY", "action": "!DELETE"} criterion = {"id": domain_id, "type": "PRIMARY", "action": "!DELETE"}
central_api.find_zone(context, criterion=criterion) central_api.find_zone(context, criterion=criterion)
central_api.delete_zone(context, domain_id) domain = central_api.delete_zone(context, domain_id)
LOG.info(_LI("Deleted %(zone)s"), {'zone': domain})
return flask.Response(status=200) return flask.Response(status=200)

View File

@ -21,6 +21,7 @@ from designate import exceptions
from designate import objects from designate import objects
from designate import schema from designate import schema
from designate import utils from designate import utils
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -128,6 +129,7 @@ def create_record(domain_id):
record = central_api.create_record(context, domain_id, record = central_api.create_record(context, domain_id,
recordset['id'], recordset['id'],
record) record)
LOG.info(_LI("Created %(record)s"), {'record': record})
record = _format_record_v1(record, recordset) record = _format_record_v1(record, recordset)
@ -150,6 +152,7 @@ def get_records(domain_id):
central_api.get_zone(context, domain_id) central_api.get_zone(context, domain_id)
recordsets = central_api.find_recordsets(context, {'zone_id': domain_id}) recordsets = central_api.find_recordsets(context, {'zone_id': domain_id})
LOG.info(_LI("Retrieved %(recordsets)s"), {'recordsets': recordsets})
records = [] records = []
@ -176,6 +179,8 @@ def get_record(domain_id, record_id):
recordset = central_api.get_recordset( recordset = central_api.get_recordset(
context, domain_id, record['recordset_id']) context, domain_id, record['recordset_id'])
LOG.info(_LI("Retrieved %(recordset)s"), {'recordset': recordset})
record = _format_record_v1(record, recordset) record = _format_record_v1(record, recordset)
return flask.jsonify(record_schema.filter(record)) return flask.jsonify(record_schema.filter(record))
@ -223,6 +228,7 @@ def update_record(domain_id, record_id):
recordset.update(_extract_recordset_values(values)) recordset.update(_extract_recordset_values(values))
if len(recordset.obj_what_changed()) > 0: if len(recordset.obj_what_changed()) > 0:
recordset = central_api.update_recordset(context, recordset) recordset = central_api.update_recordset(context, recordset)
LOG.info(_LI("Updated %(recordset)s"), {'recordset': recordset})
# Format and return the response # Format and return the response
record = _format_record_v1(record, recordset) record = _format_record_v1(record, recordset)
@ -238,7 +244,9 @@ def _delete_recordset_if_empty(context, domain_id, recordset_id):
}) })
# Make sure it's the right recordset # Make sure it's the right recordset
if len(recordset.records) == 0: if len(recordset.records) == 0:
central_api.delete_recordset(context, domain_id, recordset_id) recordset = central_api.delete_recordset(
context, domain_id, recordset_id)
LOG.info(_LI("Deleted %(recordset)s"), {'recordset': recordset})
@blueprint.route('/domains/<uuid:domain_id>/records/<uuid:record_id>', @blueprint.route('/domains/<uuid:domain_id>/records/<uuid:record_id>',
@ -257,8 +265,13 @@ def delete_record(domain_id, record_id):
criterion = {'zone_id': domain_id, 'id': record_id} criterion = {'zone_id': domain_id, 'id': record_id}
record = central_api.find_record(context, criterion) record = central_api.find_record(context, criterion)
central_api.delete_record( # Cannot delete a managed record via the API.
if record['managed'] is True:
raise exceptions.BadRequest('Managed records may not be deleted')
record = central_api.delete_record(
context, domain_id, record['recordset_id'], record_id) context, domain_id, record['recordset_id'], record_id)
LOG.info(_LI("Deleted %(record)s"), {'record': record})
_delete_recordset_if_empty(context, domain_id, record['recordset_id']) _delete_recordset_if_empty(context, domain_id, record['recordset_id'])
return flask.Response(status=200) return flask.Response(status=200)

View File

@ -20,6 +20,7 @@ from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import schema from designate import schema
from designate import objects from designate import objects
from designate.i18n import _LI
from designate.central import rpcapi as central_rpcapi from designate.central import rpcapi as central_rpcapi
@ -80,6 +81,7 @@ def create_server():
try: try:
# Update the pool # Update the pool
updated_pool = central_api.update_pool(context, pool) updated_pool = central_api.update_pool(context, pool)
LOG.info(_LI("Updated %(pool)s"), {'pool': pool})
except exceptions.DuplicatePoolAttribute: except exceptions.DuplicatePoolAttribute:
raise exceptions.DuplicateServer() raise exceptions.DuplicateServer()
@ -109,12 +111,15 @@ def get_servers():
# Get the default pool # Get the default pool
pool = central_api.get_pool(context, default_pool_id) pool = central_api.get_pool(context, default_pool_id)
LOG.info(_LI("Retrieved %(pool)s"), {'pool': pool})
servers = objects.ServerList() servers = objects.ServerList()
for ns in pool.ns_records: for ns in pool.ns_records:
servers.append(_pool_ns_record_to_server(ns)) servers.append(_pool_ns_record_to_server(ns))
LOG.info(_LI("Retrieved %(servers)s"), {'servers': servers})
return flask.jsonify(servers_schema.filter({'servers': servers})) return flask.jsonify(servers_schema.filter({'servers': servers}))
@ -126,6 +131,7 @@ def get_server(server_id):
# Get the default pool # Get the default pool
pool = central_api.get_pool(context, default_pool_id) pool = central_api.get_pool(context, default_pool_id)
LOG.info(_LI("Retrieved %(pool)s"), {'pool': pool})
# Create an empty PoolNsRecord object # Create an empty PoolNsRecord object
nameserver = objects.PoolNsRecord() nameserver = objects.PoolNsRecord()
@ -140,6 +146,8 @@ def get_server(server_id):
if nameserver.id != server_id: if nameserver.id != server_id:
raise exceptions.ServerNotFound raise exceptions.ServerNotFound
LOG.info(_LI("Retrieved %(server)s"), {'server': nameserver})
server = _pool_ns_record_to_server(nameserver) server = _pool_ns_record_to_server(nameserver)
return flask.jsonify(server_schema.filter(server)) return flask.jsonify(server_schema.filter(server))
@ -182,7 +190,8 @@ def update_server(server_id):
# Now that it's been validated, add it back to the pool and persist it # Now that it's been validated, add it back to the pool and persist it
pool.ns_records.append(nameserver) pool.ns_records.append(nameserver)
central_api.update_pool(context, pool) pool = central_api.update_pool(context, pool)
LOG.info(_LI("Updated %(pool)s"), {'pool': pool})
return flask.jsonify(server_schema.filter(server)) return flask.jsonify(server_schema.filter(server))
@ -211,6 +220,7 @@ def delete_server(server_id):
ns_records.pop(index) ns_records.pop(index)
# Update the pool without the deleted server # Update the pool without the deleted server
central_api.update_pool(context, pool) pool = central_api.update_pool(context, pool)
LOG.info(_LI("Updated %(pool)s"), {'pool': pool})
return flask.Response(status=200) return flask.Response(status=200)

View File

@ -20,6 +20,7 @@ from oslo_config import cfg
from designate import schema from designate import schema
from designate.central import rpcapi as central_rpcapi from designate.central import rpcapi as central_rpcapi
from designate.objects import TsigKey from designate.objects import TsigKey
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -57,6 +58,8 @@ def create_tsigkey():
tsigkey = central_api.create_tsigkey(context, tsigkey) tsigkey = central_api.create_tsigkey(context, tsigkey)
LOG.info(_LI("Created %(tsigkey)s"), {'tsigkey': tsigkey})
response = flask.jsonify(tsigkey_schema.filter(tsigkey)) response = flask.jsonify(tsigkey_schema.filter(tsigkey))
response.status_int = 201 response.status_int = 201
response.location = flask.url_for('.get_tsigkey', tsigkey_id=tsigkey['id']) response.location = flask.url_for('.get_tsigkey', tsigkey_id=tsigkey['id'])
@ -73,6 +76,8 @@ def get_tsigkeys():
criterion = {'scope': 'POOL', 'resource_id': default_pool_id} criterion = {'scope': 'POOL', 'resource_id': default_pool_id}
tsigkeys = central_api.find_tsigkeys(context, criterion) tsigkeys = central_api.find_tsigkeys(context, criterion)
LOG.info(_LI("Retrieved %(tsigkeys)s"), {'tsigkeys': tsigkeys})
return flask.jsonify(tsigkeys_schema.filter({'tsigkeys': tsigkeys})) return flask.jsonify(tsigkeys_schema.filter({'tsigkeys': tsigkeys}))
@ -90,6 +95,8 @@ def get_tsigkey(tsigkey_id):
tsigkey = central_api.find_tsigkeys(context, criterion) tsigkey = central_api.find_tsigkeys(context, criterion)
LOG.info(_LI("Retrieved %(tsigkey)s"), {'tsigkey': tsigkey})
return flask.jsonify(tsigkey_schema.filter(tsigkey)) return flask.jsonify(tsigkey_schema.filter(tsigkey))
@ -120,6 +127,8 @@ def update_tsigkey(tsigkey_id):
tsigkey.update(values) tsigkey.update(values)
tsigkey = central_api.update_tsigkey(context, tsigkey) tsigkey = central_api.update_tsigkey(context, tsigkey)
LOG.info(_LI("Updated %(tsigkey)s"), {'tsigkey': tsigkey})
return flask.jsonify(tsigkey_schema.filter(tsigkey)) return flask.jsonify(tsigkey_schema.filter(tsigkey))
@ -139,6 +148,8 @@ def delete_tsigkey(tsigkey_id):
central_api.find_tsigkeys(context, criterion) central_api.find_tsigkeys(context, criterion)
# Delete the TSIG Key # Delete the TSIG Key
central_api.delete_tsigkey(context, tsigkey_id) tsigkey = central_api.delete_tsigkey(context, tsigkey_id)
LOG.info(_LI("Deleted %(tsigkey)s"), {'tsigkey': tsigkey})
return flask.Response(status=200) return flask.Response(status=200)

View File

@ -21,6 +21,7 @@ from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import Blacklist from designate.objects import Blacklist
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -37,10 +38,11 @@ class BlacklistsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( blacklist = self.central_api.get_blacklist(context, blacklist_id)
'API_v2',
self.central_api.get_blacklist(context, blacklist_id), LOG.info(_LI("Retrieved %(blacklist)s"), {'blacklist': blacklist})
request=request)
return DesignateAdapter.render('API_v2', blacklist, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def get_all(self, **params): def get_all(self, **params):
@ -57,11 +59,12 @@ class BlacklistsController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return DesignateAdapter.render( blacklists = self.central_api.find_blacklists(
'API_v2', context, criterion, marker, limit, sort_key, sort_dir)
self.central_api.find_blacklists(
context, criterion, marker, limit, sort_key, sort_dir), LOG.info(_LI("Retrieved %(blacklists)s"), {'blacklists': blacklists})
request=request)
return DesignateAdapter.render('API_v2', blacklists, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -79,6 +82,8 @@ class BlacklistsController(rest.RestController):
blacklist = self.central_api.create_blacklist( blacklist = self.central_api.create_blacklist(
context, blacklist) context, blacklist)
LOG.info(_LI("Created %(blacklist)s"), {'blacklist': blacklist})
response.status_int = 201 response.status_int = 201
blacklist = DesignateAdapter.render( blacklist = DesignateAdapter.render(
@ -111,6 +116,8 @@ class BlacklistsController(rest.RestController):
blacklist = self.central_api.update_blacklist(context, blacklist) blacklist = self.central_api.update_blacklist(context, blacklist)
LOG.info(_LI("Updated %(blacklist)s"), {'blacklist': blacklist})
response.status_int = 200 response.status_int = 200
return DesignateAdapter.render('API_v2', blacklist, request=request) return DesignateAdapter.render('API_v2', blacklist, request=request)
@ -123,7 +130,9 @@ class BlacklistsController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_blacklist(context, blacklist_id) blacklist = self.central_api.delete_blacklist(context, blacklist_id)
LOG.info(_LI("Deleted %(blacklist)s"), {'blacklist': blacklist})
response.status_int = 204 response.status_int = 204

View File

@ -16,12 +16,15 @@
import re import re
import pecan import pecan
from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import objects from designate import objects
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.i18n import _LI
LOG = logging.getLogger(__name__)
FIP_REGEX = '^(?P<region>[A-Za-z0-9\\.\\-_]{1,100}):' \ FIP_REGEX = '^(?P<region>[A-Za-z0-9\\.\\-_]{1,100}):' \
'(?P<id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-' \ '(?P<id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-' \
@ -47,10 +50,11 @@ class FloatingIPController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( fips = self.central_api.list_floatingips(context)
'API_v2',
self.central_api.list_floatingips(context), LOG.info(_LI("Retrieved %(fips)s"), {'fips': fips})
request=request)
return DesignateAdapter.render('API_v2', fips, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def patch_one(self, fip_key): def patch_one(self, fip_key):
@ -76,6 +80,8 @@ class FloatingIPController(rest.RestController):
fip.validate() fip.validate()
LOG.info(_LI("Updated %(fip)s"), {'fip': fip})
fip = self.central_api.update_floatingip(context, region, id_, fip) fip = self.central_api.update_floatingip(context, region, id_, fip)
response.status_int = 202 response.status_int = 202
@ -93,7 +99,8 @@ class FloatingIPController(rest.RestController):
region, id_ = fip_key_to_data(fip_key) region, id_ = fip_key_to_data(fip_key)
return DesignateAdapter.render( fip = self.central_api.get_floatingip(context, region, id_)
'API_v2',
self.central_api.get_floatingip(context, region, id_), LOG.info(_LI("Retrieved %(fip)s"), {'fip': fip})
request=request)
return DesignateAdapter.render('API_v2', fip, request=request)

View File

@ -20,6 +20,7 @@ from designate.i18n import _LW
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import Pool from designate.objects import Pool
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -35,10 +36,11 @@ class PoolsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( pool = self.central_api.get_pool(context, pool_id)
'API_v2',
self.central_api.get_pool(context, pool_id), LOG.info(_LI("Retrieved %(pool)s"), {'pool': pool})
request=request)
return DesignateAdapter.render('API_v2', pool, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def get_all(self, **params): def get_all(self, **params):
@ -55,11 +57,12 @@ class PoolsController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return DesignateAdapter.render( pools = self.central_api.find_pools(
'API_v2', context, criterion, marker, limit, sort_key, sort_dir)
self.central_api.find_pools(
context, criterion, marker, limit, sort_key, sort_dir), LOG.info(_LI("Retrieved %(pools)s"), {'pools': pools})
request=request)
return DesignateAdapter.render('API_v2', pools, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -80,10 +83,14 @@ class PoolsController(rest.RestController):
# Create the pool # Create the pool
pool = self.central_api.create_pool(context, pool) pool = self.central_api.create_pool(context, pool)
LOG.info(_LI("Created %(pool)s"), {'pool': pool})
pool = DesignateAdapter.render('API_v2', pool, request=request) pool = DesignateAdapter.render('API_v2', pool, request=request)
response.status_int = 201 response.status_int = 201
response.headers['Location'] = pool['links']['self'] response.headers['Location'] = pool['links']['self']
# Prepare and return the response body # Prepare and return the response body
return pool return pool
@ -114,6 +121,8 @@ class PoolsController(rest.RestController):
pool = self.central_api.update_pool(context, pool) pool = self.central_api.update_pool(context, pool)
LOG.info(_LI("Updated %(pool)s"), {'pool': pool})
response.status_int = 202 response.status_int = 202
return DesignateAdapter.render('API_v2', pool, request=request) return DesignateAdapter.render('API_v2', pool, request=request)
@ -131,7 +140,9 @@ class PoolsController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_pool(context, pool_id) pool = self.central_api.delete_pool(context, pool_id)
LOG.info(_LI("Deleted %(pool)s"), {'pool': pool})
response.status_int = 204 response.status_int = 204

View File

@ -22,6 +22,7 @@ from designate.api.v2.controllers import rest
from designate.objects import RecordSet from designate.objects import RecordSet
from designate.objects import RecordSetList from designate.objects import RecordSetList
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -37,11 +38,12 @@ class RecordSetsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( recordset = self.central_api.get_recordset(context, zone_id,
'API_v2', recordset_id)
self.central_api.get_recordset(
context, zone_id, recordset_id), LOG.info(_LI("Retrieved %(recordset)s"), {'recordset': recordset})
request=request)
return DesignateAdapter.render('API_v2', recordset, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@utils.validate_uuid('zone_id') @utils.validate_uuid('zone_id')
@ -100,6 +102,8 @@ class RecordSetsController(rest.RestController):
recordsets = new_rsets recordsets = new_rsets
LOG.info(_LI("Retrieved %(recordsets)s"), {'recordsets': recordsets})
return DesignateAdapter.render('API_v2', recordsets, request=request) return DesignateAdapter.render('API_v2', recordsets, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -131,6 +135,8 @@ class RecordSetsController(rest.RestController):
else: else:
response.status_int = 201 response.status_int = 201
LOG.info(_LI("Created %(recordset)s"), {'recordset': recordset})
recordset = DesignateAdapter.render( recordset = DesignateAdapter.render(
'API_v2', recordset, request=request) 'API_v2', recordset, request=request)
@ -177,6 +183,8 @@ class RecordSetsController(rest.RestController):
# Persist the resource # Persist the resource
recordset = self.central_api.update_recordset(context, recordset) recordset = self.central_api.update_recordset(context, recordset)
LOG.info(_LI("Updated %(recordset)s"), {'recordset': recordset})
if recordset['status'] == 'PENDING': if recordset['status'] == 'PENDING':
response.status_int = 202 response.status_int = 202
else: else:
@ -201,6 +209,9 @@ class RecordSetsController(rest.RestController):
recordset = self.central_api.delete_recordset( recordset = self.central_api.delete_recordset(
context, zone_id, recordset_id) context, zone_id, recordset_id)
LOG.info(_LI("Deleted %(recordset)s"), {'recordset': recordset})
response.status_int = 202 response.status_int = 202
return DesignateAdapter.render('API_v2', recordset, request=request) return DesignateAdapter.render('API_v2', recordset, request=request)

View File

@ -19,6 +19,7 @@ from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import Tld from designate.objects import Tld
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -35,10 +36,11 @@ class TldsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( tld = self.central_api.get_tld(context, tld_id)
'API_v2',
self.central_api.get_tld(context, tld_id), LOG.info(_LI("Retrieved %(tld)s"), {'tld': tld})
request=request)
return DesignateAdapter.render('API_v2', tld, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def get_all(self, **params): def get_all(self, **params):
@ -55,11 +57,12 @@ class TldsController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return DesignateAdapter.render( tlds = self.central_api.find_tlds(
'API_v2', context, criterion, marker, limit, sort_key, sort_dir)
self.central_api.find_tlds(
context, criterion, marker, limit, sort_key, sort_dir), LOG.info(_LI("Retrieved %(tlds)s"), {'tlds': tlds})
request=request)
return DesignateAdapter.render('API_v2', tlds, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -75,11 +78,15 @@ class TldsController(rest.RestController):
# Create the tld # Create the tld
tld = self.central_api.create_tld(context, tld) tld = self.central_api.create_tld(context, tld)
LOG.info(_LI("Created %(tld)s"), {'tld': tld})
response.status_int = 201 response.status_int = 201
tld = DesignateAdapter.render('API_v2', tld, request=request) tld = DesignateAdapter.render('API_v2', tld, request=request)
response.headers['Location'] = tld['links']['self'] response.headers['Location'] = tld['links']['self']
# Prepare and return the response body # Prepare and return the response body
return tld return tld
@ -104,6 +111,8 @@ class TldsController(rest.RestController):
tld = self.central_api.update_tld(context, tld) tld = self.central_api.update_tld(context, tld)
LOG.info(_LI("Updated %(tld)s"), {'tld': tld})
response.status_int = 200 response.status_int = 200
return DesignateAdapter.render('API_v2', tld, request=request) return DesignateAdapter.render('API_v2', tld, request=request)
@ -116,7 +125,9 @@ class TldsController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_tld(context, tld_id) tld = self.central_api.delete_tld(context, tld_id)
LOG.info(_LI("Deleted %(tld)s"), {'tld': tld})
response.status_int = 204 response.status_int = 204

View File

@ -21,6 +21,8 @@ from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import TsigKey from designate.objects import TsigKey
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -36,10 +38,11 @@ class TsigKeysController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return DesignateAdapter.render( tsigkey = self.central_api.get_tsigkey(context, tsigkey_id)
'API_v2',
self.central_api.get_tsigkey(context, tsigkey_id), LOG.info(_LI("Retrieved %(tsigkey)s"), {'tsigkey': tsigkey})
request=request)
return DesignateAdapter.render('API_v2', tsigkey, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def get_all(self, **params): def get_all(self, **params):
@ -53,14 +56,15 @@ class TsigKeysController(rest.RestController):
# Extract any filter params # Extract any filter params
accepted_filters = ('name', 'algorithm', 'scope') accepted_filters = ('name', 'algorithm', 'scope')
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
tsigkeys = self.central_api.find_tsigkeys(
context, criterion, marker, limit, sort_key, sort_dir)
return DesignateAdapter.render( LOG.info(_LI("Retrieved %(tsigkeys)s"), {'tsigkeys': tsigkeys})
'API_v2',
self.central_api.find_tsigkeys( return DesignateAdapter.render('API_v2', tsigkeys, request=request)
context, criterion, marker, limit, sort_key, sort_dir),
request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -78,6 +82,8 @@ class TsigKeysController(rest.RestController):
tsigkey = self.central_api.create_tsigkey( tsigkey = self.central_api.create_tsigkey(
context, tsigkey) context, tsigkey)
LOG.info(_LI("Created %(tsigkey)s"), {'tsigkey': tsigkey})
tsigkey = DesignateAdapter.render('API_v2', tsigkey, request=request) tsigkey = DesignateAdapter.render('API_v2', tsigkey, request=request)
response.headers['Location'] = tsigkey['links']['self'] response.headers['Location'] = tsigkey['links']['self']
@ -109,6 +115,8 @@ class TsigKeysController(rest.RestController):
# Update and persist the resource # Update and persist the resource
tsigkey = self.central_api.update_tsigkey(context, tsigkey) tsigkey = self.central_api.update_tsigkey(context, tsigkey)
LOG.info(_LI("Updated %(tsigkey)s"), {'tsigkey': tsigkey})
response.status_int = 200 response.status_int = 200
return DesignateAdapter.render('API_v2', tsigkey, request=request) return DesignateAdapter.render('API_v2', tsigkey, request=request)
@ -121,7 +129,9 @@ class TsigKeysController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_tsigkey(context, tsigkey_id) tsigkey = self.central_api.delete_tsigkey(context, tsigkey_id)
LOG.info(_LI("Deleted %(tsigkey)s"), {'tsigkey': tsigkey})
response.status_int = 204 response.status_int = 204

View File

@ -15,6 +15,7 @@
# under the License. # under the License.
import pecan import pecan
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import utils from designate import utils
@ -24,11 +25,15 @@ from designate.api.v2.controllers.zones import tasks
from designate.api.v2.controllers.zones import nameservers from designate.api.v2.controllers.zones import nameservers
from designate import objects from designate import objects
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class ZonesController(rest.RestController): class ZonesController(rest.RestController):
SORT_KEYS = ['created_at', 'id', 'updated_at', 'name', 'tenant_id', SORT_KEYS = ['created_at', 'id', 'updated_at', 'name', 'tenant_id',
@ -47,9 +52,13 @@ class ZonesController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
zone = self.central_api.get_zone(context, zone_id)
LOG.info(_LI("Retrieved %(zone)s"), {'zone': zone})
return DesignateAdapter.render( return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.get_zone(context, zone_id), zone,
request=request) request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -68,11 +77,12 @@ class ZonesController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return DesignateAdapter.render( zones = self.central_api.find_zones(
'API_v2', context, criterion, marker, limit, sort_key, sort_dir)
self.central_api.find_zones(
context, criterion, marker, limit, sort_key, sort_dir), LOG.info(_LI("Retrieved %(zones)s"), {'zones': zones})
request=request)
return DesignateAdapter.render('API_v2', zones, request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -97,6 +107,8 @@ class ZonesController(rest.RestController):
# Create the zone # Create the zone
zone = self.central_api.create_zone(context, zone) zone = self.central_api.create_zone(context, zone)
LOG.info(_LI("Created %(zone)s"), {'zone': zone})
# Prepare the response headers # Prepare the response headers
# If the zone has been created asynchronously # If the zone has been created asynchronously
@ -166,6 +178,8 @@ class ZonesController(rest.RestController):
zone = self.central_api.update_zone( zone = self.central_api.update_zone(
context, zone, increment_serial=increment_serial) context, zone, increment_serial=increment_serial)
LOG.info(_LI("Updated %(zone)s"), {'zone': zone})
if zone.status == 'PENDING': if zone.status == 'PENDING':
response.status_int = 202 response.status_int = 202
else: else:
@ -184,4 +198,6 @@ class ZonesController(rest.RestController):
zone = self.central_api.delete_zone(context, zone_id) zone = self.central_api.delete_zone(context, zone_id)
response.status_int = 202 response.status_int = 202
LOG.info(_LI("Deleted %(zone)s"), {'zone': zone})
return DesignateAdapter.render('API_v2', zone, request=request) return DesignateAdapter.render('API_v2', zone, request=request)

View File

@ -15,13 +15,17 @@
# under the License. # under the License.
import pecan import pecan
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class NameServersController(rest.RestController): class NameServersController(rest.RestController):
@ -34,8 +38,12 @@ class NameServersController(rest.RestController):
# This is a work around to overcome the fact that pool ns_records list # This is a work around to overcome the fact that pool ns_records list
# object have 2 different representations in the v2 API # object have 2 different representations in the v2 API
ns_records = self.central_api.get_zone_ns_records(context, zone_id)
LOG.info(_LI("Created %(ns_records)s"), {'ns_records': ns_records})
return { return {
"nameservers": DesignateAdapter.render( "nameservers": DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.get_zone_ns_records(context, zone_id), ns_records,
request=request)} request=request)}

View File

@ -13,9 +13,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import pecan import pecan
from oslo_log import log as logging
from designate import utils from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.i18n import _LI
LOG = logging.getLogger(__name__)
class AbandonController(rest.RestController): class AbandonController(rest.RestController):
@ -33,6 +38,7 @@ class AbandonController(rest.RestController):
zone = self.central_api.delete_zone(context, zone_id) zone = self.central_api.delete_zone(context, zone_id)
if zone.deleted_at: if zone.deleted_at:
response.status_int = 204 response.status_int = 204
LOG.info(_LI("Abandoned %(zone)s"), {'zone': zone})
else: else:
response.status_int = 500 response.status_int = 500

View File

@ -20,8 +20,8 @@ from designate import exceptions
from designate import policy from designate import policy
from designate import utils from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects.adapters.api_v2.zone_export \ from designate.objects.adapters import DesignateAdapter
import ZoneExportAPIv2Adapter from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -61,7 +61,9 @@ class ZoneExportCreateController(rest.RestController):
context, zone_id) context, zone_id)
response.status_int = 202 response.status_int = 202
zone_export = ZoneExportAPIv2Adapter.render( LOG.info(_LI("Created %(zone_export)s"), {'zone_export': zone_export})
zone_export = DesignateAdapter.render(
'API_v2', zone_export, request=request) 'API_v2', zone_export, request=request)
response.headers['Location'] = zone_export['links']['self'] response.headers['Location'] = zone_export['links']['self']
@ -82,10 +84,13 @@ class ZoneExportsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return ZoneExportAPIv2Adapter.render( zone_export = self.central_api.get_zone_export(context, export_id)
LOG.info(_LI("Retrived %(zone_export)s"), {'zone_export': zone_export})
return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.get_zone_export( zone_export,
context, export_id),
request=request) request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -102,10 +107,15 @@ class ZoneExportsController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return ZoneExportAPIv2Adapter.render( zone_exports = self.central_api.find_zone_exports(
context, criterion, marker, limit, sort_key, sort_dir)
LOG.info(_LI("Retrived %(zone_exports)s"),
{'zone_exports': zone_exports})
return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.find_zone_exports( zone_exports,
context, criterion, marker, limit, sort_key, sort_dir),
request=request) request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -116,7 +126,11 @@ class ZoneExportsController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_zone_export(context, zone_export_id) zone_export = self.central_api.delete_zone_export(
context, zone_export_id)
LOG.info(_LI("Deleted %(zone_export)s"), {'zone_export': zone_export})
response.status_int = 204 response.status_int = 204
return '' return ''

View File

@ -20,9 +20,8 @@ from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import utils from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects.adapters.api_v2.zone_import \ from designate.objects.adapters import DesignateAdapter
import ZoneImportAPIv2Adapter from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -39,10 +38,14 @@ class ZoneImportController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
return ZoneImportAPIv2Adapter.render( zone_import = self.central_api.get_zone_import(
context, import_id)
LOG.info(_LI("Retrived %(zone_import)s"), {'zone_import': zone_import})
return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.get_zone_import( zone_import,
context, import_id),
request=request) request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -59,10 +62,15 @@ class ZoneImportController(rest.RestController):
criterion = self._apply_filter_params( criterion = self._apply_filter_params(
params, accepted_filters, {}) params, accepted_filters, {})
return ZoneImportAPIv2Adapter.render( zone_imports = self.central_api.find_zone_imports(
context, criterion, marker, limit, sort_key, sort_dir)
LOG.info(_LI("Retrived %(zone_imports)s"),
{'zone_imports': zone_imports})
return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.find_zone_imports( zone_imports,
context, criterion, marker, limit, sort_key, sort_dir),
request=request) request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
@ -85,7 +93,9 @@ class ZoneImportController(rest.RestController):
context, body) context, body)
response.status_int = 202 response.status_int = 202
zone_import = ZoneImportAPIv2Adapter.render( LOG.info(_LI("Created %(zone_import)s"), {'zone_import': zone_import})
zone_import = DesignateAdapter.render(
'API_v2', zone_import, request=request) 'API_v2', zone_import, request=request)
response.headers['Location'] = zone_import['links']['self'] response.headers['Location'] = zone_import['links']['self']
@ -100,7 +110,11 @@ class ZoneImportController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_zone_import(context, zone_import_id) zone_import = self.central_api.delete_zone_import(
context, zone_import_id)
LOG.info(_LI("Deleted %(zone_import)s"), {'zone_import': zone_import})
response.status_int = 204 response.status_int = 204
return '' return ''

View File

@ -20,6 +20,7 @@ from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import ZoneTransferAccept from designate.objects import ZoneTransferAccept
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -37,11 +38,14 @@ class TransferAcceptsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
transfer_accepts = self.central_api.get_zone_transfer_accept(
context, transfer_accept_id)
LOG.info(_LI("Retrieved %(transfer_accepts)s"),
{'transfer_accepts': transfer_accepts})
return DesignateAdapter.render( return DesignateAdapter.render(
'API_v2', 'API_v2', transfer_accepts, request=request)
self.central_api.get_zone_transfer_accept(
context, transfer_accept_id),
request=request)
@pecan.expose(template='json:', content_type='application/json') @pecan.expose(template='json:', content_type='application/json')
def post_all(self): def post_all(self):
@ -61,9 +65,13 @@ class TransferAcceptsController(rest.RestController):
context, zone_transfer_accept) context, zone_transfer_accept)
response.status_int = 201 response.status_int = 201
LOG.info(_LI("Created %(zone_transfer_accept)s"),
{'zone_transfer_accept': zone_transfer_accept})
zone_transfer_accept = DesignateAdapter.render( zone_transfer_accept = DesignateAdapter.render(
'API_v2', zone_transfer_accept, request=request) 'API_v2', zone_transfer_accept, request=request)
response.headers['Location'] = zone_transfer_accept['links']['self'] response.headers['Location'] = zone_transfer_accept['links']['self']
# Prepare and return the response body # Prepare and return the response body
return zone_transfer_accept return zone_transfer_accept

View File

@ -21,6 +21,9 @@ from designate import exceptions
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.objects import ZoneTransferRequest from designate.objects import ZoneTransferRequest
from designate.objects.adapters import DesignateAdapter from designate.objects.adapters import DesignateAdapter
from designate.i18n import _LI
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -36,10 +39,15 @@ class TransferRequestsController(rest.RestController):
request = pecan.request request = pecan.request
context = request.environ['context'] context = request.environ['context']
transfer_request = self.central_api.get_zone_transfer_request(
context, transfer_request_id)
LOG.info(_LI("Retrieved %(transfer_request)s"),
{'transfer_request': transfer_request})
return DesignateAdapter.render( return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.get_zone_transfer_request( transfer_request,
context, transfer_request_id),
request=request, request=request,
context=context) context=context)
@ -56,10 +64,15 @@ class TransferRequestsController(rest.RestController):
# Extract any filter params. # Extract any filter params.
criterion = self._apply_filter_params(params, ('status',), {}) criterion = self._apply_filter_params(params, ('status',), {})
zone_transfer_requests = self.central_api.find_zone_transfer_requests(
context, criterion, marker, limit, sort_key, sort_dir)
LOG.info(_LI("Retrieved %(zone_transfer_requests)s"),
{'zone_transfer_requests': zone_transfer_requests})
return DesignateAdapter.render( return DesignateAdapter.render(
'API_v2', 'API_v2',
self.central_api.find_zone_transfer_requests( zone_transfer_requests,
context, criterion, marker, limit, sort_key, sort_dir),
request=request, request=request,
context=context) context=context)
@ -87,6 +100,9 @@ class TransferRequestsController(rest.RestController):
context, zone_transfer_request) context, zone_transfer_request)
response.status_int = 201 response.status_int = 201
LOG.info(_LI("Created %(zone_transfer_request)s"),
{'zone_transfer_request': zone_transfer_request})
zone_transfer_request = DesignateAdapter.render( zone_transfer_request = DesignateAdapter.render(
'API_v2', zone_transfer_request, request=request, context=context) 'API_v2', zone_transfer_request, request=request, context=context)
@ -119,6 +135,9 @@ class TransferRequestsController(rest.RestController):
zone_transfer_request = self.central_api.update_zone_transfer_request( zone_transfer_request = self.central_api.update_zone_transfer_request(
context, zone_transfer_request) context, zone_transfer_request)
LOG.info(_LI("Updated %(zt_request)s"),
{'zt_request': zone_transfer_request})
response.status_int = 200 response.status_int = 200
return DesignateAdapter.render( return DesignateAdapter.render(
@ -132,10 +151,13 @@ class TransferRequestsController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
self.central_api.delete_zone_transfer_request( zone_transfer_request = self.central_api.delete_zone_transfer_request(
context, zone_transfer_request_id) context, zone_transfer_request_id)
response.status_int = 204 response.status_int = 204
LOG.info(_LI("Deleted %(zone_transfer_request)s"),
{'zone_transfer_request': zone_transfer_request})
# NOTE: This is a hack and a half.. But Pecan needs it. # NOTE: This is a hack and a half.. But Pecan needs it.
return '' return ''

View File

@ -14,9 +14,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import pecan import pecan
from oslo_log import log as logging
from designate import utils from designate import utils
from designate.api.v2.controllers import rest from designate.api.v2.controllers import rest
from designate.i18n import _LI
LOG = logging.getLogger(__name__)
class XfrController(rest.RestController): class XfrController(rest.RestController):
@ -29,6 +34,10 @@ class XfrController(rest.RestController):
response = pecan.response response = pecan.response
context = request.environ['context'] context = request.environ['context']
zone = self.central_api.get_zone(context, zone_id)
LOG.info(_LI("Triggered XFR for %(zone)s"), {'zone': zone})
self.central_api.xfr_zone(context, zone_id) self.central_api.xfr_zone(context, zone_id)
response.status_int = 202 response.status_int = 202