Port Report Extensions from v1 to v2
The reports available in v1 are now available in v2 Change-Id: I5691888353b9abee99e2ef029b4f1615065e064a Implements: blueprint port-reports-extension
This commit is contained in:
parent
331ee19582
commit
f8e1e6a3ee
46
designate/api/v2/controllers/extensions/counts.py
Normal file
46
designate/api/v2/controllers/extensions/counts.py
Normal file
@ -0,0 +1,46 @@
|
||||
# COPYRIGHT 2014 Rackspace
|
||||
#
|
||||
# Author: Betsy Luzader <betsy.luzader@rackspace.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 pecan
|
||||
|
||||
from designate.openstack.common import log as logging
|
||||
from designate.api.v2.controllers import rest
|
||||
from designate.api.v2.views.extensions import reports as reports_view
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CountsController(rest.RestController):
|
||||
|
||||
_view = reports_view.CountsView()
|
||||
|
||||
@pecan.expose(template='json:', content_type='application/json')
|
||||
def get_all(self):
|
||||
request = pecan.request
|
||||
context = pecan.request.environ['context']
|
||||
|
||||
counts = self.central_api.count_report(context)
|
||||
|
||||
return self._view.show(context, request, counts)
|
||||
|
||||
@pecan.expose(template='json:', content_type='application/json')
|
||||
def get_one(self, criterion):
|
||||
request = pecan.request
|
||||
context = pecan.request.environ['context']
|
||||
|
||||
counts = self.central_api.count_report(context, criterion=criterion)
|
||||
|
||||
return self._view.show(context, request, counts)
|
32
designate/api/v2/controllers/extensions/reports.py
Normal file
32
designate/api/v2/controllers/extensions/reports.py
Normal file
@ -0,0 +1,32 @@
|
||||
# COPYRIGHT 2014 Rackspace
|
||||
#
|
||||
# Author: Betsy Luzader <betsy.luzader@rackspace.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.
|
||||
|
||||
from designate.openstack.common import log as logging
|
||||
from designate.api.v2.controllers import rest
|
||||
from designate.api.v2.controllers.extensions import counts
|
||||
from designate.api.v2.controllers.extensions import tenants
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReportsController(rest.RestController):
|
||||
|
||||
@staticmethod
|
||||
def get_path():
|
||||
return '.reports'
|
||||
|
||||
counts = counts.CountsController()
|
||||
tenants = tenants.TenantsController()
|
47
designate/api/v2/controllers/extensions/tenants.py
Normal file
47
designate/api/v2/controllers/extensions/tenants.py
Normal file
@ -0,0 +1,47 @@
|
||||
# COPYRIGHT 2014 Rackspace
|
||||
#
|
||||
# Author: Betsy Luzader <betsy.luzader@rackspace.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 pecan
|
||||
|
||||
from designate.openstack.common import log as logging
|
||||
from designate.api.v2.controllers import rest
|
||||
from designate.api.v2.views.extensions import reports as reports_view
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TenantsController(rest.RestController):
|
||||
|
||||
_view = reports_view.TenantsView()
|
||||
|
||||
@pecan.expose(template='json:', content_type='application/json')
|
||||
def get_all(self):
|
||||
request = pecan.request
|
||||
context = pecan.request.environ['context']
|
||||
|
||||
tenants = self.central_api.find_tenants(context)
|
||||
|
||||
return self._view.list(context, request, tenants)
|
||||
|
||||
@pecan.expose(template='json:', content_type='application/json')
|
||||
def get_one(self, tenant_id):
|
||||
"""Get Tenant"""
|
||||
request = pecan.request
|
||||
context = request.environ['context']
|
||||
|
||||
tenant = self.central_api.get_tenant(context, tenant_id)
|
||||
|
||||
return self._view.show_detail(context, request, tenant)
|
66
designate/api/v2/views/extensions/reports.py
Normal file
66
designate/api/v2/views/extensions/reports.py
Normal file
@ -0,0 +1,66 @@
|
||||
# COPYRIGHT 2014 Rackspace
|
||||
#
|
||||
# Author: Betsy Luzader <betsy.luzader@rackspace.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.
|
||||
from designate.api.v2.views import base as base_view
|
||||
from designate.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CountsView(base_view.BaseView):
|
||||
"""View for the Counts Reports"""
|
||||
|
||||
_resource_name = 'reports'
|
||||
_collection_name = 'reports'
|
||||
|
||||
def show(self, context, request, counts):
|
||||
"""Basic view of the Counts Reports"""
|
||||
|
||||
return {
|
||||
"counts": counts
|
||||
}
|
||||
|
||||
|
||||
class TenantsView(base_view.BaseView):
|
||||
"""View for the Tenants Reports"""
|
||||
|
||||
_resource_name = 'tenants'
|
||||
_collection_name = 'tenants'
|
||||
|
||||
def _get_base_href(self, parents=None):
|
||||
|
||||
href = "%s/v2/reports/tenants" % (self.base_uri)
|
||||
|
||||
return href.rstrip('?')
|
||||
|
||||
def show_basic(self, context, request, tenants):
|
||||
"""Basic view of the Tenants Report"""
|
||||
|
||||
return {
|
||||
"domain_count": tenants['domain_count'],
|
||||
"id": tenants['id'],
|
||||
"links": self._get_resource_links(request, tenants)
|
||||
}
|
||||
|
||||
def show_detail(self, context, request, tenant):
|
||||
"""Detail view of the Tenants Report"""
|
||||
|
||||
return {
|
||||
"domains_count": tenant['domain_count'],
|
||||
"domains": tenant['domains'],
|
||||
"id": tenant['id'],
|
||||
"links": self._get_resource_links(request, tenant)
|
||||
}
|
@ -303,6 +303,11 @@ class CentralAPI(object):
|
||||
LOG.info(_LI("count_records: Calling central's count_records."))
|
||||
return self.client.call(context, 'count_records', criterion=criterion)
|
||||
|
||||
# Misc. Report combining counts for tenants, domains and records
|
||||
def count_report(self, context, criterion=None):
|
||||
LOG.info(_LI("count_report: Calling central's count_report."))
|
||||
return self.client.call(context, 'count_report', criterion=criterion)
|
||||
|
||||
# Sync Methods
|
||||
def sync_domains(self, context):
|
||||
LOG.info(_LI("sync_domains: Calling central's sync_domains."))
|
||||
|
@ -712,6 +712,26 @@ class Service(service.Service):
|
||||
|
||||
return self.storage.count_domains(context, criterion)
|
||||
|
||||
# Report combining all the count reports based on criterion
|
||||
def count_report(self, context, criterion=None):
|
||||
reports = []
|
||||
|
||||
if criterion is None:
|
||||
# Get all the reports
|
||||
reports.append({'zones': self.count_domains(context),
|
||||
'records': self.count_records(context),
|
||||
'tenants': self.count_tenants(context)})
|
||||
elif criterion == 'zones':
|
||||
reports.append({'zones': self.count_domains(context)})
|
||||
elif criterion == 'records':
|
||||
reports.append({'records': self.count_records(context)})
|
||||
elif criterion == 'tenants':
|
||||
reports.append({'tenants': self.count_tenants(context)})
|
||||
else:
|
||||
raise exceptions.ReportNotFound()
|
||||
|
||||
return reports
|
||||
|
||||
@transaction
|
||||
def touch_domain(self, context, domain_id):
|
||||
domain = self.storage.get_domain(context, domain_id)
|
||||
|
@ -245,6 +245,10 @@ class RecordNotFound(NotFound):
|
||||
error_type = 'record_not_found'
|
||||
|
||||
|
||||
class ReportNotFound(NotFound):
|
||||
error_type = 'report_not_found'
|
||||
|
||||
|
||||
class LastServerDeleteNotAllowed(BadRequest):
|
||||
error_type = 'last_server_delete_not_allowed'
|
||||
|
||||
|
@ -91,7 +91,7 @@ debug = False
|
||||
#enabled_extensions_v1 = diagnostics, quotas, reports, sync, touch
|
||||
|
||||
# Enabled API Version 2 extensions
|
||||
#enabled_extensions_v2 = quotas
|
||||
#enabled_extensions_v2 = reports, quotas
|
||||
|
||||
#-----------------------
|
||||
# Keystone Middleware
|
||||
|
@ -53,6 +53,7 @@ designate.api.v1.extensions =
|
||||
touch = designate.api.v1.extensions.touch:blueprint
|
||||
|
||||
designate.api.v2.extensions =
|
||||
reports = designate.api.v2.controllers.extensions.reports:ReportsController
|
||||
quotas = designate.api.v2.controllers.extensions.quotas:QuotasController
|
||||
|
||||
designate.storage =
|
||||
|
Loading…
x
Reference in New Issue
Block a user