Skip to content

Commit 2d7f5e5

Browse files
committed
rework DNS
Rework DNS to be closer to the upstream version Implement functional tests for the OSC.DNS Rename dns_ptr to dns_ptr_record similar to designateclient
1 parent 40c1960 commit 2d7f5e5

23 files changed

Lines changed: 568 additions & 593 deletions

File tree

doc/source/user/proxies/dns.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PTR Records Operations
4343

4444
.. autoclass:: otcextensions.sdk.dns.v2._proxy.Proxy
4545

46-
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.ptrs
47-
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.create_ptr
48-
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.get_ptr
49-
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.restore_ptr
46+
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.floating_ips
47+
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.set_floating_ip
48+
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.get_floating_ip
49+
.. automethod:: otcextensions.sdk.dns.v2._proxy.Proxy.unset_floating_ip

doc/source/user/resources/dns/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Anti DDoS Resources
66

77
v2/zone
88
v2/nameserver
9-
v2/ptr
9+
v2/floating_ip
1010
v2/recordset
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
otcextensions.sdk.dns.v2.floating_ip
2+
====================================
3+
4+
.. automodule:: otcextensions.sdk.dns.v2.floating_ip
5+
6+
The DNS FloatingIP Class
7+
------------------------
8+
9+
The ``floating_ip`` class inherits from :class:`~otcextensions.sdk.sdk_resource.Resource`.
10+
11+
.. autoclass:: otcextensions.sdk.dns.v2.floating_ip.FloatingIP
12+
:members:

doc/source/user/resources/dns/v2/ptr.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

otcextensions/osclient/dns/v2/ptr.py

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
def _get_columns(item):
3030
column_map = {
3131
}
32-
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
32+
hidden = ['location', 'links']
33+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map,
34+
hidden)
3335

3436

3537
class ListPTR(command.Lister):
3638
_description = _('List PTR records')
3739
columns = (
38-
'id', 'name', 'type', 'status', 'description'
40+
'id', 'ptrdname', 'address', 'status', 'description', 'ttl'
3941
)
4042

4143
def get_parser(self, prog_name):
@@ -48,7 +50,7 @@ def take_action(self, parsed_args):
4850

4951
query = {}
5052

51-
data = client.ptrs(**query)
53+
data = client.floating_ips(**query)
5254

5355
table = (self.columns,
5456
(utils.get_item_properties(
@@ -64,20 +66,8 @@ def get_parser(self, prog_name):
6466
parser = super(ShowPTR, self).get_parser(prog_name)
6567

6668
parser.add_argument(
67-
'--ptr',
68-
metavar='<ID>',
69-
help=_('PTR record ID.')
70-
)
71-
parser.add_argument(
72-
'--region',
73-
metavar='<region>',
74-
default='en-de',
75-
help=_('Region of the FloatingIP.')
76-
)
77-
parser.add_argument(
78-
'--floating_ip',
79-
metavar='<UUID>',
80-
help=_('FloatingIP ID.')
69+
'floatingip_id',
70+
help=_('Floating IP ID in format region:floatingip_id.')
8171
)
8272

8373
return parser
@@ -86,15 +76,7 @@ def take_action(self, parsed_args):
8676

8777
client = self.app.client_manager.dns
8878

89-
query = {}
90-
91-
if parsed_args.ptr:
92-
query['ptr'] = parsed_args.ptr
93-
else:
94-
query['region'] = parsed_args.region
95-
query['floating_ip_id'] = parsed_args.floating_ip
96-
97-
obj = client.get_ptr(**query)
79+
obj = client.get_floating_ip(parsed_args.floatingip_id)
9880

9981
display_columns, columns = _get_columns(obj)
10082
data = utils.get_item_properties(obj, columns)
@@ -109,19 +91,7 @@ def get_parser(self, prog_name):
10991
parser = super(DeletePTR, self).get_parser(prog_name)
11092

11193
parser.add_argument(
112-
'--ptr',
113-
metavar='<ID>',
114-
help=_('PTR record ID.')
115-
)
116-
parser.add_argument(
117-
'--region',
118-
metavar='<region>',
119-
default='en-de',
120-
help=_('Region of the FloatingIP.')
121-
)
122-
parser.add_argument(
123-
'--floating_ip',
124-
metavar='<UUID>',
94+
'floatingip_id',
12595
help=_('FloatingIP ID.')
12696
)
12797

@@ -130,15 +100,7 @@ def get_parser(self, prog_name):
130100
def take_action(self, parsed_args):
131101
client = self.app.client_manager.dns
132102

133-
query = {}
134-
135-
if parsed_args.ptr:
136-
query['ptr'] = parsed_args.ptr
137-
else:
138-
query['region'] = parsed_args.region
139-
query['floating_ip_id'] = parsed_args.floating_ip
140-
141-
return client.restore_ptr(**query)
103+
client.unset_floating_ip(parsed_args.floatingip_id)
142104

143105

144106
class SetPTR(command.ShowOne):
@@ -147,26 +109,15 @@ class SetPTR(command.ShowOne):
147109
def get_parser(self, prog_name):
148110
parser = super(SetPTR, self).get_parser(prog_name)
149111

150-
fgrp = parser.add_argument_group()
151-
fgrp.add_argument(
152-
'--region',
153-
metavar='<region>',
154-
default='en-de',
155-
required=True,
156-
help=_('Region of the FloatingIP.')
157-
)
158-
fgrp.add_argument(
159-
'--floating_ip',
160-
metavar='<UUID>',
161-
required=True,
162-
help=_('FloatingIP ID.')
112+
parser.add_argument(
113+
'floatingip_id',
114+
help=_('Floating IP ID in format region:floatingip_id.')
163115
)
164116
parser.add_argument(
165-
'--ptrdname',
166-
metavar='<ptrdomain>',
167-
required=True,
168-
help=_('Domain of the PTR record.')
117+
'ptrdname',
118+
help=_('PTRD Name')
169119
)
120+
170121
parser.add_argument(
171122
'--description',
172123
metavar='<description>',
@@ -189,16 +140,14 @@ def take_action(self, parsed_args):
189140

190141
attrs = {}
191142

192-
if parsed_args.ptrdname:
193-
attrs['ptrdname'] = parsed_args.ptrdname
143+
attrs['ptrdname'] = parsed_args.ptrdname
194144
if parsed_args.description:
195145
attrs['description'] = parsed_args.description
196146
if parsed_args.ttl:
197147
attrs['ttl'] = parsed_args.ttl
198148

199-
obj = client.create_ptr(
200-
region=parsed_args.region,
201-
floating_ip_id=parsed_args.floating_ip,
149+
obj = client.set_floating_ip(
150+
floating_ip=parsed_args.floatingip_id,
202151
**attrs
203152
)
204153

otcextensions/osclient/dns/v2/recordset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
def _get_columns(item):
3232
column_map = {
3333
}
34-
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
34+
hidden = ['location', 'links']
35+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map,
36+
hidden)
3537

3638

3739
class ListRS(command.Lister):
@@ -225,7 +227,7 @@ def get_parser(self, prog_name):
225227
)
226228
parser.add_argument(
227229
'recordset',
228-
metavar='<UUID>',
230+
metavar='<id>',
229231
help=_('UUID of the recordset.')
230232
)
231233
parser.add_argument(
@@ -271,7 +273,7 @@ def take_action(self, parsed_args):
271273
for rec in parsed_args.record:
272274
attrs['records'].append(rec)
273275

274-
recordset = client.get_recordset(zone.id, parsed_args.recordset)
276+
recordset = client.get_recordset(parsed_args.recordset, zone.id)
275277

276278
obj = client.update_recordset(
277279
recordset=recordset,

otcextensions/osclient/dns/v2/zone.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
def _get_columns(item):
3636
column_map = {
3737
}
38-
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
38+
hidden = ['location', 'links']
39+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map,
40+
hidden)
3941

4042

4143
class ListZone(command.Lister):
@@ -120,7 +122,8 @@ def take_action(self, parsed_args):
120122
if parsed_args.zone:
121123
client = self.app.client_manager.dns
122124
for zone in parsed_args.zone:
123-
client.delete_zone(zone=zone, ignore_missing=False)
125+
zn = client.find_zone(zone, ignore_missing=False)
126+
client.delete_zone(zone=zn)
124127

125128

126129
class CreateZone(command.ShowOne):

otcextensions/sdk/dns/v2/_base.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
import six
13+
14+
from openstack import exceptions
15+
from openstack import resource
16+
17+
18+
class Resource(resource.Resource):
19+
20+
@classmethod
21+
def find(cls, session, name_or_id, ignore_missing=True, **params):
22+
"""Find a resource by its name or id.
23+
24+
:param session: The session to use for making this request.
25+
:type session: :class:`~keystoneauth1.adapter.Adapter`
26+
:param name_or_id: This resource's identifier, if needed by
27+
the request. The default is ``None``.
28+
:param bool ignore_missing: When set to ``False``
29+
:class:`~openstack.exceptions.ResourceNotFound` will be
30+
raised when the resource does not exist.
31+
When set to ``True``, None will be returned when
32+
attempting to find a nonexistent resource.
33+
:param dict params: Any additional parameters to be passed into
34+
underlying methods, such as to
35+
:meth:`~openstack.resource.Resource.existing`
36+
in order to pass on URI parameters.
37+
38+
:return: The :class:`Resource` object matching the given name or id
39+
or None if nothing matches.
40+
:raises: :class:`openstack.exceptions.DuplicateResource` if more
41+
than one resource is found for this request.
42+
:raises: :class:`openstack.exceptions.ResourceNotFound` if nothing
43+
is found and ignore_missing is ``False``.
44+
"""
45+
session = cls._get_session(session)
46+
# Try to short-circuit by looking directly for a matching ID.
47+
try:
48+
match = cls.existing(
49+
id=name_or_id,
50+
connection=session._get_connection(),
51+
**params)
52+
return match.fetch(session, **params)
53+
except exceptions.SDKException:
54+
# DNS may return 400 when we try to do GET with name
55+
pass
56+
57+
if ('name' in cls._query_mapping._mapping.keys()
58+
and 'name' not in params):
59+
params['name'] = name_or_id
60+
61+
data = cls.list(session, **params)
62+
63+
result = cls._get_one_match(name_or_id, data)
64+
if result is not None:
65+
return result
66+
67+
if ignore_missing:
68+
return None
69+
raise exceptions.ResourceNotFound(
70+
"No %s found for %s" % (cls.__name__, name_or_id))
71+
72+
@classmethod
73+
def _get_next_link(cls, uri, response, data, marker, limit, total_yielded):
74+
next_link = None
75+
params = {}
76+
if isinstance(data, dict):
77+
links = data.get('links')
78+
if links:
79+
next_link = links.get('next')
80+
81+
total = data.get('metadata', {}).get('total_count')
82+
if total:
83+
# We have a kill switch
84+
total_count = int(total)
85+
if total_count <= total_yielded:
86+
return None, params
87+
88+
# Parse params from Link (next page URL) into params.
89+
# This prevents duplication of query parameters that with large
90+
# number of pages result in HTTP 414 error eventually.
91+
if next_link:
92+
parts = six.moves.urllib.parse.urlparse(next_link)
93+
query_params = six.moves.urllib.parse.parse_qs(parts.query)
94+
params.update(query_params)
95+
next_link = six.moves.urllib.parse.urljoin(next_link,
96+
parts.path)
97+
98+
# If we still have no link, and limit was given and is non-zero,
99+
# and the number of records yielded equals the limit, then the user
100+
# is playing pagination ball so we should go ahead and try once more.
101+
if not next_link and limit:
102+
next_link = uri
103+
params['marker'] = marker
104+
params['limit'] = limit
105+
return next_link, params

0 commit comments

Comments
 (0)