diff options
author | Erik Olof Gunnar Andersson <eandersson@blizzard.com> | 2019-09-10 19:45:29 -0700 |
---|---|---|
committer | Erik Olof Gunnar Andersson <eandersson@blizzard.com> | 2019-09-10 20:53:25 -0700 |
commit | 093d8d7170cbf6ef8c7a7c0ff2a4dcd7ecd6361b (patch) | |
tree | aaa453be6cf3df5cf18937694059911329163bf3 /designateclient | |
parent | 5c9bbbfac8f03be416b268798045b5814c3fbe06 (diff) | |
download | python-designateclient-093d8d7170cbf6ef8c7a7c0ff2a4dcd7ecd6361b.tar.gz |
The v1 has officially been removed from Designate since
the Queens release, and was deperecated long before that.
Change-Id: Ic5b44761ff939e2b319924af87849b3a79f9cb07
Diffstat (limited to 'designateclient')
36 files changed, 3 insertions, 3060 deletions
diff --git a/designateclient/cli/__init__.py b/designateclient/cli/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/designateclient/cli/__init__.py +++ /dev/null diff --git a/designateclient/cli/base.py b/designateclient/cli/base.py deleted file mode 100644 index af4f2de..0000000 --- a/designateclient/cli/base.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 abc -import warnings - -from keystoneauth1 import exceptions as ks_exceptions -from osc_lib.command import command -import six - -from designateclient import exceptions -from designateclient import utils -from designateclient.v1 import Client - - -@six.add_metaclass(abc.ABCMeta) -class Command(command.Command): - def run(self, parsed_args): - - warnings.simplefilter('once', category=DeprecationWarning) - warnings.warn( - 'The "designate" CLI is being deprecated in favour of the ' - '"openstack" CLI plugin. All designate API v2 commands are ' - 'implemented there. When the v1 API is removed this CLI will ' - 'stop functioning', - DeprecationWarning) - warnings.resetwarnings() - warnings.simplefilter('ignore', category=DeprecationWarning) - - self.client = Client( - region_name=self.app.options.os_region_name, - service_type=self.app.options.os_service_type, - endpoint_type=self.app.options.os_endpoint_type, - session=self.app.session, - all_tenants=self.app.options.all_tenants, - edit_managed=self.app.options.edit_managed, - endpoint=self.app.options.os_endpoint) - warnings.resetwarnings() - try: - return super(Command, self).run(parsed_args) - except exceptions.RemoteError as e: - columns = ['Code', 'Type'] - values = [e.code, e.type] - - if e.message: - columns.append('Message') - values.append(e.message) - - if e.errors: - columns.append('Errors') - values.append(e.errors) - - self.error_output(parsed_args, columns, values) - except ks_exceptions.EndpointNotFound as e: - self.app.log.error('No endpoint was found. You must provide a ' - 'username or user id via --os-username, ' - '--os-user-id, env[OS_USERNAME] or ' - 'env[OS_USER_ID]. You may also be using a ' - 'cloud that does not have the V1 API enabled. ' - 'If your cloud does not have the V1 DNS API ' - 'use the openstack CLI to interact with the ' - 'DNS Service.') - - return 1 - - def error_output(self, parsed_args, column_names, data): - self.formatter.emit_one(column_names, - data, - self.app.stdout, - parsed_args) - self.app.log.error('The requested action did not complete ' - 'successfully') - - @abc.abstractmethod - def execute(self, parsed_args): - """ - Execute something, this is since we overload self.take_action() - in order to format the data - - This method __NEEDS__ to be overloaded! - - :param parsed_args: The parsed args that are given by take_action() - """ - - def post_execute(self, data): - """ - Format the results locally if needed, by default we just return data - - :param data: Whatever is returned by self.execute() - """ - return data - - def take_action(self, parsed_args): - results = self.execute(parsed_args) - return self.post_execute(results) - - def find_resourceid_by_name_or_id(self, resource_plural, name_or_id): - resource_client = getattr(self.client, resource_plural) - return utils.find_resourceid_by_name_or_id(resource_client, name_or_id) - - -class ListCommand(Command, command.Lister): - columns = None - - def post_execute(self, results): - if len(results) > 0: - columns = self.columns or utils.get_columns(results) - data = [utils.get_item_properties(i, columns) for i in results] - return columns, data - else: - return [], () - - -class GetCommand(Command, command.ShowOne): - def post_execute(self, results): - return results.keys(), results.values() - - -class CreateCommand(Command, command.ShowOne): - def post_execute(self, results): - return results.keys(), results.values() - - -class UpdateCommand(Command, command.ShowOne): - def post_execute(self, results): - return results.keys(), results.values() - - -class DeleteCommand(Command, command.ShowOne): - def post_execute(self, results): - return [], [] diff --git a/designateclient/cli/diagnostics.py b/designateclient/cli/diagnostics.py deleted file mode 100644 index e621616..0000000 --- a/designateclient/cli/diagnostics.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base - -LOG = logging.getLogger(__name__) - - -class PingCommand(base.GetCommand): - """Ping a service on a given host""" - - def get_parser(self, prog_name): - parser = super(PingCommand, self).get_parser(prog_name) - - parser.add_argument('--service', help="Service name (e.g. central)", - required=True) - parser.add_argument('--host', help="Hostname", required=True) - - return parser - - def execute(self, parsed_args): - return self.client.diagnostics.ping(parsed_args.service, - parsed_args.host) diff --git a/designateclient/cli/domains.py b/designateclient/cli/domains.py deleted file mode 100644 index 25ccd31..0000000 --- a/designateclient/cli/domains.py +++ /dev/null @@ -1,144 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base -from designateclient.v1.domains import Domain - -LOG = logging.getLogger(__name__) - - -class ListDomainsCommand(base.ListCommand): - """List Domains""" - - columns = ['id', 'name', 'serial'] - - def execute(self, parsed_args): - return self.client.domains.list() - - -class GetDomainCommand(base.GetCommand): - """Get Domain""" - - def get_parser(self, prog_name): - parser = super(GetDomainCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Domain ID or name.") - - return parser - - def execute(self, parsed_args): - id = self.find_resourceid_by_name_or_id('domains', parsed_args.id) - return self.client.domains.get(id) - - -class CreateDomainCommand(base.CreateCommand): - """Create Domain""" - - def get_parser(self, prog_name): - parser = super(CreateDomainCommand, self).get_parser(prog_name) - - parser.add_argument('--name', help="Domain name.", required=True) - parser.add_argument('--email', help="Domain email.", required=True) - parser.add_argument('--ttl', type=int, help="Time to live (seconds).") - parser.add_argument('--description', help="Description.") - - return parser - - def execute(self, parsed_args): - domain = Domain( - name=parsed_args.name, - email=parsed_args.email, - ) - - if parsed_args.description: - domain.description = parsed_args.description - - if parsed_args.ttl is not None: - domain.ttl = parsed_args.ttl - - return self.client.domains.create(domain) - - -class UpdateDomainCommand(base.UpdateCommand): - """Update Domain""" - - def get_parser(self, prog_name): - parser = super(UpdateDomainCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Domain ID or name.") - parser.add_argument('--name', help="Domain name.") - parser.add_argument('--email', help="Domain email.") - parser.add_argument('--ttl', type=int, help="Time to live (seconds).") - description_group = parser.add_mutually_exclusive_group() - description_group.add_argument('--description', help="Description.") - description_group.add_argument('--no-description', action='store_true') - - return parser - - def execute(self, parsed_args): - # TODO(kiall): API needs updating.. this get is silly - id = self.find_resourceid_by_name_or_id('domains', parsed_args.id) - domain = self.client.domains.get(id) - - if parsed_args.name: - domain.name = parsed_args.name - - if parsed_args.email: - domain.email = parsed_args.email - - if parsed_args.ttl is not None: - domain.ttl = parsed_args.ttl - - if parsed_args.no_description: - domain.description = None - elif parsed_args.description: - domain.description = parsed_args.description - - return self.client.domains.update(domain) - - -class DeleteDomainCommand(base.DeleteCommand): - """Delete Domain""" - - def get_parser(self, prog_name): - parser = super(DeleteDomainCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Domain ID or name.") - - return parser - - def execute(self, parsed_args): - id = self.find_resourceid_by_name_or_id('domains', parsed_args.id) - return self.client.domains.delete(id) - - -class ListDomainServersCommand(base.ListCommand): - """List Domain Servers""" - - columns = ['name'] - - def get_parser(self, prog_name): - parser = super(ListDomainServersCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Domain ID or name.") - - return parser - - def execute(self, parsed_args): - id = self.find_resourceid_by_name_or_id('domains', parsed_args.id) - return self.client.domains.list_domain_servers(id) diff --git a/designateclient/cli/quotas.py b/designateclient/cli/quotas.py deleted file mode 100644 index ae41690..0000000 --- a/designateclient/cli/quotas.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2014 Hewlett-Packard Development Company, L.P. -# -# Author: Endre Karlson <endre.karlson@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 logging - -from designateclient.cli import base - - -LOG = logging.getLogger(__name__) - - -class GetQuotaCommand(base.GetCommand): - """Get Quota""" - - def get_parser(self, prog_name): - parser = super(GetQuotaCommand, self).get_parser(prog_name) - - parser.add_argument('tenant_id', help="Tenant ID") - - return parser - - def execute(self, parsed_args): - return self.client.quotas.get(parsed_args.tenant_id) - - -class UpdateQuotaCommand(base.UpdateCommand): - """Update Quota""" - - def get_parser(self, prog_name): - parser = super(UpdateQuotaCommand, self).get_parser(prog_name) - - parser.add_argument('tenant_id', help="Tenant ID.") - parser.add_argument('--domains', help="Allowed domains.", type=int) - parser.add_argument('--domain-recordsets', - help="Allowed domain records.", - type=int) - parser.add_argument('--recordset-records', - help="Allowed recordset records.", - type=int) - parser.add_argument('--domain-records', - help="Allowed domain records.", - type=int) - parser.add_argument('--api-export-size', - help="Allowed zone export recordsets.", - type=int) - return parser - - def execute(self, parsed_args): - # TODO(kiall): API needs updating.. this get is silly - quota = self.client.quotas.get(parsed_args.tenant_id) - - for key, old in quota.items(): - new = getattr(parsed_args, key) - if new is not None and new != old: - quota[key] = new - return self.client.quotas.update(parsed_args.tenant_id, quota) - - -class ResetQuotaCommand(base.DeleteCommand): - """Reset Quota""" - - def get_parser(self, prog_name): - parser = super(ResetQuotaCommand, self).get_parser(prog_name) - - parser.add_argument('tenant_id', help="Tenant ID.") - - return parser - - def execute(self, parsed_args): - self.client.quotas.reset(parsed_args.tenant_id) diff --git a/designateclient/cli/records.py b/designateclient/cli/records.py deleted file mode 100644 index 6e276ca..0000000 --- a/designateclient/cli/records.py +++ /dev/null @@ -1,187 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base -from designateclient.v1.records import Record - -LOG = logging.getLogger(__name__) - - -class ListRecordsCommand(base.ListCommand): - """List Records""" - - columns = ['id', 'type', 'name', 'data'] - - def get_parser(self, prog_name): - parser = super(ListRecordsCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID or name.") - - return parser - - def execute(self, parsed_args): - domain_id = self.find_resourceid_by_name_or_id( - 'domains', parsed_args.domain_id) - return self.client.records.list(domain_id) - - -class GetRecordCommand(base.GetCommand): - """Get Record""" - - def get_parser(self, prog_name): - parser = super(GetRecordCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID or name.") - parser.add_argument('id', help="Record ID.") - - return parser - - def execute(self, parsed_args): - domain_id = self.find_resourceid_by_name_or_id( - 'domains', parsed_args.domain_id) - return self.client.records.get(domain_id, parsed_args.id) - - -class CreateRecordCommand(base.CreateCommand): - """Create Record""" - - def get_parser(self, prog_name): - parser = super(CreateRecordCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID or name.") - parser.add_argument( - '--name', help="Record (relative|absolute) name.", required=True) - parser.add_argument('--type', help="Record type.", required=True) - parser.add_argument('--data', help="Record data.", required=True) - parser.add_argument('--ttl', type=int, help="Record TTL.") - parser.add_argument('--priority', type=int, help="Record priority.") - parser.add_argument('--description', help="Description.") - - return parser - - def execute(self, parsed_args): - domain_id = self.find_resourceid_by_name_or_id( - 'domains', parsed_args.domain_id) - - if not parsed_args.name.endswith('.'): - # Relative name? - domain_name = self.client.domains.get(domain_id)['name'] - absolute = parsed_args.name + '.' - relative = absolute + domain_name - if absolute.endswith('.' + domain_name): - # Relative name or absolute name missing final period? - msg = ('"%s" is a relative name but looks like an absolute ' - 'name, use --name "%s" or "%s"' - % (parsed_args.name, absolute, relative)) - raise ValueError(msg) - parsed_args.name = relative - - record = Record( - name=parsed_args.name, - type=parsed_args.type, - data=parsed_args.data, - ) - - if parsed_args.ttl is not None: - record.ttl = parsed_args.ttl - - if parsed_args.priority is not None: - record.priority = parsed_args.priority - - if parsed_args.description: - record.description = parsed_args.description - - return self.client.records.create(domain_id, record) - - -class UpdateRecordCommand(base.UpdateCommand): - """Update Record""" - - def get_parser(self, prog_name): - parser = super(UpdateRecordCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID or name.") - parser.add_argument('id', help="Record ID.") - parser.add_argument('--name', help="Record name.") - parser.add_argument('--type', help="Record type.") - parser.add_argument('--data', help="Record data.") - - description_group = parser.add_mutually_exclusive_group() - description_group.add_argument('--description', help="Description.") - description_group.add_argument('--no-description', action='store_true') - - ttl_group = parser.add_mutually_exclusive_group() - ttl_group.add_argument('--ttl', type=int, - help="Record time to live (seconds).") - ttl_group.add_argument('--no-ttl', action='store_true') - - priotity_group = parser.add_mutually_exclusive_group() - priotity_group.add_argument('--priority', type=int, - help="Record priority.") - priotity_group.add_argument('--no-priority', action='store_true') - - return parser - - def execute(self, parsed_args): - # TODO(kiall): API needs updating.. this get is silly - record = self.client.records.get(parsed_args.domain_id, parsed_args.id) - - if parsed_args.name: - record.name = parsed_args.name - - if parsed_args.type: - record.type = parsed_args.type - - if parsed_args.data: - record.data = parsed_args.data - - if parsed_args.no_ttl: - record.ttl = None - elif parsed_args.ttl is not None: - record.ttl = parsed_args.ttl - - if parsed_args.no_priority: - record.priority = None - elif parsed_args.priority is not None: - record.priority = parsed_args.priority - - if parsed_args.no_description: - record.description = None - elif parsed_args.description: - record.description = parsed_args.description - - domain_id = self.find_resourceid_by_name_or_id( - 'domains', parsed_args.domain_id) - return self.client.records.update(domain_id, record) - - -class DeleteRecordCommand(base.DeleteCommand): - """Delete Record""" - - def get_parser(self, prog_name): - parser = super(DeleteRecordCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID or name.") - parser.add_argument('id', help="Record ID.") - - return parser - - def execute(self, parsed_args): - domain_id = self.find_resourceid_by_name_or_id( - 'domains', parsed_args.domain_id) - return self.client.records.delete(domain_id, parsed_args.id) diff --git a/designateclient/cli/reports.py b/designateclient/cli/reports.py deleted file mode 100644 index 6ecfc2e..0000000 --- a/designateclient/cli/reports.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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 designateclient.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="The 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) diff --git a/designateclient/cli/servers.py b/designateclient/cli/servers.py deleted file mode 100644 index 184271b..0000000 --- a/designateclient/cli/servers.py +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base -from designateclient.v1.servers import Server - -LOG = logging.getLogger(__name__) - - -class ListServersCommand(base.ListCommand): - """List Servers""" - - columns = ['id', 'name'] - - def execute(self, parsed_args): - return self.client.servers.list() - - -class GetServerCommand(base.GetCommand): - """Get Server""" - - def get_parser(self, prog_name): - parser = super(GetServerCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Server ID.") - - return parser - - def execute(self, parsed_args): - return self.client.servers.get(parsed_args.id) - - -class CreateServerCommand(base.CreateCommand): - """Create Server""" - - def get_parser(self, prog_name): - parser = super(CreateServerCommand, self).get_parser(prog_name) - - parser.add_argument('--name', help="Server name.", required=True) - - return parser - - def execute(self, parsed_args): - server = Server( - name=parsed_args.name, - ) - - return self.client.servers.create(server) - - -class UpdateServerCommand(base.UpdateCommand): - """Update Server""" - - def get_parser(self, prog_name): - parser = super(UpdateServerCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Server ID.") - parser.add_argument('--name', help="Server name.") - - return parser - - def execute(self, parsed_args): - # TODO(kiall): API needs updating.. this get is silly - server = self.client.servers.get(parsed_args.id) - - if parsed_args.name: - server.name = parsed_args.name - - return self.client.servers.update(server) - - -class DeleteServerCommand(base.DeleteCommand): - """Delete Server""" - - def get_parser(self, prog_name): - parser = super(DeleteServerCommand, self).get_parser(prog_name) - - parser.add_argument('id', help="Server ID.") - - return parser - - def execute(self, parsed_args): - return self.client.servers.delete(parsed_args.id) diff --git a/designateclient/cli/sync.py b/designateclient/cli/sync.py deleted file mode 100644 index 18e2852..0000000 --- a/designateclient/cli/sync.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base - -LOG = logging.getLogger(__name__) - - -class SyncAllCommand(base.DeleteCommand): - """Sync Everything""" - - def execute(self, parsed_args): - self.client.sync.sync_all() - - LOG.info('Synchronization of all domains scheduled') - - -class SyncDomainCommand(base.DeleteCommand): - """Sync a single Domain""" - - def get_parser(self, prog_name): - parser = super(SyncDomainCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID") - - return parser - - def execute(self, parsed_args): - self.client.sync.sync_domain(parsed_args.domain_id) - - LOG.info('Synchronization of domain scheduled') - - -class SyncRecordCommand(base.DeleteCommand): - """Sync a single Record""" - - def get_parser(self, prog_name): - parser = super(SyncRecordCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID") - parser.add_argument('record_id', help="Record ID") - - return parser - - def execute(self, parsed_args): - self.client.sync.sync_record(parsed_args.domain_id, - parsed_args.record_id) - - LOG.info('Synchronization of record scheduled') diff --git a/designateclient/cli/touch.py b/designateclient/cli/touch.py deleted file mode 100644 index a9713f0..0000000 --- a/designateclient/cli/touch.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging - -from designateclient.cli import base - -LOG = logging.getLogger(__name__) - - -class TouchDomainCommand(base.DeleteCommand): - """Touch a single Domain""" - - def get_parser(self, prog_name): - parser = super(TouchDomainCommand, self).get_parser(prog_name) - - parser.add_argument('domain_id', help="Domain ID") - - return parser - - def execute(self, parsed_args): - self.client.touch.domain(parsed_args.domain_id) - - LOG.info('Domain touched successfully') diff --git a/designateclient/osc/plugin.py b/designateclient/osc/plugin.py index eeeae7a..6b8719b 100644 --- a/designateclient/osc/plugin.py +++ b/designateclient/osc/plugin.py @@ -16,9 +16,9 @@ """OpenStackClient plugin for DNS service.""" -from osc_lib import utils as oscutils +import os -from designateclient import shell +from osc_lib import utils as oscutils DEFAULT_API_VERSION = '2' @@ -45,7 +45,7 @@ def build_option_parser(parser): parser.add_argument( '--os-dns-api-version', metavar='<dns-api-version>', - default=shell.env('OS_DNS_API_VERSION', default="2"), + default=os.environ.get('OS_DNS_API_VERSION', '2'), help='DNS API version, default=' + DEFAULT_API_VERSION + ' (Env: OS_DNS_API_VERSION)') diff --git a/designateclient/resources/schemas/v1/domain.json b/designateclient/resources/schemas/v1/domain.json deleted file mode 100644 index 5ed584f..0000000 --- a/designateclient/resources/schemas/v1/domain.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "id": "domain", - - "$schema": "http://json-schema.org/draft-03/hyper-schema", - - "title": "domain", - "description": "Domain", - "additionalProperties": false, - - "properties": { - "id": { - "type": "string", - "description": "Domain Identifier", - "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$", - "readonly": true - }, - "name": { - "type": "string", - "description": "Domain name", - "format": "domain-name", - "maxLength": 255, - "required": true, - "readonly": true - }, - "email": { - "type": "string", - "description": "Hostmaster email address", - "format": "email", - "maxLength": 255, - "required": true - }, - "ttl": { - "type": "integer", - "description": "Time to live", - "minimum": 1, - "maximum": 2147483647 - }, - "serial": { - "type": "integer", - "description": "Serial Number", - "minimum": 1, - "maximum": 4294967295, - "readonly": true - }, - "description": { - "type": ["string", "null"], - "description": "Description for the Domain", - "maxLength": 160 - }, - "created_at": { - "type": "string", - "description": "Date and time of domain creation", - "format": "date-time", - "readonly": true - }, - "updated_at": { - "type": ["string", "null"], - "description": "Date and time of last domain update", - "format": "date-time", - "readonly": true - } - }, - "links": [{ - "rel": "self", - "href": "/domains/{id}" - }, { - "rel": "records", - "href": "/domains/{id}/records" - }, { - "rel": "servers", - "href": "/domains/{id}/servers" - }, { - "rel": "collection", - "href": "/domains" - }] -} diff --git a/designateclient/resources/schemas/v1/record.json b/designateclient/resources/schemas/v1/record.json deleted file mode 100644 index cecc9fd..0000000 --- a/designateclient/resources/schemas/v1/record.json +++ /dev/null @@ -1,246 +0,0 @@ -{ - "id": "record", - - "$schema": "http://json-schema.org/draft-03/hyper-schema", - - "title": "record", - "description": "Record", - "additionalProperties": false, - - "properties": { - "id": { - "type": "string", - "description": "Record Identifier", - "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$", - "readonly": true - }, - "domain_id": { - "type": "string", - "description": "Domain Identifier", - "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$", - "readonly": true - }, - "name": { - "type": "string", - "description": "DNS Record Name", - "format": "host-name", - "maxLength": 255, - "required": true - }, - "type": { - "type": "string", - "description": "DNS Record Type", - "enum": ["A", "AAAA", "CNAME", "MX", "SRV", "TXT", "SPF", "NS", "PTR", "SSHFP", "SOA"], - "required": true - }, - "data": { - "type": "string", - "description": "DNS Record Value", - "maxLength": 255, - "required": true - }, - "priority": { - "type": ["integer", "null"], - "description": "DNS Record Priority", - "minimum": 0, - "maximum": 65535 - }, - "ttl": { - "type": ["integer", "null"], - "description": "Time to live", - "minimum": 1, - "maximum": 2147483647 - }, - "description": { - "type": ["string", "null"], - "description": "Description for the record", - "maxLength": 160 - }, - "created_at": { - "type": "string", - "description": "Date and time of record creation", - "format": "date-time", - "readonly": true - }, - "updated_at": { - "type": ["string", "null"], - "description": "Date and time of last record update", - "format": "date-time", - "readonly": true - } - }, - "oneOf": [{ - "description": "An A Record", - "properties": { - "type": { - "type": "string", - "enum": ["A"] - }, - "data": { - "format": "ip-address", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "An AAAA Record", - "properties": { - "type": { - "type": "string", - "enum": ["AAAA"] - }, - "data": { - "format": "ipv6", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A CNAME Record", - "properties": { - "type": { - "type": "string", - "enum": ["CNAME"] - }, - "data": { - "format": "host-name", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A MX Record", - "properties": { - "type": { - "type": "string", - "enum": ["MX"] - }, - "data": { - "format": "host-name", - "required": true - }, - "priority": { - "type": "integer", - "required": true - } - } - }, { - "description": "A SRV Record", - "properties": { - "type": { - "type": "string", - "enum": ["SRV"] - }, - "name": { - "type": "string", - "pattern": "^(?:_[A-Za-z0-9_\\-]{1,62}\\.){2}" - }, - "data": { - "type": "string", - "pattern": "^(?:(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])\\s){2}(?!.{255,})((?!\\-)[A-Za-z0-9_\\-]{1,63}(?<!\\-)\\.)+$" - }, - "priority": { - "type": "integer", - "required": true - } - } - }, { - "description": "A TXT Record", - "properties": { - "type": { - "type": "string", - "enum": ["TXT"] - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A SPF Record", - "properties": { - "type": { - "type": "string", - "enum": ["SPF"] - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A NS Record", - "properties": { - "type": { - "type": "string", - "enum": ["NS"] - }, - "data": { - "format": "host-name", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A PTR Record", - "properties": { - "type": { - "type": "string", - "enum": ["PTR"] - }, - "name": { - "type": "string", - "pattern": "^(?:(?:\\d{1,3}\\.){4}in-addr\\.arpa\\.|(?:[a-f|\\d]\\.){32}ip6\\.arpa\\.)$" - }, - "data": { - "format": "host-name", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A SSHFP Record", - "properties": { - "type": { - "type": "string", - "enum": ["SSHFP"] - }, - "data": { - "pattern": "^[1-2] 1 [0-9A-Fa-f]{40}$", - "required": true - }, - "priority": { - "type": "null" - } - } - }, { - "description": "A SOA Record", - "properties": { - "type": { - "type": "string", - "enum": ["SOA"] - }, - "priority": { - "type": "null" - } - } - }], - "links": [{ - "rel": "self", - "href": "/domains/{domain_id}/records/{id}" - }, { - "rel": "domain", - "href": "/domains/{domain_id}" - }, { - "rel": "collection", - "href": "/domains/{domain_id}/records" - }] -} diff --git a/designateclient/resources/schemas/v1/server.json b/designateclient/resources/schemas/v1/server.json deleted file mode 100644 index 402b42b..0000000 --- a/designateclient/resources/schemas/v1/server.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "id": "server", - - "$schema": "http://json-schema.org/draft-03/hyper-schema", - - "title": "server", - "description": "Server", - "additionalProperties": false, - - "properties": { - "id": { - "type": "string", - "description": "Server Identifier", - "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$", - "readonly": true - }, - "name": { - "type": "string", - "description": "Server DNS name", - "format": "host-name", - "maxLength": 255, - "required": true - }, - "created_at": { - "type": "string", - "description": "Date and time of server creation", - "format": "date-time", - "readonly": true - }, - "updated_at": { - "type": ["string", "null"], - "description": "Date and time of last server update", - "format": "date-time", - "readonly": true - } - }, - "links": [{ - "rel": "self", - "href": "/servers/{id}" - }, { - "rel": "collection", - "href": "/servers" - }] -} diff --git a/designateclient/shell.py b/designateclient/shell.py deleted file mode 100644 index dcd4f06..0000000 --- a/designateclient/shell.py +++ /dev/null @@ -1,252 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 logging -import os -import traceback - -from cliff.app import App -from cliff.commandmanager import CommandManager - -from designateclient import utils -from designateclient.version import version_info as version - - -def env(*vars, **kwargs): - """Search for the first defined of possibly many env vars - - Returns the first environment variable defined in vars, or - returns the default defined in kwargs. - - """ - for v in vars: - value = os.environ.get(v) - if value: - return value - return kwargs.get('default', '') - - -class DesignateShell(App): - CONSOLE_MESSAGE_FORMAT = '%(levelname)s: %(message)s' - DEFAULT_VERBOSE_LEVEL = 0 - - def __init__(self): - super(DesignateShell, self).__init__( - description='Designate Client', - version=version.version_string(), - command_manager=CommandManager('designateclient.cli'), - ) - - self.log = logging.getLogger(__name__) - - def build_option_parser(self, description, version): - parser = super(DesignateShell, self).build_option_parser( - description, version) - - parser.add_argument('--os-username', - default=env('OS_USERNAME'), - help='Name used for authentication with the ' - 'OpenStack Identity service. ' - 'Defaults to env[OS_USERNAME].') - - parser.add_argument('--os-user-id', - default=env('OS_USER_ID'), - help='User ID used for authentication with the ' - 'OpenStack Identity service. ' - 'Defaults to env[OS_USER_ID].') - - parser.add_argument('--os-user-domain-id', - default=env('OS_USER_DOMAIN_ID'), - help='Defaults to env[OS_USER_DOMAIN_ID].') - - parser.add_argument('--os-user-domain-name', - default=env('OS_USER_DOMAIN_NAME'), - help='Defaults to env[OS_USER_DOMAIN_NAME].') - - parser.add_argument('--os-password', - default=env('OS_PASSWORD'), - help='Password used for authentication with the ' - 'OpenStack Identity service. ' - 'Defaults to env[OS_PASSWORD].') - - parser.add_argument('--os-tenant-name', - default=env('OS_TENANT_NAME'), - help='Tenant to request authorization on. ' - 'Defaults to env[OS_TENANT_NAME].') - - parser.add_argument('--os-tenant-id', - default=env('OS_TENANT_ID'), - help='Tenant to request authorization on. ' - 'Defaults to env[OS_TENANT_ID].') - - parser.add_argument('--os-project-name', - default=env('OS_PROJECT_NAME'), - help='Project to request authorization on. ' - 'Defaults to env[OS_PROJECT_NAME].') - - parser.add_argument('--os-domain-name', - default=env('OS_DOMAIN_NAME'), - help='Project to request authorization on. ' - 'Defaults to env[OS_DOMAIN_NAME].') - - parser.add_argument('--os-domain-id', - default=env('OS_DOMAIN_ID'), - help='Defaults to env[OS_DOMAIN_ID].') - - parser.add_argument('--os-project-id', - default=env('OS_PROJECT_ID'), - help='Project to request authorization on. ' - 'Defaults to env[OS_PROJECT_ID].') - - parser.add_argument('--os-project-domain-id', - default=env('OS_PROJECT_DOMAIN_ID'), - help='Defaults to env[OS_PROJECT_DOMAIN_ID].') - - parser.add_argument('--os-project-domain-name', - default=env('OS_PROJECT_DOMAIN_NAME'), - help='Defaults to env[OS_PROJECT_DOMAIN_NAME].') - - parser.add_argument('--os-auth-url', - default=env('OS_AUTH_URL'), - help='Specify the Identity endpoint to use for ' - 'authentication. ' - 'Defaults to env[OS_AUTH_URL].') - - parser.add_argument('--os-region-name', - default=env('OS_REGION_NAME'), - help='Specify the region to use. ' - 'Defaults to env[OS_REGION_NAME].') - - parser.add_argument('--os-token', - default=env('OS_SERVICE_TOKEN'), - help='Specify an existing token to use instead of ' - 'retrieving one via authentication (e.g. ' - 'with username & password). ' - 'Defaults to env[OS_SERVICE_TOKEN].') - - parser.add_argument('--os-endpoint', - default=env('OS_DNS_ENDPOINT', - 'OS_SERVICE_ENDPOINT'), - help='Specify an endpoint to use instead of ' - 'retrieving one from the service catalog ' - '(via authentication). ' - 'Defaults to env[OS_DNS_ENDPOINT].') - - parser.add_argument('--os-endpoint-type', - default=env('OS_ENDPOINT_TYPE', - default='publicURL'), - help='Defaults to env[OS_ENDPOINT_TYPE].') - - parser.add_argument('--os-service-type', - default=env('OS_DNS_SERVICE_TYPE', default='dns'), - help=("Defaults to env[OS_DNS_SERVICE_TYPE], or " - "'dns'.")) - - parser.add_argument('--os-cacert', - default=env('OS_CACERT'), - help=('CA certificate bundle file. Defaults to ' - 'env[OS_CACERT].')) - - parser.add_argument('--insecure', action='store_true', - help="Explicitly allow 'insecure' SSL requests.") - - parser.add_argument('--all-tenants', action='store_true', - help="Allows to list all domains from all " - "tenants.") - - parser.add_argument('--edit-managed', action='store_true', - help='Allows to edit records that are marked as ' - 'managed.') - - return parser - - def configure_logging(self): - """Configure logging for the app - - Cliff sets some defaults we don't want so re-work it a bit - """ - - if self.options.debug: - # --debug forces verbose_level 3 - # Set this here so cliff.app.configure_logging() can work - self.options.verbose_level = 3 - - super(DesignateShell, self).configure_logging() - root_logger = logging.getLogger('') - - # Requests logs some stuff at INFO that we don't want - # unless we have DEBUG - requests_log = logging.getLogger("requests") - requests_log.setLevel(logging.ERROR) - - # Other modules we don't want DEBUG output for so - # don't reset them below - iso8601_log = logging.getLogger("iso8601") - iso8601_log.setLevel(logging.ERROR) - - # Set logging to the requested level - self.dump_stack_trace = False - if self.options.verbose_level == 0: - # --quiet - root_logger.setLevel(logging.ERROR) - elif self.options.verbose_level == 1: - # This is the default case, no --debug, --verbose or --quiet - root_logger.setLevel(logging.WARNING) - elif self.options.verbose_level == 2: - # One --verbose - root_logger.setLevel(logging.INFO) - elif self.options.verbose_level >= 3: - # Two or more --verbose - root_logger.setLevel(logging.DEBUG) - requests_log.setLevel(logging.DEBUG) - - if self.options.debug: - # --debug forces traceback - self.dump_stack_trace = True - - def initialize_app(self, argv): - super(DesignateShell, self).initialize_app(argv) - self.session = utils.get_session( - auth_url=self.options.os_auth_url, - endpoint=self.options.os_endpoint, - domain_id=self.options.os_domain_id, - domain_name=self.options.os_domain_name, - project_id=self.options.os_project_id or self.options.os_tenant_id, - project_name=(self.options.os_project_name or - self.options.os_tenant_name), - project_domain_name=self.options.os_project_domain_name, - project_domain_id=self.options.os_project_domain_id, - username=self.options.os_username, - user_id=self.options.os_user_id, - password=self.options.os_password, - user_domain_id=self.options.os_user_domain_id, - user_domain_name=self.options.os_user_domain_name, - token=self.options.os_token, - insecure=self.options.insecure, - cacert=self.options.os_cacert - ) - - def run(self, argv): - try: - return super(DesignateShell, self).run(argv) - except Exception as e: - if not logging.getLogger('').handlers: - logging.basicConfig() - if self.dump_stack_trace: - self.log.error(traceback.format_exc(e)) - else: - self.log.error('Exception raised: ' + str(e)) - return 1 diff --git a/designateclient/tests/test_utils.py b/designateclient/tests/test_utils.py index e4fa7b0..359d0e1 100644 --- a/designateclient/tests/test_utils.py +++ b/designateclient/tests/test_utils.py @@ -62,24 +62,3 @@ class UtilsTestCase(base.TestCase): self.assertRaises(exceptions.NoUniqueMatch, self._find_resourceid_by_name_or_id, 'baba', by_name=True) - - def test_load_schema(self): - schema = utils.load_schema('v1', 'domain') - self.assertIsInstance(schema, dict) - - def test_load_schema_missing(self): - self.assertRaises(exceptions.ResourceNotFound, utils.load_schema, - 'v1', 'missing') - - def test_resource_string_empty_param(self): - self.assertRaises(ValueError, utils.resource_string) - - def test_resource_string(self): - name = ['schemas', 'v1', 'domain.json'] - resource_string = utils.resource_string(*name) - self.assertIsNotNone(resource_string) - - def test_resource_string_missing(self): - name = ['schemas', 'v1', 'missing'] - self.assertRaises(exceptions.ResourceNotFound, utils.resource_string, - *name) diff --git a/designateclient/tests/test_v1/__init__.py b/designateclient/tests/test_v1/__init__.py deleted file mode 100644 index 3654a91..0000000 --- a/designateclient/tests/test_v1/__init__.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# 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 uuid - -from designateclient.tests import base - - -class CrudMixin(object): - path_prefix = None - - def new_ref(self, **kwargs): - kwargs.setdefault('id', uuid.uuid4().hex) - return kwargs - - def stub_entity(self, method, parts=None, entity=None, id=None, **kwargs): - if entity: - kwargs['json'] = entity - - if not parts: - parts = [self.RESOURCE] - - if self.path_prefix: - parts.insert(0, self.path_prefix) - - if id: - if not parts: - parts = [] - - parts.append(id) - - self.stub_url(method, parts=parts, **kwargs) - - def assertList(self, expected, actual): - self.assertEqual(len(expected), len(actual)) - for i in expected: - self.assertIn(i, actual) - - -class APIV1TestCase(base.APITestCase): - VERSION = "1" diff --git a/designateclient/tests/test_v1/test_client.py b/designateclient/tests/test_v1/test_client.py deleted file mode 100644 index f46f64d..0000000 --- a/designateclient/tests/test_v1/test_client.py +++ /dev/null @@ -1,124 +0,0 @@ -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# 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. - -from designateclient.tests import test_v1 -from designateclient import utils -from designateclient import v1 - -from keystoneauth1 import session as keystone_session - - -class TestClient(test_v1.APIV1TestCase): - def test_all_tenants(self): - # Create a client with the all_tenants flag set to True - client = v1.Client(all_tenants=True) - - # Verify this has been picked up - self.assertTrue(client.all_tenants) - - def test_all_tenants_not_supplied(self): - # Create a client without supplying any all_tenants flag - client = v1.Client() - - # Verify all_tenants is False - self.assertFalse(client.all_tenants) - self.assertIsNotNone(client.all_tenants) - - def test_all_tenants_through_session(self): - # Create a session with the all_tenants flag set to True - session = utils.get_session( - auth_url='Anything', - endpoint='Anything', - domain_id='Anything', - domain_name='Anything', - project_id='Anything', - project_name='Anything', - project_domain_name='Anything', - project_domain_id='Anything', - username='Anything', - user_id='Anything', - password='Anything', - user_domain_id='Anything', - user_domain_name='Anything', - token=None, - insecure=False, - cacert=None, - all_tenants=True) - - # Create a client using the pre-created session - client = v1.Client(session=session) - - # Verify the all_tenants flag has been picked up - self.assertTrue(client.all_tenants) - - def test_edit_managed(self): - # Create a client with the edit_managed flag set to True - client = v1.Client(edit_managed=True) - - # Verify this has been picked up - self.assertTrue(client.edit_managed) - - def test_edit_managed_not_supplied(self): - # Create a client without supplying any edit_managed flag - client = v1.Client() - - # Verify edit_managed is False - self.assertFalse(client.edit_managed) - self.assertIsNotNone(client.edit_managed) - - def test_edit_managed_through_session(self): - # Create a session with the edit_managed flag set to True - session = utils.get_session( - auth_url='Anything', - endpoint='Anything', - domain_id='Anything', - domain_name='Anything', - project_id='Anything', - project_name='Anything', - project_domain_name='Anything', - project_domain_id='Anything', - username='Anything', - user_id='Anything', - password='Anything', - user_domain_id='Anything', - user_domain_name='Anything', - token=None, - insecure=False, - cacert=None, - edit_managed=True) - - # Create a client using the pre-created session - client = v1.Client(session=session) - - # Verify the edit_managed flag has been picked up - self.assertTrue(client.edit_managed) - - def test_timeout_new_session(self): - client = v1.Client( - auth_url="http://127.0.0.1:22/", - timeout=1, - ) - assert client.session.timeout == 1 - - def test_timeout_override_session_timeout(self): - # The adapter timeout should override the session timeout - session = keystone_session.Session(timeout=10) - client = v1.Client( - auth_url="http://127.0.0.1:22/", - session=session, - timeout=2, - ) - self.assertEqual(2, client.session.timeout) diff --git a/designateclient/tests/test_v1/test_diagnostics.py b/designateclient/tests/test_v1/test_diagnostics.py deleted file mode 100644 index 09487f1..0000000 --- a/designateclient/tests/test_v1/test_diagnostics.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import diagnostics - - -class TestDiagnostics(test_v1.APIV1TestCase, test_v1.CrudMixin): - - @patch.object(diagnostics.DiagnosticsController, "ping") - def test_ping(self, ping): - args = mock.MagicMock() - args.service = "foo" - args.host = "host1" - self.client.diagnostics.ping(args.host, args.service) - self.client.diagnostics.ping.assert_called_with("host1", "foo") diff --git a/designateclient/tests/test_v1/test_domain.py b/designateclient/tests/test_v1/test_domain.py deleted file mode 100644 index fa69030..0000000 --- a/designateclient/tests/test_v1/test_domain.py +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 uuid - -from mock import patch - -from designateclient.tests import test_v1 -from designateclient import utils -from designateclient.v1 import domains -from designateclient import warlock - -Domain = warlock.model_factory(utils.load_schema('v1', 'domain')) - - -class TestDomain(test_v1.APIV1TestCase, test_v1.CrudMixin): - RESOURCE = 'domains' - - def new_ref(self, **kwargs): - ref = super(TestDomain, self).new_ref(**kwargs) - ref.setdefault("name", uuid.uuid4().hex) - ref.setdefault("email", "abc@example.com.") - ref.setdefault("ttl", 3600) - return ref - - def test_create(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": 60} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - response = self.client.domains.create(values["name"]) - self.assertEqual(ref['id'], response['id']) - - def test_create_with_description(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": 60, - "description": "fully qualified domain"} - - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - response = self.client.domains.create(values["name"]) - self.assertEqual(ref['id'], response['id']) - - def test_create_with_description_too_long(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": 60, - "description": "d" * 161} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.domains.create, - values["name"]) - - def test_create_with_zero_ttl(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": 0} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.domains.create, - values["name"]) - - def test_create_with_negative_ttl(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": -1} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.domains.create, - values["name"]) - - def test_create_with_no_ttl(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain1.com.", - "email": "nsadmin@example.org", - "ttl": ""} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.domains.create, - values["name"]) - - def test_create_with_name_too_long(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "domain" + "a" * 255 + ".com.", - "email": "nsadmin@example.org", - "ttl": 60} - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.domains.create, - values["name"]) - - def test_list(self): - items = [ - self.new_ref(email="abc@example.org", - id="89acac79-38e7-497d-807c-a011e1310438"), - self.new_ref(email="root@example.org", - id="89acac79-38e7-497d-807c-a011e1310435") - ] - - self.stub_url("GET", parts=[self.RESOURCE], json={"domains": items}) - - listed = self.client.domains.list() - self.assertList(items, listed) - self.assertQueryStringIs("") - - def test_get(self): - ref = self.new_ref(email="abc@example.org", - id="89acac79-38e7-497d-807c-a011e1310438") - - self.stub_entity("GET", entity=ref, id=ref["id"]) - - response = self.client.domains.get(ref["id"]) - self.assertEqual(ref, response) - - def test_delete(self): - ref = self.new_ref(email="abc@example.org", - id="89acac79-38e7-497d-807c-a011e1310438") - - self.stub_entity("DELETE", entity=ref, id=ref["id"]) - - self.client.domains.delete(ref["id"]) - self.assertRequestBodyIs(None) - - def test_update(self): - ref = self.new_ref(id="89acac79-38e7-497d-807c-a011e1310438") - - self.stub_entity("PUT", entity=ref, id=ref["id"]) - - values = ref.copy() - - self.client.domains.update(Domain(values)) - - @patch.object(domains.DomainsController, "list_domain_servers") - def test_list_domain_servers(self, domains_get): - domains_get.return_value = [{"id": "foo", "name": "ns1.example.com."}] - - ref = [{ - "id": "foo", - "name": "ns1.example.com.", - }] - parts = ["domains", "foo", "servers"] - self.stub_url("GET", parts=parts, json={"servers": ref}) - - response = self.client.domains.list_domain_servers("foo") - self.assertEqual(ref, response) diff --git a/designateclient/tests/test_v1/test_quotas.py b/designateclient/tests/test_v1/test_quotas.py deleted file mode 100644 index 4e73940..0000000 --- a/designateclient/tests/test_v1/test_quotas.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import quotas - - -class TestQuota(test_v1.APIV1TestCase, test_v1.CrudMixin): - - @patch.object(quotas.QuotasController, "get") - def test_get(self, quota_get): - QUOTA = {"domains": 10, - "recordset_records": 20, - "domain_records": 500, - "domain_recordsets": 500} - quota_get.return_value = QUOTA - response = self.client.quotas.get("foo") - self.assertEqual(QUOTA, response) - - @patch.object(quotas.QuotasController, "update") - def test_update(self, quota_update): - args = mock.MagicMock() - args.tenant_id = "1234" - args.value = {"domains": 1000} - self.client.quotas.update(args.tenant_id, args.value) - self.client.quotas.update.assert_called_with(args.tenant_id, - args.value) - - @patch.object(quotas.QuotasController, "reset") - def test_reset(self, quota_reset): - args = mock.MagicMock() - args.tenant_id = "1234" - self.client.quotas.reset(args.tenant_id) - self.client.quotas.reset.assert_called_with("1234") diff --git a/designateclient/tests/test_v1/test_records.py b/designateclient/tests/test_v1/test_records.py deleted file mode 100644 index b1b54b5..0000000 --- a/designateclient/tests/test_v1/test_records.py +++ /dev/null @@ -1,222 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 uuid - -from designateclient.tests import test_v1 -from designateclient import utils -from designateclient import warlock - - -Record = warlock.model_factory(utils.load_schema('v1', 'record')) - -DOMAIN = { - "id": str(uuid.uuid4()), - "name": "example.com." -} - - -class TestRecords(test_v1.APIV1TestCase, test_v1.CrudMixin): - RESOURCE = 'records' - - def new_ref(self, **kwargs): - ref = super(TestRecords, self).new_ref(**kwargs) - ref.setdefault("name", uuid.uuid4().hex) - ref.setdefault("type", "A") - ref.setdefault("data", "10.0.0.1") - return ref - - def test_create_record(self): - ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_AAAA_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778888", - type="AAAA", - data="2001:db8:0:1234:0:5678:9:12") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_MX_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778989", - type="MX", - data="mail.example.com.", - priority=10) - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_CNAME_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778890", - type="CNAME", - data="example.com.") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_TXT_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778889", - type="TXT", - data="This is a TXT record") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_SRV_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778888", - type="SRV", - data="0 5060 sip.example.com.", - priority=30) - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_NS_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677779999", - type="NS", - data="ns1.example.com.") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_PTR_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778891", - type="PTR", - data="www.example.com.") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_SPF_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778899", - type="SPF", - data="v=spf1 +mx a:colo.example.com/28 -all") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_create_SSHFP_record(self): - ref = self.new_ref(id="11112222-3333-4444-5555-666677778888", - type="SSHFP", - data="2 1 6c3c958af43d953f91f40e0d84157f4fe7b4a898") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("POST", parts=parts, json=ref) - - values = ref.copy() - del values["id"] - - self.client.records.create(DOMAIN['id'], Record(values)) - self.assertRequestBodyIs(json=values) - - def test_get(self): - ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_entity("GET", entity=ref, id=ref["id"], parts=parts) - - response = self.client.records.get(DOMAIN["id"], ref["id"]) - self.assertEqual(ref, response) - - def test_list(self): - items = [ - self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad"), - self.new_ref(id="11112222-3333-4444-5555-666677778888") - ] - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_url("GET", parts=parts, json={"records": items}) - - listed = self.client.records.list(DOMAIN["id"]) - self.assertList(items, listed) - self.assertQueryStringIs("") - - def test_update(self): - ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad", - type="A", - data="192.0.2.5") - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_entity("PUT", entity=ref, id=ref["id"], parts=parts) - - values = ref.copy() - del values["id"] - - self.client.records.update(DOMAIN["id"], Record(ref)) - - def test_delete(self): - ref = self.new_ref() - - parts = ["domains", DOMAIN["id"], self.RESOURCE] - self.stub_entity("DELETE", id=ref["id"], parts=parts) - - self.client.records.delete(DOMAIN["id"], ref["id"]) - self.assertRequestBodyIs(None) diff --git a/designateclient/tests/test_v1/test_reports.py b/designateclient/tests/test_v1/test_reports.py deleted file mode 100644 index 0edd154..0000000 --- a/designateclient/tests/test_v1/test_reports.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import reports - - -class TestReports(test_v1.APIV1TestCase, test_v1.CrudMixin): - - @patch.object(reports.ReportsController, "count_all") - def test_count_all(self, count_all): - self.client.reports.count_all() - self.client.reports.count_all.assert_called_with() - - @patch.object(reports.ReportsController, "count_domains") - def test_count_domain(self, count_domains): - self.client.reports.count_domains() - self.client.reports.count_domains.assert_called_once_with() - - @patch.object(reports.ReportsController, "count_tenants") - def test_count_tenants(self, count_tenants): - self.client.reports.count_tenants() - self.client.reports.count_tenants.assert_called_once_with() - - @patch.object(reports.ReportsController, "count_records") - def test_count_records(self, count_records): - self.client.reports.count_records() - self.client.reports.count_records.assert_called_once_with() - - @patch.object(reports.ReportsController, "tenants_all") - def test_tenants_all(self, tenants_all): - self.client.reports.tenants_all() - self.client.reports.tenants_all.assert_called_once_with() - - @patch.object(reports.ReportsController, "tenant_domains") - def test_tenant_domains(self, tenant_domains): - args = mock.MagicMock() - args.other_tenant_id = "uuid" - self.client.reports.tenant_domains(args.other_tenant_id) - self.client.reports.tenant_domains.assert_called_once_with("uuid") diff --git a/designateclient/tests/test_v1/test_servers.py b/designateclient/tests/test_v1/test_servers.py deleted file mode 100644 index b8fa653..0000000 --- a/designateclient/tests/test_v1/test_servers.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 uuid - -import mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import servers - - -class TestServers(test_v1.APIV1TestCase, test_v1.CrudMixin): - RESOURCE = 'servers' - - def new_ref(self, **kwargs): - ref = super(TestServers, self).new_ref(**kwargs) - ref.setdefault("name", uuid.uuid4().hex) - return ref - - def test_list(self): - items = [ - self.new_ref(name="ns1.example.org.", - id="89acac79-38e7-497d-807c-a011e1310438"), - self.new_ref(name="ns2.example.org.", - id="89acac79-38e7-497d-807c-a011e1310435") - ] - - self.stub_url("GET", parts=[self.RESOURCE], json={"servers": items}) - - listed = self.client.servers.list() - self.assertList(items, listed) - self.assertQueryStringIs("") - - def test_get(self): - ref = self.new_ref(name="ns1.example.org.", - id="89acac79-38e7-497d-807c-a011e1310438") - - self.stub_entity("GET", entity=ref, id=ref["id"]) - - response = self.client.servers.get(ref["id"]) - self.assertEqual(ref, response) - - def test_create(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "ns1.example.org."} - - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.client.servers.create({"name": "ns1.example.org."}) - self.assertRequestBodyIs(json=values) - - def test_create_with_name_too_long(self): - ref = {"id": "89acac79-38e7-497d-807c-a011e1310438", - "name": "ns1." + "foo" * 85 + ".org."} - - self.stub_url("POST", parts=[self.RESOURCE], json=ref) - - values = ref.copy() - del values["id"] - - self.assertRaises(ValueError, self.client.servers.create, - {"name": "ns1.example.org."}) - - @patch.object(servers.ServersController, "update") - def test_update(self, server_update): - ref = self.new_ref() - - self.stub_entity("PUT", entity=ref, id=ref["id"]) - - mock_server = mock.MagicMock() - self.client.servers.update(mock_server) - self.client.servers.update.assert_called_with(mock_server) - - def test_delete(self): - ref = self.new_ref() - - self.stub_entity("DELETE", id=ref["id"]) - - self.client.servers.delete(ref["id"]) - self.assertRequestBodyIs(None) diff --git a/designateclient/tests/test_v1/test_sync.py b/designateclient/tests/test_v1/test_sync.py deleted file mode 100644 index 88ad5d1..0000000 --- a/designateclient/tests/test_v1/test_sync.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import sync - - -class TestSync(test_v1.APIV1TestCase, test_v1.CrudMixin): - - @patch.object(sync.SyncController, "sync_all") - def test_sync_all(self, sync_all): - self.client.sync.sync_all() - self.client.sync.sync_all.assert_called_with() - - @patch.object(sync.SyncController, "sync_domain") - def test_sync_domain(self, sync_domain): - args = mock.MagicMock() - args.tenant_id = "1234" - self.client.sync.sync_domain(args.tenant_id) - self.client.sync.sync_domain.assert_called_with("1234") - - @patch.object(sync.SyncController, "sync_record") - def test_sync_record(self, sync_record): - args = mock.MagicMock() - args.tenant_id = "1234" - args.record_id = "uuid" - self.client.sync.sync_record(args.tenant_id, args.record_id) - self.client.sync.sync_record.assert_called_with("1234", "uuid") diff --git a/designateclient/tests/test_v1/test_touch.py b/designateclient/tests/test_v1/test_touch.py deleted file mode 100644 index 5c944b0..0000000 --- a/designateclient/tests/test_v1/test_touch.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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 mock -from mock import patch - -from designateclient.tests import test_v1 -from designateclient.v1 import touch - - -class TestTouch(test_v1.APIV1TestCase, test_v1.CrudMixin): - - @patch.object(touch.TouchController, "domain") - def test_domain(self, domain): - args = mock.MagicMock() - args.domain_id = "1234" - self.client.touch.domain(args.domain_id) - self.client.touch.domain.assert_called_with("1234") diff --git a/designateclient/utils.py b/designateclient/utils.py index d526fd8..cf1ddce 100644 --- a/designateclient/utils.py +++ b/designateclient/utils.py @@ -14,47 +14,18 @@ # License for the specific language governing permissions and limitations # under the License. -import os import uuid -from oslo_serialization import jsonutils - from debtcollector import removals from keystoneauth1 import adapter from keystoneauth1.identity import generic from keystoneauth1 import session as ks_session from keystoneauth1 import token_endpoint -import pkg_resources import six from designateclient import exceptions -def resource_string(*args, **kwargs): - if len(args) == 0: - raise ValueError() - - package = kwargs.pop('package', None) - - if not package: - package = 'designateclient' - - resource_path = os.path.join('resources', *args) - - if not pkg_resources.resource_exists(package, resource_path): - raise exceptions.ResourceNotFound('Could not find the requested ' - 'resource: %s' % resource_path) - - return pkg_resources.resource_string(package, resource_path) - - -def load_schema(version, name, package=None): - schema_string = resource_string('schemas', version, '%s.json' % name, - package=package) - - return jsonutils.loads(schema_string) - - def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): """Return a tuple containing the item properties. diff --git a/designateclient/v1/__init__.py b/designateclient/v1/__init__.py deleted file mode 100644 index 2474a4e..0000000 --- a/designateclient/v1/__init__.py +++ /dev/null @@ -1,161 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 debtcollector import removals -from stevedore import extension - -from designateclient import exceptions -from designateclient import utils -from designateclient import version - - -@removals.removed_class( - 'designateclient.v1.Client', - replacement='designateclient.v2.client.Client', - message='Designate v1 API is being retired, and the v1 Client class will ' - 'stop functioning. Please update code to the ' - 'designateclient.v2.client.Client class. The API is deprecated', - version='2.2.0', - removal_version='?', - stacklevel=3) -class Client(object): - """Client for the Designate v1 API""" - - def __init__(self, endpoint=None, username=None, user_id=None, - user_domain_id=None, user_domain_name=None, password=None, - tenant_name=None, tenant_id=None, domain_name=None, - domain_id=None, project_name=None, - project_id=None, project_domain_name=None, - project_domain_id=None, auth_url=None, token=None, - endpoint_type='publicURL', region_name=None, - service_type='dns', insecure=False, session=None, - cacert=None, all_tenants=None, edit_managed=None, - timeout=None): - """ - :param endpoint: Endpoint URL - :param token: A token instead of username / password - :param insecure: Allow "insecure" HTTPS requests - """ - - if endpoint: - endpoint = endpoint.rstrip('/') - if not endpoint.endswith('v1'): - endpoint = "%s/v1" % endpoint - - # Compatibility code to mimic the old behaviour of the client - if session is None: - session = utils.get_session( - auth_url=auth_url, - endpoint=endpoint, - domain_id=domain_id, - domain_name=domain_name, - project_id=project_id or tenant_id, - project_name=project_name or tenant_name, - project_domain_name=project_domain_name, - project_domain_id=project_domain_id, - username=username, - user_id=user_id, - password=password, - user_domain_id=user_domain_id, - user_domain_name=user_domain_name, - token=token, - insecure=insecure, - cacert=cacert, - ) - - # NOTE: all_tenants and edit_managed are pulled from the session for - # backwards compat reasons, do not pull additional modifiers from - # here. Once removed, the kwargs above should default to False. - if all_tenants is None: - self.all_tenants = getattr(session, 'all_tenants', False) - else: - self.all_tenants = all_tenants - - if edit_managed is None: - self.edit_managed = getattr(session, 'edit_managed', False) - else: - self.edit_managed = edit_managed - - # Since we have to behave nicely like a legacy client/bindings we use - # an adapter around the session to not modify it's state. - interface = endpoint_type.rstrip('URL') - - self.session = utils.AdapterWithTimeout( - session, - auth=session.auth, - endpoint_override=endpoint, - region_name=region_name, - service_type=service_type, - interface=interface, - user_agent='python-designateclient-%s' % version.version_info, - version='1', - timeout=timeout, - ) - - def _load_controller(ext): - controller = ext.plugin(client=self) - setattr(self, ext.name, controller) - - # Load all controllers - mgr = extension.ExtensionManager('designateclient.v1.controllers') - mgr.map(_load_controller) - - def wrap_api_call(self, func, *args, **kw): - """ - Wrap a self.<rest function> with exception handling - - :param func: The function to wrap - """ - kw['raise_exc'] = False - kw.setdefault('headers', {}) - kw['headers'].setdefault('Content-Type', 'application/json') - if self.all_tenants: - kw['headers'].update({'X-Auth-All-Projects': 'true'}) - if self.edit_managed: - kw['headers'].update({'X-Designate-Edit-Managed-Records': 'true'}) - - # Trigger the request - response = func(*args, **kw) - - # Decode is response, if possible - try: - response_payload = response.json() - except ValueError: - response_payload = {} - - if response.status_code == 400: - raise exceptions.BadRequest(**response_payload) - elif response.status_code in (401, 403, 413): - raise exceptions.Forbidden(**response_payload) - elif response.status_code == 404: - raise exceptions.NotFound(**response_payload) - elif response.status_code == 409: - raise exceptions.Conflict(**response_payload) - elif response.status_code >= 500: - raise exceptions.Unknown(**response_payload) - else: - return response - - def get(self, path, **kw): - return self.wrap_api_call(self.session.get, path, **kw) - - def post(self, path, **kw): - return self.wrap_api_call(self.session.post, path, **kw) - - def put(self, path, **kw): - return self.wrap_api_call(self.session.put, path, **kw) - - def delete(self, path, **kw): - return self.wrap_api_call(self.session.delete, path, **kw) diff --git a/designateclient/v1/diagnostics.py b/designateclient/v1/diagnostics.py deleted file mode 100644 index d2e5153..0000000 --- a/designateclient/v1/diagnostics.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 designateclient import client - - -class DiagnosticsController(client.Controller): - def ping(self, service, host): - """ - Ping a service on a given host - """ - response = self.client.get('/diagnostics/ping/%s/%s' % - (service, host)) - - return response.json() diff --git a/designateclient/v1/domains.py b/designateclient/v1/domains.py deleted file mode 100644 index 1430bbf..0000000 --- a/designateclient/v1/domains.py +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 oslo_serialization import jsonutils - -from designateclient import client -from designateclient import utils -from designateclient import warlock - - -Domain = warlock.model_factory(utils.load_schema('v1', 'domain')) -Server = warlock.model_factory(utils.load_schema('v1', 'server')) - - -class DomainsController(client.CrudController): - def list(self): - """ - Retrieve a list of domains - - :returns: A list of :class:`Domain` - """ - response = self.client.get('/domains') - - return [Domain(i) for i in response.json()['domains']] - - def get(self, domain_id): - """ - Retrieve a domain - - :param domain_id: Domain Identifier - :returns: :class:`Domain` - """ - response = self.client.get('/domains/%s' % domain_id) - - return Domain(response.json()) - - def create(self, domain): - """ - Create a domain - - :param domain: A :class:`Domain` to create - :returns: :class:`Domain` - """ - response = self.client.post('/domains', data=jsonutils.dumps(domain)) - - return Domain(response.json()) - - def update(self, domain): - """ - Update a domain - - :param domain: A :class:`Domain` to update - :returns: :class:`Domain` - """ - response = self.client.put('/domains/%s' % domain.id, - data=jsonutils.dumps(domain.changes)) - - return Domain(response.json()) - - def delete(self, domain): - """ - Delete a domain - - :param domain: A :class:`Domain`, or Domain Identifier to delete - """ - if isinstance(domain, Domain): - self.client.delete('/domains/%s' % domain.id) - else: - self.client.delete('/domains/%s' % domain) - - def list_domain_servers(self, domain_id): - """ - Retrieve the list of nameservers for a domain - - :param domain_id: Domain Identifier - :returns: A list of :class:`Server` - """ - response = self.client.get('/domains/%s/servers' % domain_id) - - return [Server(i) for i in response.json()['servers']] diff --git a/designateclient/v1/quotas.py b/designateclient/v1/quotas.py deleted file mode 100644 index 432edf2..0000000 --- a/designateclient/v1/quotas.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2014 Hewlett-Packard Development Company, L.P. -# -# Author: Endre Karlson <endre.karlson@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. - -from oslo_serialization import jsonutils - -from designateclient import client - - -class QuotasController(client.Controller): - def get(self, tenant_id): - """ - Ping a service on a given host - """ - response = self.client.get('/quotas/%s' % tenant_id) - - return response.json() - - def update(self, tenant_id, values): - response = self.client.put('/quotas/%s' % tenant_id, - data=jsonutils.dumps(values)) - return response.json() - - def reset(self, tenant_id): - response = self.client.delete('/quotas/%s' % tenant_id) - - return response diff --git a/designateclient/v1/records.py b/designateclient/v1/records.py deleted file mode 100644 index c239e12..0000000 --- a/designateclient/v1/records.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 oslo_serialization import jsonutils - -from designateclient import client -from designateclient import utils -from designateclient.v1.domains import Domain -from designateclient import warlock - - -Record = warlock.model_factory(utils.load_schema('v1', 'record')) - - -class RecordsController(client.CrudController): - def list(self, domain): - """ - Retrieve a list of records - - :param domain: :class:`Domain` or Domain Identifier - :returns: A list of :class:`Record` - """ - domain_id = domain.id if isinstance(domain, Domain) else domain - - response = self.client.get('/domains/%(domain_id)s/records' % { - 'domain_id': domain_id - }) - - return [Record(i) for i in response.json()['records']] - - def get(self, domain, record_id): - """ - Retrieve a record - - :param domain: :class:`Domain` or Domain Identifier - :param record_id: Record Identifier - :returns: :class:`Record` - """ - domain_id = domain.id if isinstance(domain, Domain) else domain - - uri = '/domains/%(domain_id)s/records/%(record_id)s' % { - 'domain_id': domain_id, - 'record_id': record_id - } - - response = self.client.get(uri) - - return Record(response.json()) - - def create(self, domain, record): - """ - Create a record - - :param domain: :class:`Domain` or Domain Identifier - :param record: A :class:`Record` to create - :returns: :class:`Record` - """ - domain_id = domain.id if isinstance(domain, Domain) else domain - - uri = '/domains/%(domain_id)s/records' % { - 'domain_id': domain_id - } - - response = self.client.post(uri, data=jsonutils.dumps(record)) - - return Record(response.json()) - - def update(self, domain, record): - """ - Update a record - - :param domain: :class:`Domain` or Domain Identifier - :param record: A :class:`Record` to update - :returns: :class:`Record` - """ - domain_id = domain.id if isinstance(domain, Domain) else domain - - uri = '/domains/%(domain_id)s/records/%(record_id)s' % { - 'domain_id': domain_id, - 'record_id': record.id - } - - response = self.client.put(uri, data=jsonutils.dumps(record.changes)) - - return Record(response.json()) - - def delete(self, domain, record): - """ - Delete a record - - :param domain: :class:`Domain` or Domain Identifier - :param record: A :class:`Record`, or Record Identifier to delete - """ - domain_id = domain.id if isinstance(domain, Domain) else domain - record_id = record.id if isinstance(record, Record) else record - - uri = '/domains/%(domain_id)s/records/%(record_id)s' % { - 'domain_id': domain_id, - 'record_id': record_id - } - - self.client.delete(uri) diff --git a/designateclient/v1/reports.py b/designateclient/v1/reports.py deleted file mode 100644 index 4a32c6c..0000000 --- a/designateclient/v1/reports.py +++ /dev/null @@ -1,67 +0,0 @@ -# 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 designateclient import client - - -class ReportsController(client.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']] diff --git a/designateclient/v1/servers.py b/designateclient/v1/servers.py deleted file mode 100644 index 34dcca6..0000000 --- a/designateclient/v1/servers.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 oslo_serialization import jsonutils - -from designateclient import client -from designateclient import utils -from designateclient import warlock - - -Server = warlock.model_factory(utils.load_schema('v1', 'server')) - - -class ServersController(client.CrudController): - def list(self): - """ - Retrieve a list of servers - - :returns: A list of :class:`Server` - """ - response = self.client.get('/servers') - - return [Server(i) for i in response.json()['servers']] - - def get(self, server_id): - """ - Retrieve a server - - :param server_id: Server Identifier - :returns: :class:`Server` - """ - response = self.client.get('/servers/%s' % server_id) - - return Server(response.json()) - - def create(self, server): - """ - Create a server - - :param server: A :class:`Server` to create - :returns: :class:`Server` - """ - response = self.client.post('/servers', data=jsonutils.dumps(server)) - - return Server(response.json()) - - def update(self, server): - """ - Update a server - - :param server: A :class:`Server` to update - :returns: :class:`Server` - """ - response = self.client.put('/servers/%s' % server.id, - data=jsonutils.dumps(server.changes)) - - return Server(response.json()) - - def delete(self, server): - """ - Delete a server - - :param server: A :class:`Server`, or Server Identifier to delete - """ - if isinstance(server, Server): - self.client.delete('/servers/%s' % server.id) - else: - self.client.delete('/servers/%s' % server) diff --git a/designateclient/v1/sync.py b/designateclient/v1/sync.py deleted file mode 100644 index f86e642..0000000 --- a/designateclient/v1/sync.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2012 Managed I.T. -# -# Author: Kiall Mac Innes <kiall@managedit.ie> -# -# 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 designateclient import client - - -class SyncController(client.Controller): - def sync_all(self): - """ - Sync Everything - """ - self.client.post('/domains/sync') - - def sync_domain(self, domain_id): - """ - Sync Single Domain - """ - self.client.post('/domains/%s/sync' % domain_id) - - def sync_record(self, domain_id, record_id): - """ - Sync Single Record - """ - self.client.post('/domains/%s/records/%s/sync' % - (domain_id, record_id)) diff --git a/designateclient/v1/touch.py b/designateclient/v1/touch.py deleted file mode 100644 index bbbdbd2..0000000 --- a/designateclient/v1/touch.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2013 Hewlett-Packard Development Company, L.P. -# -# 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. -from designateclient import client - - -class TouchController(client.Controller): - def domain(self, domain_id): - """ - Touch a single Domain - """ - self.client.post('/domains/%s/touch' % domain_id) |