diff options
author | Rudolf Vriend <rudolf.vriend@sap.com> | 2017-07-07 14:00:17 +0200 |
---|---|---|
committer | Rudolf Vriend <rudolf.vriend@sap.com> | 2017-07-07 14:16:30 +0200 |
commit | b741282eaff277977507379bbd0de3454eb66232 (patch) | |
tree | fdfbebda4ec64f19c390689c517b47ee06f63446 /designateclient/v2 | |
parent | 3bb401758c00a9d66383484c60933421d9a21d63 (diff) | |
download | python-designateclient-b741282eaff277977507379bbd0de3454eb66232.tar.gz |
Add tsig key support to python-designateclient
This fix adds support for the designate tsig keys api to
python-designateclient.
It will add tsigkey related crud commands to the openstackclient.
Change-Id: I84336c3aca85ca62771fd2115481eda32ee980d2
Closes-Bug: #1702506
Diffstat (limited to 'designateclient/v2')
-rw-r--r-- | designateclient/v2/cli/tsigkeys.py | 170 | ||||
-rw-r--r-- | designateclient/v2/client.py | 2 | ||||
-rw-r--r-- | designateclient/v2/tsigkeys.py | 50 |
3 files changed, 222 insertions, 0 deletions
diff --git a/designateclient/v2/cli/tsigkeys.py b/designateclient/v2/cli/tsigkeys.py new file mode 100644 index 0000000..b1d42ad --- /dev/null +++ b/designateclient/v2/cli/tsigkeys.py @@ -0,0 +1,170 @@ +# Copyright 2017 SAP SE +# +# Author: Rudolf Vriend <rudolf.vriend@sap.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 osc_lib.command import command +import six + +from designateclient import utils +from designateclient.v2.cli import common +from designateclient.v2.utils import get_all + +LOG = logging.getLogger(__name__) + + +def _format_tsigkey(tsigkey): + # Remove unneeded fields for display output formatting + tsigkey.pop('links', None) + + +class ListTSIGKeysCommand(command.Lister): + """List tsigkeys""" + + columns = ['id', 'name', 'algorithm', 'secret', 'scope', 'resource_id'] + + def get_parser(self, prog_name): + parser = super(ListTSIGKeysCommand, self).get_parser(prog_name) + + parser.add_argument('--name', help="TSIGKey NAME", required=False) + parser.add_argument('--algorithm', help="TSIGKey algorithm", + required=False) + parser.add_argument('--scope', help="TSIGKey scope", required=False) + + common.add_all_common_options(parser) + + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.dns + common.set_all_common_headers(client, parsed_args) + + criterion = {} + if parsed_args.name is not None: + criterion["name"] = parsed_args.name + if parsed_args.algorithm is not None: + criterion["algorithm"] = parsed_args.algorithm + if parsed_args.scope is not None: + criterion["scope"] = parsed_args.scope + + data = get_all(client.tsigkeys.list, criterion) + + cols = self.columns + return cols, (utils.get_item_properties(s, cols) for s in data) + + +class ShowTSIGKeyCommand(command.ShowOne): + """Show tsigkey details""" + + def get_parser(self, prog_name): + parser = super(ShowTSIGKeyCommand, self).get_parser(prog_name) + + parser.add_argument('id', help="TSIGKey ID") + + common.add_all_common_options(parser) + + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.dns + common.set_all_common_headers(client, parsed_args) + data = client.tsigkeys.get(parsed_args.id) + _format_tsigkey(data) + return six.moves.zip(*sorted(six.iteritems(data))) + + +class CreateTSIGKeyCommand(command.ShowOne): + """Create new tsigkey""" + + def get_parser(self, prog_name): + parser = super(CreateTSIGKeyCommand, self).get_parser(prog_name) + + parser.add_argument('--name', help="TSIGKey Name", required=True) + parser.add_argument('--algorithm', help="TSIGKey algorithm", + required=True) + parser.add_argument('--secret', help="TSIGKey secret", required=True) + parser.add_argument('--scope', help="TSIGKey scope", required=True) + parser.add_argument('--resource-id', help="TSIGKey resource_id", + required=True) + + common.add_all_common_options(parser) + + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.dns + common.set_all_common_headers(client, parsed_args) + data = client.tsigkeys.create(parsed_args.name, parsed_args.algorithm, + parsed_args.secret, parsed_args.scope, + parsed_args.resource_id) + _format_tsigkey(data) + return six.moves.zip(*sorted(six.iteritems(data))) + + +class SetTSIGKeyCommand(command.ShowOne): + """Set tsigkey properties""" + + def get_parser(self, prog_name): + parser = super(SetTSIGKeyCommand, self).get_parser(prog_name) + + parser.add_argument('id', help="TSIGKey ID") + parser.add_argument('--name', help="TSIGKey Name") + parser.add_argument('--algorithm', help="TSIGKey algorithm") + parser.add_argument('--secret', help="TSIGKey secret") + parser.add_argument('--scope', help="TSIGKey scope") + + common.add_all_common_options(parser) + + return parser + + def take_action(self, parsed_args): + data = {} + + if parsed_args.name: + data['name'] = parsed_args.name + if parsed_args.algorithm: + data['algorithm'] = parsed_args.algorithm + if parsed_args.secret: + data['secret'] = parsed_args.secret + if parsed_args.scope: + data['scope'] = parsed_args.scope + + client = self.app.client_manager.dns + common.set_all_common_headers(client, parsed_args) + + data = client.tsigkeys.update(parsed_args.id, data) + _format_tsigkey(data) + return six.moves.zip(*sorted(six.iteritems(data))) + + +class DeleteTSIGKeyCommand(command.Command): + """Delete tsigkey""" + + def get_parser(self, prog_name): + parser = super(DeleteTSIGKeyCommand, self).get_parser(prog_name) + + parser.add_argument('id', help="TSIGKey ID") + + common.add_all_common_options(parser) + + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.dns + common.set_all_common_headers(client, parsed_args) + client.tsigkeys.delete(parsed_args.id) + + LOG.info('TSIGKey %s was deleted', parsed_args.id) diff --git a/designateclient/v2/client.py b/designateclient/v2/client.py index d5dda03..b9a42af 100644 --- a/designateclient/v2/client.py +++ b/designateclient/v2/client.py @@ -25,6 +25,7 @@ from designateclient.v2.recordsets import RecordSetController from designateclient.v2.reverse import FloatingIPController from designateclient.v2.service_statuses import ServiceStatusesController from designateclient.v2.tlds import TLDController +from designateclient.v2.tsigkeys import TSIGKeysController from designateclient.v2.zones import ZoneController from designateclient.v2.zones import ZoneExportsController from designateclient.v2.zones import ZoneImportsController @@ -138,3 +139,4 @@ class Client(object): self.zone_imports = ZoneImportsController(self) self.pools = PoolController(self) self.quotas = QuotasController(self) + self.tsigkeys = TSIGKeysController(self) diff --git a/designateclient/v2/tsigkeys.py b/designateclient/v2/tsigkeys.py new file mode 100644 index 0000000..988700f --- /dev/null +++ b/designateclient/v2/tsigkeys.py @@ -0,0 +1,50 @@ +# Copyright 2017 SAP SE +# +# Author: Rudolf Vriend <rudolf.vriend@sap.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.v2.base import V2Controller +from designateclient.v2 import utils as v2_utils + + +class TSIGKeysController(V2Controller): + def create(self, name, algorithm, secret, scope, resource_id): + data = { + 'name': name, + 'algorithm': algorithm, + 'secret': secret, + 'scope': scope, + 'resource_id': resource_id + } + + return self._post('/tsigkeys', data=data) + + def list(self, criterion=None, marker=None, limit=None): + url = self.build_url('/tsigkeys', criterion, marker, limit) + + return self._get(url, response_key='tsigkeys') + + def get(self, tsigkey): + tsigkey = v2_utils.resolve_by_name(self.list, tsigkey) + + return self._get('/tsigkeys/%s' % tsigkey) + + def update(self, tsigkey, values): + tsigkey = v2_utils.resolve_by_name(self.list, tsigkey) + + return self._patch('/tsigkeys/%s' % tsigkey, data=values) + + def delete(self, tsigkey): + tsigkey = v2_utils.resolve_by_name(self.list, tsigkey) + + return self._delete('/tsigkeys/%s' % tsigkey) |