Merge "Add global flags to cli"
This commit is contained in:
commit
fd118972b0
@ -33,6 +33,7 @@ def make_client(instance):
|
||||
API_NAME, instance._api_version[API_NAME],
|
||||
API_VERSIONS)
|
||||
kwargs = oscutils.build_kwargs_dict('endpoint_type', instance._interface)
|
||||
|
||||
return cls(session=instance.session,
|
||||
region_name=instance._region_name, **kwargs)
|
||||
|
||||
|
@ -22,8 +22,10 @@ from cliff import show
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2.utils import get_all
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -37,8 +39,16 @@ class ListBlacklistsCommand(lister.Lister):
|
||||
|
||||
columns = ['id', 'pattern', 'description']
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListBlacklistsCommand, self).get_parser(prog_name)
|
||||
|
||||
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)
|
||||
|
||||
cols = self.columns
|
||||
data = get_all(client.blacklists.list)
|
||||
@ -53,10 +63,13 @@ class ShowBlacklistCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Blacklist 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.blacklists.get(parsed_args.id)
|
||||
_format_blacklist(data)
|
||||
return six.moves.zip(*sorted(six.iteritems(data)))
|
||||
@ -72,10 +85,13 @@ class CreateBlacklistCommand(show.ShowOne):
|
||||
required=True)
|
||||
parser.add_argument('--description', help="Description")
|
||||
|
||||
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.blacklists.create(
|
||||
parsed_args.pattern, parsed_args.description)
|
||||
@ -97,6 +113,8 @@ class SetBlacklistCommand(show.ShowOne):
|
||||
description_group.add_argument('--description', help="Description")
|
||||
description_group.add_argument('--no-description', action='store_true')
|
||||
|
||||
common.add_all_common_options(parser)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -111,6 +129,7 @@ class SetBlacklistCommand(show.ShowOne):
|
||||
data['description'] = parsed_args.description
|
||||
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
updated = client.blacklists.update(parsed_args.id, data)
|
||||
|
||||
@ -126,10 +145,13 @@ class DeleteBlacklistCommand(command.Command):
|
||||
|
||||
parser.add_argument('id', help="Blacklist 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.blacklists.delete(parsed_args.id)
|
||||
|
||||
LOG.info('Blacklist %s was deleted', parsed_args.id)
|
||||
|
74
designateclient/v2/cli/common.py
Normal file
74
designateclient/v2/cli/common.py
Normal file
@ -0,0 +1,74 @@
|
||||
# Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
||||
#
|
||||
# Author: Graham Hayes <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.
|
||||
|
||||
|
||||
def add_all_projects_option(parser):
|
||||
parser.add_argument(
|
||||
'--all-projects',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Show results from all projects. Default: False'
|
||||
)
|
||||
|
||||
|
||||
def add_edit_managed_option(parser):
|
||||
parser.add_argument(
|
||||
'--edit-managed',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Edit resources marked as managed. Default: False'
|
||||
)
|
||||
|
||||
|
||||
def add_sudo_project_id_option(parser):
|
||||
parser.add_argument(
|
||||
'--sudo-project-id',
|
||||
default=None,
|
||||
help='Project ID to impersonate for this command. Default: None'
|
||||
)
|
||||
|
||||
|
||||
def add_all_common_options(parser):
|
||||
add_all_projects_option(parser)
|
||||
add_edit_managed_option(parser)
|
||||
add_sudo_project_id_option(parser)
|
||||
|
||||
|
||||
def set_all_projects(client, value):
|
||||
client.session.all_projects = value
|
||||
|
||||
|
||||
def set_sudo_project_id(client, value):
|
||||
client.session.sudo_project_id = value
|
||||
|
||||
|
||||
def set_edit_managed(client, value):
|
||||
client.session.edit_managed = value
|
||||
|
||||
|
||||
def set_all_common_headers(client, parsed_args):
|
||||
|
||||
if parsed_args.all_projects is not None and \
|
||||
isinstance(parsed_args.all_projects, bool):
|
||||
set_all_projects(client, parsed_args.all_projects)
|
||||
|
||||
if parsed_args.edit_managed is not None and \
|
||||
isinstance(parsed_args.edit_managed, bool):
|
||||
set_edit_managed(client, parsed_args.edit_managed)
|
||||
|
||||
if parsed_args.sudo_project_id is not None and \
|
||||
isinstance(parsed_args.sudo_project_id, str):
|
||||
set_sudo_project_id(client, parsed_args.sudo_project_id)
|
@ -21,8 +21,10 @@ from cliff import show
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2.utils import get_all
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -33,6 +35,14 @@ def _format_recordset(recordset):
|
||||
return recordset
|
||||
|
||||
|
||||
def _has_project_id(data):
|
||||
if len(data) < 1:
|
||||
return False
|
||||
if 'project_id' in data[0]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class ListRecordSetsCommand(lister.Lister):
|
||||
"""List recordsets"""
|
||||
|
||||
@ -57,10 +67,13 @@ class ListRecordSetsCommand(lister.Lister):
|
||||
parser.add_argument('zone_id', help="Zone ID. To list all"
|
||||
" recordsets specify 'all'")
|
||||
|
||||
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.type is not None:
|
||||
@ -94,6 +107,9 @@ class ListRecordSetsCommand(lister.Lister):
|
||||
data = get_all(client.recordsets.list, args=[parsed_args.zone_id],
|
||||
criterion=criterion)
|
||||
|
||||
if client.session.all_projects and _has_project_id(data):
|
||||
cols.insert(1, 'project_id')
|
||||
|
||||
for i, rs in enumerate(data):
|
||||
data[i] = _format_recordset(rs)
|
||||
|
||||
@ -109,10 +125,13 @@ class ShowRecordSetCommand(show.ShowOne):
|
||||
parser.add_argument('zone_id', help="Zone ID")
|
||||
parser.add_argument('id', help="RecordSet 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.recordsets.get(parsed_args.zone_id, parsed_args.id)
|
||||
|
||||
_format_recordset(data)
|
||||
@ -133,10 +152,13 @@ class CreateRecordSetCommand(show.ShowOne):
|
||||
parser.add_argument('--ttl', type=int, help="Time To Live (Seconds)")
|
||||
parser.add_argument('--description', help="Description")
|
||||
|
||||
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.recordsets.create(
|
||||
parsed_args.zone_id,
|
||||
@ -168,6 +190,8 @@ class SetRecordSetCommand(show.ShowOne):
|
||||
ttl_group.add_argument('--ttl', type=int, help="TTL")
|
||||
ttl_group.add_argument('--no-ttl', action='store_true')
|
||||
|
||||
common.add_all_common_options(parser)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -187,6 +211,7 @@ class SetRecordSetCommand(show.ShowOne):
|
||||
data['records'] = parsed_args.records
|
||||
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
updated = client.recordsets.update(
|
||||
parsed_args.zone_id,
|
||||
@ -207,10 +232,13 @@ class DeleteRecordSetCommand(show.ShowOne):
|
||||
parser.add_argument('zone_id', help="Zone ID")
|
||||
parser.add_argument('id', help="RecordSet 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.recordsets.delete(parsed_args.zone_id, parsed_args.id)
|
||||
|
||||
LOG.info('RecordSet %s was deleted', parsed_args.id)
|
||||
|
@ -22,8 +22,10 @@ from cliff import show
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2.utils import get_all
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -39,6 +41,7 @@ class ListFloatingIPCommand(lister.Lister):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
cols = self.columns
|
||||
data = get_all(client.floatingips.list)
|
||||
@ -53,10 +56,13 @@ class ShowFloatingIPCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('floatingip_id', help="Floating IP 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.floatingips.get(parsed_args.floatingip_id)
|
||||
_format_floatingip(data)
|
||||
return six.moves.zip(*sorted(six.iteritems(data)))
|
||||
@ -79,6 +85,8 @@ class SetFloatingIPCommand(show.ShowOne):
|
||||
ttl_group.add_argument('--ttl', type=int, help="TTL")
|
||||
ttl_group.add_argument('--no-ttl', action='store_true')
|
||||
|
||||
common.add_all_common_options(parser)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -95,6 +103,7 @@ class SetFloatingIPCommand(show.ShowOne):
|
||||
data['ttl'] = parsed_args.ttl
|
||||
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
fip = client.floatingips.set(
|
||||
parsed_args.floatingip_id,
|
||||
@ -114,9 +123,12 @@ class UnsetFloatingIPCommand(command.Command):
|
||||
|
||||
parser.add_argument('floatingip_id', help="Floating IP 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.floatingips.unset(parsed_args.floatingip_id)
|
||||
LOG.info('FloatingIP PTR %s was unset', parsed_args.floatingip_id)
|
||||
|
@ -21,8 +21,10 @@ from cliff import show
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2 import utils as v2_utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -47,10 +49,13 @@ class ListServiceStatusesCommand(lister.Lister):
|
||||
parser.add_argument("--service_name", help="Service Name",
|
||||
required=False)
|
||||
parser.add_argument("--status", help="Status", 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)
|
||||
|
||||
cols = self.columns
|
||||
|
||||
@ -77,10 +82,13 @@ class ShowServiceStatusCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Service Status 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.service_statuses.get(parsed_args.id)
|
||||
|
||||
_format_status(data)
|
||||
|
@ -22,8 +22,10 @@ from cliff import show
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2.utils import get_all
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -44,10 +46,13 @@ class ListTLDsCommand(lister.Lister):
|
||||
|
||||
parser.add_argument('--description', help="TLD Description")
|
||||
|
||||
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 = get_all(client.tlds.list)
|
||||
|
||||
@ -63,10 +68,13 @@ class ShowTLDCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="TLD 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.tlds.get(parsed_args.id)
|
||||
_format_tld(data)
|
||||
return six.moves.zip(*sorted(six.iteritems(data)))
|
||||
@ -81,10 +89,13 @@ class CreateTLDCommand(show.ShowOne):
|
||||
parser.add_argument('--name', help="TLD Name", required=True)
|
||||
parser.add_argument('--description', help="Description")
|
||||
|
||||
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.tlds.create(parsed_args.name, parsed_args.description)
|
||||
_format_tld(data)
|
||||
return six.moves.zip(*sorted(six.iteritems(data)))
|
||||
@ -102,6 +113,8 @@ class SetTLDCommand(show.ShowOne):
|
||||
description_group.add_argument('--description', help="Description")
|
||||
description_group.add_argument('--no-description', action='store_true')
|
||||
|
||||
common.add_all_common_options(parser)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -116,6 +129,7 @@ class SetTLDCommand(show.ShowOne):
|
||||
data['description'] = parsed_args.description
|
||||
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
data = client.tlds.update(parsed_args.id, data)
|
||||
_format_tld(data)
|
||||
@ -130,10 +144,13 @@ class DeleteTLDCommand(command.Command):
|
||||
|
||||
parser.add_argument('id', help="TLD 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.tlds.delete(parsed_args.id)
|
||||
|
||||
LOG.info('TLD %s was deleted', parsed_args.id)
|
||||
|
@ -23,8 +23,10 @@ from osc_lib import exceptions as osc_exc
|
||||
import six
|
||||
|
||||
from designateclient import utils
|
||||
from designateclient.v2.cli import common
|
||||
from designateclient.v2.utils import get_all
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -58,10 +60,15 @@ class ListZonesCommand(lister.Lister):
|
||||
required=False)
|
||||
parser.add_argument('--status', help="Zone Status", 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)
|
||||
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
criterion = {}
|
||||
if parsed_args.type is not None:
|
||||
@ -85,6 +92,10 @@ class ListZonesCommand(lister.Lister):
|
||||
data = get_all(client.zones.list, criterion)
|
||||
|
||||
cols = self.columns
|
||||
|
||||
if client.session.all_projects:
|
||||
cols.insert(1, 'project_id')
|
||||
|
||||
return cols, (utils.get_item_properties(s, cols) for s in data)
|
||||
|
||||
|
||||
@ -96,10 +107,13 @@ class ShowZoneCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Zone 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.zones.get(parsed_args.id)
|
||||
|
||||
@ -120,10 +134,13 @@ class CreateZoneCommand(show.ShowOne):
|
||||
parser.add_argument('--description', help="Description")
|
||||
parser.add_argument('--masters', help="Zone Masters", nargs='+')
|
||||
|
||||
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)
|
||||
|
||||
payload = {}
|
||||
|
||||
@ -170,10 +187,13 @@ class SetZoneCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('--masters', help="Zone Masters", nargs='+')
|
||||
|
||||
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 = {}
|
||||
|
||||
@ -205,10 +225,14 @@ class DeleteZoneCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Zone 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.zones.delete(parsed_args.id)
|
||||
LOG.info('Zone %s was deleted', parsed_args.id)
|
||||
|
||||
@ -223,10 +247,13 @@ class AbandonZoneCommand(command.Command):
|
||||
|
||||
parser.add_argument('id', help="Zone 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.zones.abandon(parsed_args.id)
|
||||
|
||||
@ -241,10 +268,13 @@ class AXFRZoneCommand(command.Command):
|
||||
|
||||
parser.add_argument('id', help="Zone 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.zones.axfr(parsed_args.id)
|
||||
|
||||
@ -265,10 +295,13 @@ class CreateTransferRequestCommand(show.ShowOne):
|
||||
help="Target Project ID to transfer to.")
|
||||
parser.add_argument('--description', help="Description")
|
||||
|
||||
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.zone_transfers.create_request(
|
||||
parsed_args.zone_id, parsed_args.target_project_id,
|
||||
@ -286,10 +319,13 @@ class ListTransferRequestsCommand(lister.Lister):
|
||||
parser = super(ListTransferRequestsCommand, self).get_parser(
|
||||
prog_name)
|
||||
|
||||
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.zone_transfers.list_requests()
|
||||
|
||||
@ -305,10 +341,13 @@ class ShowTransferRequestCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Zone Tranfer Request 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.zone_transfers.get_request(parsed_args.id)
|
||||
|
||||
@ -326,10 +365,13 @@ class SetTransferRequestCommand(show.ShowOne):
|
||||
description_group.add_argument('--description', help="Description")
|
||||
description_group.add_argument('--no-description', action='store_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 = {}
|
||||
|
||||
@ -350,10 +392,13 @@ class DeleteTransferRequestCommand(command.Command):
|
||||
|
||||
parser.add_argument('id', help="Zone Transfer Request 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.zone_transfers.delete_request(parsed_args.id)
|
||||
|
||||
@ -372,10 +417,13 @@ class AcceptTransferRequestCommand(show.ShowOne):
|
||||
parser.add_argument('--key', help="Transfer Key", type=str,
|
||||
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.zone_transfers.accept_request(
|
||||
parsed_args.transfer_id, parsed_args.key)
|
||||
@ -392,10 +440,13 @@ class ListTransferAcceptsCommand(lister.Lister):
|
||||
parser = super(ListTransferAcceptsCommand, self).get_parser(
|
||||
prog_name)
|
||||
|
||||
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.zone_transfers.list_requests()
|
||||
|
||||
@ -411,10 +462,13 @@ class ShowTransferAcceptCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('id', help="Zone Tranfer Accept 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.zone_transfers.get_accept(parsed_args.id)
|
||||
|
||||
@ -428,12 +482,15 @@ class ExportZoneCommand(show.ShowOne):
|
||||
parser = super(ExportZoneCommand, self).get_parser(
|
||||
prog_name)
|
||||
|
||||
common.add_all_common_options(parser)
|
||||
|
||||
parser.add_argument('zone_id', help="Zone ID", type=str)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.dns
|
||||
common.set_all_common_headers(client, parsed_args)
|
||||
|
||||
data = client.zone_exports.create(parsed_args.zone_id)
|
||||
_format_zone_export_record(data)
|
||||
@ -457,10 +514,13 @@ class ListZoneExportsCommand(lister.Lister):
|
||||
parser = super(ListZoneExportsCommand, self).get_parser(
|
||||
prog_name)
|
||||
|
||||
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.zone_exports.list()
|
||||
|
||||
@ -478,10 +538,13 @@ class ShowZoneExportCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('zone_export_id', help="Zone Export ID", type=str)
|
||||
|
||||
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.zone_exports.get_export_record(
|
||||
parsed_args.zone_export_id)
|
||||
@ -499,10 +562,13 @@ class DeleteZoneExportCommand(command.Command):
|
||||
|
||||
parser.add_argument('zone_export_id', help="Zone Export ID", type=str)
|
||||
|
||||
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.zone_exports.delete(parsed_args.zone_export_id)
|
||||
|
||||
@ -518,10 +584,13 @@ class ShowZoneExportFileCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('zone_export_id', help="Zone Export ID", type=str)
|
||||
|
||||
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.zone_exports.get_export(parsed_args.zone_export_id)
|
||||
|
||||
@ -538,10 +607,13 @@ class ImportZoneCommand(show.ShowOne):
|
||||
parser.add_argument('zone_file_path',
|
||||
help="Path to a zone file", type=str)
|
||||
|
||||
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)
|
||||
|
||||
with open(parsed_args.zone_file_path, 'r') as f:
|
||||
zone_file_contents = f.read()
|
||||
@ -569,10 +641,13 @@ class ListZoneImportsCommand(lister.Lister):
|
||||
parser = super(ListZoneImportsCommand, self).get_parser(
|
||||
prog_name)
|
||||
|
||||
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.zone_imports.list()
|
||||
|
||||
@ -590,10 +665,13 @@ class ShowZoneImportCommand(show.ShowOne):
|
||||
|
||||
parser.add_argument('zone_import_id', help="Zone Import ID", type=str)
|
||||
|
||||
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.zone_imports.get_import_record(
|
||||
parsed_args.zone_import_id)
|
||||
@ -611,10 +689,13 @@ class DeleteZoneImportCommand(command.Command):
|
||||
|
||||
parser.add_argument('zone_import_id', help="Zone Import ID", type=str)
|
||||
|
||||
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.zone_imports.delete(parsed_args.zone_import_id)
|
||||
|
||||
|
@ -41,6 +41,9 @@ class DesignateAdapter(adapter.LegacyJsonAdapter):
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.timeout = kwargs.pop('timeout', None)
|
||||
self.all_projects = kwargs.pop('all_projects', False)
|
||||
self.edit_managed = kwargs.pop('edit_managed', False)
|
||||
self.sudo_project_id = kwargs.pop('sudo_project_id', None)
|
||||
super(self.__class__, self).__init__(*args, **kwargs)
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
@ -49,7 +52,27 @@ class DesignateAdapter(adapter.LegacyJsonAdapter):
|
||||
if self.timeout is not None:
|
||||
kwargs.setdefault('timeout', self.timeout)
|
||||
|
||||
kwargs.setdefault('headers', {}).setdefault(
|
||||
kwargs.setdefault('headers', {})
|
||||
|
||||
if self.all_projects:
|
||||
kwargs['headers'].setdefault(
|
||||
'X-Auth-All-Projects',
|
||||
self.all_projects
|
||||
)
|
||||
|
||||
if self.edit_managed:
|
||||
kwargs['headers'].setdefault(
|
||||
'X-Designate-Edit-Managed-Records',
|
||||
self.edit_managed
|
||||
)
|
||||
|
||||
if self.sudo_project_id is not None:
|
||||
kwargs['headers'].setdefault(
|
||||
'X-Auth-Sudo-Project-ID',
|
||||
self.sudo_project_id
|
||||
)
|
||||
|
||||
kwargs['headers'].setdefault(
|
||||
'Content-Type', 'application/json')
|
||||
|
||||
response, body = super(self.__class__, self).request(*args, **kwargs)
|
||||
@ -78,7 +101,8 @@ class Client(object):
|
||||
def __init__(self, region_name=None, endpoint_type='publicURL',
|
||||
extensions=None, service_type='dns', service_name=None,
|
||||
http_log_debug=False, session=None, auth=None, timeout=None,
|
||||
endpoint_override=None):
|
||||
endpoint_override=None, all_projects=False,
|
||||
edit_managed=False, sudo_project_id=None):
|
||||
if session is None:
|
||||
raise ValueError("A session instance is required")
|
||||
|
||||
@ -91,7 +115,10 @@ class Client(object):
|
||||
user_agent='python-designateclient-%s' % version.version_info,
|
||||
version=('2'),
|
||||
endpoint_override=endpoint_override,
|
||||
timeout=timeout
|
||||
timeout=timeout,
|
||||
all_projects=all_projects,
|
||||
edit_managed=edit_managed,
|
||||
sudo_project_id=sudo_project_id
|
||||
)
|
||||
|
||||
self.blacklists = BlacklistController(self)
|
||||
|
@ -77,4 +77,4 @@ def get_all(function, criterion=None, args=None):
|
||||
else:
|
||||
break
|
||||
|
||||
return returned_data
|
||||
return returned_data
|
||||
|
Loading…
Reference in New Issue
Block a user