Added reporting functionality to Moniker client

Change-Id: I12687d678a1b7c22bfbfd0480c53912152d8d7eb
This commit is contained in:
Patrick Galbraith 2013-05-03 18:40:18 -03:00
parent 9bfedc76f9
commit e853efb11d
3 changed files with 146 additions and 0 deletions

@ -0,0 +1,71 @@
# Copyright 2013 Hewlett-Packard Development Company, L.P. All Rights Reserved.
#
# Author: Patrick Galbraith <patg@patg.net>
#
# 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 monikerclient.cli import base
class DomainCountCommand(base.GetCommand):
""" Get counts for total domains """
def execute(self, parsed_args):
return self.client.reports.count_domains()
class RecordCountCommand(base.GetCommand):
""" Get counts for total records """
def execute(self, parsed_args):
return self.client.reports.count_records()
class TenantCountCommand(base.GetCommand):
""" Get counts for total tenants """
def execute(self, parsed_args):
return self.client.reports.count_tenants()
class CountsCommand(base.GetCommand):
""" Get count totals for all tenants, domains and records """
def execute(self, parsed_args):
return self.client.reports.count_all()
class TenantsCommand(base.ListCommand):
""" Get list of tenants and domain count for each """
columns = ['domain_count', 'id']
def execute(self, parsed_args):
return self.client.reports.tenants_all()
class TenantCommand(base.ListCommand):
""" Get a list of domains for given tenant """
columns = ['domain']
def get_parser(self, prog_name):
parser = super(TenantCommand, self).get_parser(prog_name)
parser.add_argument('--report-tenant-id',
help="tenant_id being reported on",
required=True)
return parser
def execute(self, parsed_args):
return self.client.reports.tenant_domains(parsed_args.report_tenant_id)

@ -0,0 +1,67 @@
# Copyright 2013 Hewlett-Packard Development Company, L.P. All Rights Reserved.
#
# Author: Patrick Galbraith <patg@patg.net>
#
# 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 monikerclient.v1.base import Controller
class ReportsController(Controller):
def count_all(self):
"""
Domain, Records and tenant total count
"""
response = self.client.get('/reports/counts')
return response.json
def count_domains(self):
"""
Domain total count
"""
response = self.client.get('/reports/counts/domains')
return response.json
def count_tenants(self):
"""
Tenant total count
"""
response = self.client.get('/reports/counts/tenants')
return response.json
def count_records(self):
"""
Record total count
"""
response = self.client.get('/reports/counts/records')
return response.json
def tenants_all(self):
"""
Per tenant count
"""
response = self.client.get('/reports/tenants')
return response.json['tenants']
def tenant_domains(self, other_tenant_id):
"""
Tenant's domain count
"""
response = self.client.get('/reports/tenants/%s' %
other_tenant_id)
return [{'domain': d} for d in response.json['domains']]

@ -48,6 +48,7 @@ setup(
cmdclass=common_setup.get_cmdclass(),
entry_points=textwrap.dedent("""
[monikerclient.v1.controllers]
reports = monikerclient.v1.reports:ReportsController
diagnostics = monikerclient.v1.diagnostics:DiagnosticsController
domains = monikerclient.v1.domains:DomainsController
records = monikerclient.v1.records:RecordsController
@ -80,6 +81,13 @@ setup(
:SyncDomainCommand
diagnostics-sync-record = monikerclient.cli.diagnostics\
:SyncRecordCommand
report-count-all = monikerclient.cli.reports:CountsCommand
report-count-domains = monikerclient.cli.reports:DomainCountCommand
report-count-records = monikerclient.cli.reports:RecordCountCommand
report-count-tenants = monikerclient.cli.reports:TenantCountCommand
report-tenants-all = monikerclient.cli.reports:TenantsCommand
report-tenant-domains = monikerclient.cli.reports:TenantCommand
"""),
classifiers=[
'Development Status :: 3 - Alpha',