fb-pdnstools 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fb_pdnstools/__init__.py +76 -34
- fb_pdnstools/base_handler.py +119 -102
- fb_pdnstools/bulk_rm_app.py +242 -152
- fb_pdnstools/bulk_rm_cfg.py +33 -19
- fb_pdnstools/common.py +13 -13
- fb_pdnstools/errors.py +15 -15
- fb_pdnstools/record.py +407 -241
- fb_pdnstools/server.py +81 -44
- fb_pdnstools/xlate.py +57 -36
- fb_pdnstools/zone.py +600 -369
- fb_pdnstools-1.1.0.data/data/share/locale/de/LC_MESSAGES/fb_pdnstools.mo +0 -0
- fb_pdnstools-1.1.0.data/data/share/locale/en/LC_MESSAGES/fb_pdnstools.mo +0 -0
- fb_pdnstools-1.1.0.dist-info/METADATA +53 -0
- fb_pdnstools-1.1.0.dist-info/RECORD +17 -0
- {fb_pdnstools-1.0.0.dist-info → fb_pdnstools-1.1.0.dist-info}/WHEEL +1 -2
- fb_pdnstools-1.1.0.dist-info/entry_points.txt +3 -0
- fb_pdnstools/local_version.py +0 -17
- fb_pdnstools-1.0.0.data/scripts/pdns-bulk-remove +0 -68
- fb_pdnstools-1.0.0.dist-info/METADATA +0 -40
- fb_pdnstools-1.0.0.dist-info/RECORD +0 -17
- fb_pdnstools-1.0.0.dist-info/top_level.txt +0 -1
- {fb_pdnstools-1.0.0.dist-info → fb_pdnstools-1.1.0.dist-info/licenses}/LICENSE +0 -0
fb_pdnstools/record.py
CHANGED
|
@@ -15,6 +15,7 @@ import datetime
|
|
|
15
15
|
import logging
|
|
16
16
|
import re
|
|
17
17
|
import time
|
|
18
|
+
|
|
18
19
|
try:
|
|
19
20
|
from collections.abc import MutableSequence
|
|
20
21
|
except ImportError:
|
|
@@ -39,21 +40,21 @@ from .errors import PowerDNSWrongRecordTypeError
|
|
|
39
40
|
from .errors import PowerDNSWrongSoaDataError
|
|
40
41
|
from .xlate import XLATOR
|
|
41
42
|
|
|
42
|
-
__version__ =
|
|
43
|
+
__version__ = "1.0.0"
|
|
43
44
|
|
|
44
45
|
LOG = logging.getLogger(__name__)
|
|
45
46
|
|
|
46
47
|
TYPE_ORDER = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
"SOA": 0,
|
|
49
|
+
"NS": 1,
|
|
50
|
+
"MX": 2,
|
|
51
|
+
"A": 3,
|
|
52
|
+
"AAAA": 4,
|
|
53
|
+
"CNAME": 5,
|
|
54
|
+
"SRV": 6,
|
|
55
|
+
"TXT": 7,
|
|
56
|
+
"SPF": 8,
|
|
57
|
+
"PTR": 9,
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
_ = XLATOR.gettext
|
|
@@ -63,12 +64,14 @@ _ = XLATOR.gettext
|
|
|
63
64
|
def compare_rrsets(x, y):
|
|
64
65
|
"""Compare two DNS record sets - thich function can be used for sorting record set lists."""
|
|
65
66
|
if not isinstance(x, PowerDNSRecordSet):
|
|
66
|
-
raise TypeError(
|
|
67
|
-
a=
|
|
67
|
+
raise TypeError(
|
|
68
|
+
_("Argument {a} {v!r} must be a {o} object.").format(a="x", v=x, o="PowerDNSRecordSet")
|
|
69
|
+
)
|
|
68
70
|
|
|
69
71
|
if not isinstance(y, PowerDNSRecordSet):
|
|
70
|
-
raise TypeError(
|
|
71
|
-
a=
|
|
72
|
+
raise TypeError(
|
|
73
|
+
_("Argument {a} {v!r} must be a {o} object.").format(a="y", v=y, o="PowerDNSRecordSet")
|
|
74
|
+
)
|
|
72
75
|
|
|
73
76
|
ret = compare_fqdn(x.name, y.name)
|
|
74
77
|
if ret:
|
|
@@ -94,8 +97,15 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
94
97
|
|
|
95
98
|
# -------------------------------------------------------------------------
|
|
96
99
|
def __init__(
|
|
97
|
-
self,
|
|
98
|
-
|
|
100
|
+
self,
|
|
101
|
+
appname=None,
|
|
102
|
+
verbose=0,
|
|
103
|
+
version=__version__,
|
|
104
|
+
base_dir=None,
|
|
105
|
+
initialized=None,
|
|
106
|
+
content=None,
|
|
107
|
+
disabled=False,
|
|
108
|
+
):
|
|
99
109
|
"""Initialize a PowerDNSRecord record."""
|
|
100
110
|
self._content = None
|
|
101
111
|
if content:
|
|
@@ -104,7 +114,8 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
104
114
|
self.disabled = disabled
|
|
105
115
|
|
|
106
116
|
super(PowerDNSRecord, self).__init__(
|
|
107
|
-
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
117
|
+
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
118
|
+
)
|
|
108
119
|
|
|
109
120
|
if initialized is not None:
|
|
110
121
|
self.initialized = initialized
|
|
@@ -156,14 +167,14 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
156
167
|
"""
|
|
157
168
|
if minimal:
|
|
158
169
|
return {
|
|
159
|
-
|
|
160
|
-
|
|
170
|
+
"content": self.content,
|
|
171
|
+
"disabled": self.disabled,
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
res = super(PowerDNSRecord, self).as_dict(short=short)
|
|
164
|
-
res[
|
|
165
|
-
res[
|
|
166
|
-
res[
|
|
175
|
+
res["content"] = self.content
|
|
176
|
+
res["disabled"] = self.disabled
|
|
177
|
+
res["enabled"] = self.enabled
|
|
167
178
|
|
|
168
179
|
return res
|
|
169
180
|
|
|
@@ -171,8 +182,13 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
171
182
|
def __copy__(self):
|
|
172
183
|
"""Return a new PowerDNSRecord as a deep copy of the current object."""
|
|
173
184
|
return PowerDNSRecord(
|
|
174
|
-
appname=self.appname,
|
|
175
|
-
|
|
185
|
+
appname=self.appname,
|
|
186
|
+
verbose=self.verbose,
|
|
187
|
+
base_dir=self.base_dir,
|
|
188
|
+
initialized=self.initialized,
|
|
189
|
+
content=self.content,
|
|
190
|
+
disabled=self.disabled,
|
|
191
|
+
)
|
|
176
192
|
|
|
177
193
|
# -------------------------------------------------------------------------
|
|
178
194
|
def __str__(self):
|
|
@@ -187,23 +203,23 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
187
203
|
# -------------------------------------------------------------------------
|
|
188
204
|
def __repr__(self):
|
|
189
205
|
"""Typecast into a string for reproduction."""
|
|
190
|
-
out =
|
|
206
|
+
out = "<%s(" % (self.__class__.__name__)
|
|
191
207
|
|
|
192
208
|
fields = []
|
|
193
|
-
fields.append(
|
|
194
|
-
fields.append(
|
|
195
|
-
fields.append(
|
|
196
|
-
fields.append(
|
|
197
|
-
fields.append(
|
|
209
|
+
fields.append("content={!r}".format(self.content))
|
|
210
|
+
fields.append("disabled={!r}".format(self.disabled))
|
|
211
|
+
fields.append("appname={!r}".format(self.appname))
|
|
212
|
+
fields.append("verbose={!r}".format(self.verbose))
|
|
213
|
+
fields.append("version={!r}".format(self.version))
|
|
198
214
|
|
|
199
|
-
out +=
|
|
215
|
+
out += ", ".join(fields) + ")>"
|
|
200
216
|
return out
|
|
201
217
|
|
|
202
218
|
# -------------------------------------------------------------------------
|
|
203
219
|
def __eq__(self, other):
|
|
204
220
|
"""Magic method for using it as the '=='-operator."""
|
|
205
221
|
if self.verbose > 4:
|
|
206
|
-
LOG.debug(_(
|
|
222
|
+
LOG.debug(_("Comparing equality of {} objects ...").format(self.__class__.__name__))
|
|
207
223
|
|
|
208
224
|
if not isinstance(other, PowerDNSRecord):
|
|
209
225
|
return False
|
|
@@ -225,11 +241,12 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
225
241
|
def __lt__(self, other):
|
|
226
242
|
"""Magic method for using it as the '<'-operator."""
|
|
227
243
|
if self.verbose > 4:
|
|
228
|
-
LOG.debug(_(
|
|
244
|
+
LOG.debug(_("Comparing less than of {} objects ...").format(self.__class__.__name__))
|
|
229
245
|
|
|
230
246
|
if not isinstance(other, PowerDNSRecord):
|
|
231
|
-
msg = _(
|
|
232
|
-
cls=other.__class__.__name__, other=other
|
|
247
|
+
msg = _("Wrong type {cls} of other parameter {other!r} for comparision.").format(
|
|
248
|
+
cls=other.__class__.__name__, other=other
|
|
249
|
+
)
|
|
233
250
|
raise PowerDNSWrongRecordTypeError(msg)
|
|
234
251
|
|
|
235
252
|
if self == other:
|
|
@@ -247,12 +264,14 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
247
264
|
def __gt__(self, other):
|
|
248
265
|
"""Magic method for using it as the '>'-operator."""
|
|
249
266
|
if self.verbose > 4:
|
|
250
|
-
LOG.debug(
|
|
251
|
-
self.__class__.__name__)
|
|
267
|
+
LOG.debug(
|
|
268
|
+
_("Comparing greater than of {} objects ...").format(self.__class__.__name__)
|
|
269
|
+
)
|
|
252
270
|
|
|
253
271
|
if not isinstance(other, PowerDNSRecord):
|
|
254
|
-
msg = _(
|
|
255
|
-
cls=other.__class__.__name__, other=other
|
|
272
|
+
msg = _("Wrong type {cls} of other parameter {other!r} for comparision.").format(
|
|
273
|
+
cls=other.__class__.__name__, other=other
|
|
274
|
+
)
|
|
256
275
|
raise PowerDNSWrongRecordTypeError(msg)
|
|
257
276
|
|
|
258
277
|
if self == other:
|
|
@@ -271,14 +290,24 @@ class PowerDNSRecord(FbBaseObject):
|
|
|
271
290
|
class PowerDnsSOAData(FbBaseObject):
|
|
272
291
|
"""Encapsulation class of a SOA (Start of authority) DNS record."""
|
|
273
292
|
|
|
274
|
-
re_soa_data = re.compile(r
|
|
275
|
-
re_ws = re.compile(r
|
|
293
|
+
re_soa_data = re.compile(r"^\s*(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$")
|
|
294
|
+
re_ws = re.compile(r"\s+")
|
|
276
295
|
|
|
277
296
|
# -------------------------------------------------------------------------
|
|
278
297
|
def __init__(
|
|
279
|
-
self,
|
|
280
|
-
|
|
281
|
-
|
|
298
|
+
self,
|
|
299
|
+
primary=None,
|
|
300
|
+
email=None,
|
|
301
|
+
serial=None,
|
|
302
|
+
refresh=None,
|
|
303
|
+
retry=None,
|
|
304
|
+
expire=None,
|
|
305
|
+
ttl=None,
|
|
306
|
+
appname=None,
|
|
307
|
+
verbose=0,
|
|
308
|
+
version=__version__,
|
|
309
|
+
base_dir=None,
|
|
310
|
+
):
|
|
282
311
|
"""Initialize a PowerDnsSOAData record."""
|
|
283
312
|
self._primary = None
|
|
284
313
|
self._email = None
|
|
@@ -289,8 +318,8 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
289
318
|
self._ttl = None
|
|
290
319
|
|
|
291
320
|
super(PowerDnsSOAData, self).__init__(
|
|
292
|
-
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
|
|
293
|
-
|
|
321
|
+
appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False
|
|
322
|
+
)
|
|
294
323
|
|
|
295
324
|
self.primary = primary
|
|
296
325
|
self.email = email
|
|
@@ -300,8 +329,15 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
300
329
|
self.expire = expire
|
|
301
330
|
self.ttl = ttl
|
|
302
331
|
|
|
303
|
-
if
|
|
304
|
-
|
|
332
|
+
if (
|
|
333
|
+
self.primary
|
|
334
|
+
and self.email
|
|
335
|
+
and self.serial is not None
|
|
336
|
+
and self.refresh
|
|
337
|
+
and self.retry
|
|
338
|
+
and self.expire
|
|
339
|
+
and self.ttl
|
|
340
|
+
):
|
|
305
341
|
self.initialized = True
|
|
306
342
|
else:
|
|
307
343
|
self.initialized = False
|
|
@@ -457,8 +493,9 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
457
493
|
return None
|
|
458
494
|
if not self.ttl:
|
|
459
495
|
return None
|
|
460
|
-
return
|
|
461
|
-
**self.__dict__
|
|
496
|
+
return "{_primary} {_email} {_serial} {_refresh} {_retry} {_expire} {_ttl}".format(
|
|
497
|
+
**self.__dict__
|
|
498
|
+
)
|
|
462
499
|
|
|
463
500
|
# -----------------------------------------------------------
|
|
464
501
|
@property
|
|
@@ -478,9 +515,15 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
478
515
|
return None
|
|
479
516
|
if not self.ttl:
|
|
480
517
|
return None
|
|
481
|
-
return
|
|
482
|
-
primary=self.primary,
|
|
483
|
-
|
|
518
|
+
return "{primary} {email} {serial} {refresh!r} {retry!r} {expire!r} {ttl!r}".format(
|
|
519
|
+
primary=self.primary,
|
|
520
|
+
email=self.email,
|
|
521
|
+
serial=self.serial,
|
|
522
|
+
refresh=self.refresh_human,
|
|
523
|
+
retry=self.retry_human,
|
|
524
|
+
expire=self.expire_human,
|
|
525
|
+
ttl=self.ttl_human,
|
|
526
|
+
)
|
|
484
527
|
|
|
485
528
|
# -------------------------------------------------------------------------
|
|
486
529
|
def as_dict(self, short=True):
|
|
@@ -494,19 +537,19 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
494
537
|
@rtype: dict
|
|
495
538
|
"""
|
|
496
539
|
res = super(PowerDnsSOAData, self).as_dict(short=short)
|
|
497
|
-
res[
|
|
498
|
-
res[
|
|
499
|
-
res[
|
|
500
|
-
res[
|
|
501
|
-
res[
|
|
502
|
-
res[
|
|
503
|
-
res[
|
|
504
|
-
res[
|
|
505
|
-
res[
|
|
506
|
-
res[
|
|
507
|
-
res[
|
|
508
|
-
res[
|
|
509
|
-
res[
|
|
540
|
+
res["primary"] = self.primary
|
|
541
|
+
res["email"] = self.email
|
|
542
|
+
res["serial"] = self.serial
|
|
543
|
+
res["refresh"] = self.refresh
|
|
544
|
+
res["refresh_human"] = self.refresh_human
|
|
545
|
+
res["retry"] = self.retry
|
|
546
|
+
res["retry_human"] = self.retry_human
|
|
547
|
+
res["expire"] = self.expire
|
|
548
|
+
res["expire_human"] = self.expire_human
|
|
549
|
+
res["ttl"] = self.ttl
|
|
550
|
+
res["ttl_human"] = self.ttl_human
|
|
551
|
+
res["data"] = self.data
|
|
552
|
+
res["data_human"] = self.data_human
|
|
510
553
|
|
|
511
554
|
return res
|
|
512
555
|
|
|
@@ -514,15 +557,23 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
514
557
|
@classmethod
|
|
515
558
|
def init_from_data(cls, data, appname=None, verbose=0, base_dir=None):
|
|
516
559
|
"""Create a PowerDnsSOAData on base of the SOA data given from DNS."""
|
|
517
|
-
line = cls.re_ws.sub(
|
|
560
|
+
line = cls.re_ws.sub(" ", to_str(data))
|
|
518
561
|
match = cls.re_soa_data.match(line)
|
|
519
562
|
if not match:
|
|
520
563
|
raise PowerDNSWrongSoaDataError(data)
|
|
521
564
|
|
|
522
565
|
soa = cls(
|
|
523
|
-
primary=match.group(1),
|
|
524
|
-
|
|
525
|
-
|
|
566
|
+
primary=match.group(1),
|
|
567
|
+
email=match.group(2),
|
|
568
|
+
serial=match.group(3),
|
|
569
|
+
refresh=match.group(4),
|
|
570
|
+
retry=match.group(5),
|
|
571
|
+
expire=match.group(6),
|
|
572
|
+
ttl=match.group(7),
|
|
573
|
+
appname=appname,
|
|
574
|
+
verbose=verbose,
|
|
575
|
+
base_dir=base_dir,
|
|
576
|
+
)
|
|
526
577
|
|
|
527
578
|
return soa
|
|
528
579
|
|
|
@@ -530,19 +581,27 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
530
581
|
def __copy__(self):
|
|
531
582
|
"""Return a new PowerDnsSOAData as a deep copy of the current object."""
|
|
532
583
|
if self.verbose > 4:
|
|
533
|
-
LOG.debug(_(
|
|
584
|
+
LOG.debug(_("Copying current {}-object in a new one.").format(self.__class__.__name__))
|
|
534
585
|
|
|
535
586
|
soa = PowerDnsSOAData(
|
|
536
|
-
primary=self.primary,
|
|
537
|
-
|
|
538
|
-
|
|
587
|
+
primary=self.primary,
|
|
588
|
+
email=self.email,
|
|
589
|
+
serial=self.serial,
|
|
590
|
+
refresh=self.refresh,
|
|
591
|
+
retry=self.retry,
|
|
592
|
+
expire=self.expire,
|
|
593
|
+
ttl=self.ttl,
|
|
594
|
+
appname=self.appname,
|
|
595
|
+
version=self.version,
|
|
596
|
+
base_dir=self.base_dir,
|
|
597
|
+
)
|
|
539
598
|
return soa
|
|
540
599
|
|
|
541
600
|
# -------------------------------------------------------------------------
|
|
542
601
|
def __eq__(self, other):
|
|
543
602
|
"""Magic method for using it as the '=='-operator."""
|
|
544
603
|
if self.verbose > 4:
|
|
545
|
-
LOG.debug(_(
|
|
604
|
+
LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
|
|
546
605
|
|
|
547
606
|
if not isinstance(other, PowerDnsSOAData):
|
|
548
607
|
return False
|
|
@@ -568,15 +627,15 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
568
627
|
def increase_serial(self):
|
|
569
628
|
"""Increase the serial number in current SOA to the current date + sequential number."""
|
|
570
629
|
i = 0
|
|
571
|
-
tpl =
|
|
630
|
+
tpl = "{year:4d}{month:02d}{day:02d}{nr:02d}"
|
|
572
631
|
curdate = datetime.date.today()
|
|
573
632
|
new_serial = 0
|
|
574
633
|
|
|
575
634
|
params = {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
635
|
+
"year": curdate.year,
|
|
636
|
+
"month": curdate.month,
|
|
637
|
+
"day": curdate.day,
|
|
638
|
+
"nr": i,
|
|
580
639
|
}
|
|
581
640
|
|
|
582
641
|
while new_serial <= self.serial:
|
|
@@ -586,10 +645,11 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
586
645
|
i += 1
|
|
587
646
|
if i > 99:
|
|
588
647
|
msg = _(
|
|
589
|
-
|
|
590
|
-
|
|
648
|
+
"Serial overflow - old serial {o} is in future, new serial {n} "
|
|
649
|
+
"has reached its maximum value."
|
|
650
|
+
).format(o=self.serial, n=new_serial)
|
|
591
651
|
raise ValueError(msg)
|
|
592
|
-
params[
|
|
652
|
+
params["nr"] = i
|
|
593
653
|
|
|
594
654
|
self.serial = new_serial
|
|
595
655
|
return new_serial
|
|
@@ -599,7 +659,7 @@ class PowerDnsSOAData(FbBaseObject):
|
|
|
599
659
|
class PowerDNSRecordList(MutableSequence):
|
|
600
660
|
"""A list containing Power DNS Records (as parts of a Record Set)."""
|
|
601
661
|
|
|
602
|
-
msg_no_pdns_record = _(
|
|
662
|
+
msg_no_pdns_record = _("Invalid type {t!r} as an item of a {c}, only {o} objects are allowed.")
|
|
603
663
|
|
|
604
664
|
# -------------------------------------------------------------------------
|
|
605
665
|
def __init__(self, *records):
|
|
@@ -617,8 +677,11 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
617
677
|
|
|
618
678
|
if len(args) > 0:
|
|
619
679
|
if len(args) > 2:
|
|
620
|
-
raise TypeError(
|
|
621
|
-
m
|
|
680
|
+
raise TypeError(
|
|
681
|
+
_("{m} takes at most {max} arguments ({n} given).").format(
|
|
682
|
+
m="index()", max=3, n=len(args) + 1
|
|
683
|
+
)
|
|
684
|
+
)
|
|
622
685
|
i = int(args[0])
|
|
623
686
|
if len(args) > 1:
|
|
624
687
|
j = int(args[1])
|
|
@@ -655,15 +718,18 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
655
718
|
if item == record:
|
|
656
719
|
return index
|
|
657
720
|
|
|
658
|
-
msg = _(
|
|
721
|
+
msg = _("Record {!r} is not in Record list.").format(record.content)
|
|
659
722
|
raise ValueError(msg)
|
|
660
723
|
|
|
661
724
|
# -------------------------------------------------------------------------
|
|
662
725
|
def __contains__(self, record):
|
|
663
726
|
"""Return whether the given record is contained in current list."""
|
|
664
727
|
if not isinstance(record, PowerDNSRecord):
|
|
665
|
-
raise TypeError(
|
|
666
|
-
|
|
728
|
+
raise TypeError(
|
|
729
|
+
self.msg_no_pdns_record.format(
|
|
730
|
+
t=record.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecord"
|
|
731
|
+
)
|
|
732
|
+
)
|
|
667
733
|
|
|
668
734
|
if not self._list:
|
|
669
735
|
return False
|
|
@@ -678,8 +744,11 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
678
744
|
def count(self, record):
|
|
679
745
|
"""Return the number of records which are equal to the given one in current list."""
|
|
680
746
|
if not isinstance(record, PowerDNSRecord):
|
|
681
|
-
raise TypeError(
|
|
682
|
-
|
|
747
|
+
raise TypeError(
|
|
748
|
+
self.msg_no_pdns_record.format(
|
|
749
|
+
t=record.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecord"
|
|
750
|
+
)
|
|
751
|
+
)
|
|
683
752
|
|
|
684
753
|
if not self._list:
|
|
685
754
|
return 0
|
|
@@ -709,8 +778,11 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
709
778
|
def __setitem__(self, key, record):
|
|
710
779
|
"""Replace the record at the given numeric index by the given one."""
|
|
711
780
|
if not isinstance(record, PowerDNSRecord):
|
|
712
|
-
raise TypeError(
|
|
713
|
-
|
|
781
|
+
raise TypeError(
|
|
782
|
+
self.msg_no_pdns_record.format(
|
|
783
|
+
t=record.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecord"
|
|
784
|
+
)
|
|
785
|
+
)
|
|
714
786
|
|
|
715
787
|
self._list.__setitem__(key, record)
|
|
716
788
|
|
|
@@ -723,8 +795,11 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
723
795
|
def append(self, record):
|
|
724
796
|
"""Append the given record to the current list."""
|
|
725
797
|
if not isinstance(record, PowerDNSRecord):
|
|
726
|
-
raise TypeError(
|
|
727
|
-
|
|
798
|
+
raise TypeError(
|
|
799
|
+
self.msg_no_pdns_record.format(
|
|
800
|
+
t=record.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecord"
|
|
801
|
+
)
|
|
802
|
+
)
|
|
728
803
|
|
|
729
804
|
self._list.append(record)
|
|
730
805
|
|
|
@@ -732,8 +807,11 @@ class PowerDNSRecordList(MutableSequence):
|
|
|
732
807
|
def insert(self, index, record):
|
|
733
808
|
"""Insert the given record in current list at given index."""
|
|
734
809
|
if not isinstance(record, PowerDNSRecord):
|
|
735
|
-
raise TypeError(
|
|
736
|
-
|
|
810
|
+
raise TypeError(
|
|
811
|
+
self.msg_no_pdns_record.format(
|
|
812
|
+
t=record.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecord"
|
|
813
|
+
)
|
|
814
|
+
)
|
|
737
815
|
|
|
738
816
|
self._list.insert(index, record)
|
|
739
817
|
|
|
@@ -762,15 +840,24 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
762
840
|
|
|
763
841
|
# -------------------------------------------------------------------------
|
|
764
842
|
def __init__(
|
|
765
|
-
self,
|
|
766
|
-
|
|
843
|
+
self,
|
|
844
|
+
appname=None,
|
|
845
|
+
verbose=0,
|
|
846
|
+
version=__version__,
|
|
847
|
+
base_dir=None,
|
|
848
|
+
initialized=None,
|
|
849
|
+
account=None,
|
|
850
|
+
content="",
|
|
851
|
+
modified_at=None,
|
|
852
|
+
):
|
|
767
853
|
"""Initialize a PowerDNSRecordSetComment object."""
|
|
768
854
|
self._account = None
|
|
769
|
-
self._content =
|
|
855
|
+
self._content = ""
|
|
770
856
|
self._modified_at = int(time.time() + 0.5)
|
|
771
857
|
|
|
772
858
|
super(PowerDNSRecordSetComment, self).__init__(
|
|
773
|
-
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
859
|
+
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
860
|
+
)
|
|
774
861
|
|
|
775
862
|
self.account = account
|
|
776
863
|
self.content = content
|
|
@@ -791,7 +878,7 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
791
878
|
self._account = None
|
|
792
879
|
return
|
|
793
880
|
v = str(value).strip()
|
|
794
|
-
if v ==
|
|
881
|
+
if v == "":
|
|
795
882
|
self._account = None
|
|
796
883
|
return
|
|
797
884
|
self._account = v
|
|
@@ -805,7 +892,7 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
805
892
|
@content.setter
|
|
806
893
|
def content(self, value):
|
|
807
894
|
if value is None:
|
|
808
|
-
self._content =
|
|
895
|
+
self._content = ""
|
|
809
896
|
return
|
|
810
897
|
v = str(value).strip()
|
|
811
898
|
self._content = v
|
|
@@ -824,15 +911,15 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
824
911
|
try:
|
|
825
912
|
v = int(value)
|
|
826
913
|
except ValueError as e:
|
|
827
|
-
msg =
|
|
828
|
-
|
|
829
|
-
|
|
914
|
+
msg = _("Invalid value for {w} of a {c} object - ").format(
|
|
915
|
+
w="modified_at", c=self.__class__.__name__
|
|
916
|
+
) + str(e)
|
|
830
917
|
raise ValueError(msg)
|
|
831
918
|
if v < 0:
|
|
832
919
|
msg = _(
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
920
|
+
"Invalid value for {w} {v!r} of a {c} object - "
|
|
921
|
+
"must be greater than or equal to zero."
|
|
922
|
+
).format(w="modified_at", c=self.__class__.__name__, v=value)
|
|
836
923
|
raise ValueError(msg)
|
|
837
924
|
self._modified_at = v
|
|
838
925
|
|
|
@@ -865,17 +952,17 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
865
952
|
"""
|
|
866
953
|
if minimal:
|
|
867
954
|
return {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
955
|
+
"account": self.account,
|
|
956
|
+
"content": self.content,
|
|
957
|
+
"modified_at": self.modified_at,
|
|
871
958
|
}
|
|
872
959
|
|
|
873
960
|
res = super(PowerDNSRecordSetComment, self).as_dict(short=short)
|
|
874
|
-
res[
|
|
875
|
-
res[
|
|
876
|
-
res[
|
|
877
|
-
res[
|
|
878
|
-
res[
|
|
961
|
+
res["account"] = self.account
|
|
962
|
+
res["content"] = self.content
|
|
963
|
+
res["modified_at"] = self.modified_at
|
|
964
|
+
res["modified_date"] = self.modified_date
|
|
965
|
+
res["valid"] = self.valid
|
|
879
966
|
|
|
880
967
|
return res
|
|
881
968
|
|
|
@@ -883,9 +970,14 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
883
970
|
def __copy__(self):
|
|
884
971
|
"""Return a new PowerDNSRecordSetComment as a deep copy of the current object."""
|
|
885
972
|
return PowerDNSRecordSetComment(
|
|
886
|
-
appname=self.appname,
|
|
973
|
+
appname=self.appname,
|
|
974
|
+
verbose=self.verbose,
|
|
975
|
+
base_dir=self.base_dir,
|
|
887
976
|
initialized=self.initialized,
|
|
888
|
-
account=self.account,
|
|
977
|
+
account=self.account,
|
|
978
|
+
content=self.content,
|
|
979
|
+
modified_at=self.modified_at,
|
|
980
|
+
)
|
|
889
981
|
|
|
890
982
|
# -------------------------------------------------------------------------
|
|
891
983
|
def __str__(self):
|
|
@@ -900,24 +992,24 @@ class PowerDNSRecordSetComment(FbBaseObject):
|
|
|
900
992
|
# -------------------------------------------------------------------------
|
|
901
993
|
def __repr__(self):
|
|
902
994
|
"""Typecast into a string for reproduction."""
|
|
903
|
-
out =
|
|
995
|
+
out = "<%s(" % (self.__class__.__name__)
|
|
904
996
|
|
|
905
997
|
fields = []
|
|
906
|
-
fields.append(
|
|
907
|
-
fields.append(
|
|
908
|
-
fields.append(
|
|
909
|
-
fields.append(
|
|
910
|
-
fields.append(
|
|
911
|
-
fields.append(
|
|
912
|
-
|
|
913
|
-
out +=
|
|
998
|
+
fields.append("account={!r}".format(self.account))
|
|
999
|
+
fields.append("content={!r}".format(self.content))
|
|
1000
|
+
fields.append("modified_at={!r}".format(self.modified_at))
|
|
1001
|
+
fields.append("appname={!r}".format(self.appname))
|
|
1002
|
+
fields.append("verbose={!r}".format(self.verbose))
|
|
1003
|
+
fields.append("version={!r}".format(self.version))
|
|
1004
|
+
|
|
1005
|
+
out += ", ".join(fields) + ")>"
|
|
914
1006
|
return out
|
|
915
1007
|
|
|
916
1008
|
# -------------------------------------------------------------------------
|
|
917
1009
|
def __eq__(self, other):
|
|
918
1010
|
"""Magic method for using it as the '=='-operator."""
|
|
919
1011
|
if self.verbose > 4:
|
|
920
|
-
LOG.debug(_(
|
|
1012
|
+
LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
|
|
921
1013
|
|
|
922
1014
|
if not isinstance(other, PowerDNSRecordSetComment):
|
|
923
1015
|
return False
|
|
@@ -942,10 +1034,22 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
942
1034
|
|
|
943
1035
|
# -------------------------------------------------------------------------
|
|
944
1036
|
def __init__(
|
|
945
|
-
self,
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1037
|
+
self,
|
|
1038
|
+
appname=None,
|
|
1039
|
+
verbose=0,
|
|
1040
|
+
version=__version__,
|
|
1041
|
+
base_dir=None,
|
|
1042
|
+
master_server=None,
|
|
1043
|
+
port=DEFAULT_PORT,
|
|
1044
|
+
key=None,
|
|
1045
|
+
use_https=False,
|
|
1046
|
+
timeout=None,
|
|
1047
|
+
path_prefix=DEFAULT_API_PREFIX,
|
|
1048
|
+
simulate=None,
|
|
1049
|
+
force=None,
|
|
1050
|
+
terminal_has_colors=False,
|
|
1051
|
+
initialized=None,
|
|
1052
|
+
):
|
|
949
1053
|
"""Initialize a PowerDNSRecordSet object."""
|
|
950
1054
|
# { 'comments': [],
|
|
951
1055
|
# 'name': 'www.bmwi.tv.',
|
|
@@ -959,10 +1063,20 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
959
1063
|
self.records = PowerDNSRecordList()
|
|
960
1064
|
|
|
961
1065
|
super(PowerDNSRecordSet, self).__init__(
|
|
962
|
-
appname=appname,
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1066
|
+
appname=appname,
|
|
1067
|
+
verbose=verbose,
|
|
1068
|
+
version=version,
|
|
1069
|
+
base_dir=base_dir,
|
|
1070
|
+
master_server=master_server,
|
|
1071
|
+
port=port,
|
|
1072
|
+
key=key,
|
|
1073
|
+
use_https=use_https,
|
|
1074
|
+
timeout=timeout,
|
|
1075
|
+
path_prefix=path_prefix,
|
|
1076
|
+
simulate=simulate,
|
|
1077
|
+
force=force,
|
|
1078
|
+
terminal_has_colors=terminal_has_colors,
|
|
1079
|
+
initialized=False,
|
|
966
1080
|
)
|
|
967
1081
|
|
|
968
1082
|
if initialized is not None:
|
|
@@ -977,13 +1091,13 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
977
1091
|
@name.setter
|
|
978
1092
|
def name(self, value):
|
|
979
1093
|
if not isinstance(value, six.string_types):
|
|
980
|
-
msg = _(
|
|
981
|
-
w=
|
|
1094
|
+
msg = _("A {w} must be a string type, but is {v!r} instead.").format(
|
|
1095
|
+
w="PowerDNSRecordSet.name", v=value
|
|
1096
|
+
)
|
|
982
1097
|
raise TypeError(msg)
|
|
983
1098
|
v = to_str(value).strip().lower()
|
|
984
|
-
if v ==
|
|
985
|
-
msg = _(
|
|
986
|
-
w='PowerDNSRecordSet.name', v=value)
|
|
1099
|
+
if v == "":
|
|
1100
|
+
msg = _("A {w} may not be empty: {v!r}.").format(w="PowerDNSRecordSet.name", v=value)
|
|
987
1101
|
raise ValueError(msg)
|
|
988
1102
|
self._name = v
|
|
989
1103
|
|
|
@@ -991,29 +1105,29 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
991
1105
|
@property
|
|
992
1106
|
def name_unicode(self):
|
|
993
1107
|
"""Give the name of the resource record set in unicode, if it is an IDNA encoded zone."""
|
|
994
|
-
n = getattr(self,
|
|
1108
|
+
n = getattr(self, "_name", None)
|
|
995
1109
|
if n is None:
|
|
996
1110
|
return None
|
|
997
|
-
if
|
|
998
|
-
return to_utf8(n).decode(
|
|
1111
|
+
if "xn--" in n:
|
|
1112
|
+
return to_utf8(n).decode("idna")
|
|
999
1113
|
return n
|
|
1000
1114
|
|
|
1001
1115
|
# -----------------------------------------------------------
|
|
1002
1116
|
@property
|
|
1003
|
-
def type(self):
|
|
1117
|
+
def type(self): # noqa: A003
|
|
1004
1118
|
"""Give the type of this record set."""
|
|
1005
1119
|
return self._type
|
|
1006
1120
|
|
|
1007
1121
|
@type.setter
|
|
1008
|
-
def type(self, value):
|
|
1122
|
+
def type(self, value): # noqa: A003
|
|
1009
1123
|
if not isinstance(value, six.string_types):
|
|
1010
|
-
msg = _(
|
|
1011
|
-
w=
|
|
1124
|
+
msg = _("A {w} must be a string type, but is {v!r} instead.").format(
|
|
1125
|
+
w="PowerDNSRecordSet.type", v=value
|
|
1126
|
+
)
|
|
1012
1127
|
raise TypeError(msg)
|
|
1013
1128
|
v = to_str(value).strip().upper()
|
|
1014
|
-
if v ==
|
|
1015
|
-
msg = _(
|
|
1016
|
-
w='PowerDNSRecordSet.type', v=value)
|
|
1129
|
+
if v == "":
|
|
1130
|
+
msg = _("A {w} may not be empty: {v!r}.").format(w="PowerDNSRecordSet.type", v=value)
|
|
1017
1131
|
raise ValueError(msg)
|
|
1018
1132
|
v = self.verify_rrset_type(v)
|
|
1019
1133
|
self._type = v
|
|
@@ -1039,66 +1153,86 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1039
1153
|
# -------------------------------------------------------------------------
|
|
1040
1154
|
@classmethod
|
|
1041
1155
|
def init_from_dict(
|
|
1042
|
-
cls,
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1156
|
+
cls,
|
|
1157
|
+
data,
|
|
1158
|
+
appname=None,
|
|
1159
|
+
verbose=0,
|
|
1160
|
+
version=__version__,
|
|
1161
|
+
base_dir=None,
|
|
1162
|
+
master_server=None,
|
|
1163
|
+
port=DEFAULT_PORT,
|
|
1164
|
+
key=None,
|
|
1165
|
+
use_https=False,
|
|
1166
|
+
timeout=None,
|
|
1167
|
+
path_prefix=DEFAULT_API_PREFIX,
|
|
1168
|
+
simulate=None,
|
|
1169
|
+
force=None,
|
|
1170
|
+
terminal_has_colors=False,
|
|
1171
|
+
initialized=None,
|
|
1172
|
+
):
|
|
1046
1173
|
"""Create a new PowerDNSRecordSet object based on a given dict."""
|
|
1047
1174
|
if not isinstance(data, dict):
|
|
1048
|
-
raise PowerDNSRecordSetError(_(
|
|
1175
|
+
raise PowerDNSRecordSetError(_("Given data {!r} is not a dict object.").format(data))
|
|
1049
1176
|
|
|
1050
1177
|
if verbose > 3:
|
|
1051
|
-
LOG.debug(_(
|
|
1178
|
+
LOG.debug(_("Creating {} object from data:").format(cls.__name__) + "\n" + pp(data))
|
|
1052
1179
|
|
|
1053
1180
|
params = {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1181
|
+
"appname": appname,
|
|
1182
|
+
"verbose": verbose,
|
|
1183
|
+
"version": version,
|
|
1184
|
+
"base_dir": base_dir,
|
|
1185
|
+
"master_server": master_server,
|
|
1186
|
+
"port": port,
|
|
1187
|
+
"key": key,
|
|
1188
|
+
"use_https": use_https,
|
|
1189
|
+
"timeout": timeout,
|
|
1190
|
+
"path_prefix": path_prefix,
|
|
1191
|
+
"simulate": simulate,
|
|
1192
|
+
"force": force,
|
|
1193
|
+
"terminal_has_colors": terminal_has_colors,
|
|
1067
1194
|
}
|
|
1068
1195
|
if initialized is not None:
|
|
1069
|
-
params[
|
|
1196
|
+
params["initialized"] = initialized
|
|
1070
1197
|
|
|
1071
1198
|
rrset = cls(**params)
|
|
1072
1199
|
|
|
1073
|
-
if
|
|
1074
|
-
for comment_dict in data[
|
|
1200
|
+
if "comments" in data and data["comments"]:
|
|
1201
|
+
for comment_dict in data["comments"]:
|
|
1075
1202
|
acc = None
|
|
1076
|
-
cont =
|
|
1203
|
+
cont = ""
|
|
1077
1204
|
modified_at = None
|
|
1078
|
-
if
|
|
1079
|
-
acc = comment_dict[
|
|
1080
|
-
if
|
|
1081
|
-
cont = comment_dict[
|
|
1082
|
-
if
|
|
1083
|
-
modified_at = comment_dict[
|
|
1205
|
+
if "account" in comment_dict:
|
|
1206
|
+
acc = comment_dict["account"]
|
|
1207
|
+
if "content" in comment_dict:
|
|
1208
|
+
cont = comment_dict["content"]
|
|
1209
|
+
if "modified_at" in comment_dict:
|
|
1210
|
+
modified_at = comment_dict["modified_at"]
|
|
1084
1211
|
comment = PowerDNSRecordSetComment(
|
|
1085
|
-
appname=appname,
|
|
1086
|
-
|
|
1212
|
+
appname=appname,
|
|
1213
|
+
verbose=verbose,
|
|
1214
|
+
base_dir=base_dir,
|
|
1215
|
+
account=acc,
|
|
1216
|
+
content=cont,
|
|
1217
|
+
modified_at=modified_at,
|
|
1218
|
+
)
|
|
1087
1219
|
if comment.valid:
|
|
1088
1220
|
comment.initialized = True
|
|
1089
1221
|
rrset.comments.append(comment)
|
|
1090
1222
|
|
|
1091
|
-
rrset._name = to_str(str(data[
|
|
1092
|
-
rrset._type = to_str(str(data[
|
|
1093
|
-
if
|
|
1094
|
-
rrset._ttl = int(data[
|
|
1223
|
+
rrset._name = to_str(str(data["name"]))
|
|
1224
|
+
rrset._type = to_str(str(data["type"]).upper())
|
|
1225
|
+
if "ttl" in data:
|
|
1226
|
+
rrset._ttl = int(data["ttl"])
|
|
1095
1227
|
|
|
1096
|
-
if
|
|
1097
|
-
for single_record in data[
|
|
1228
|
+
if "records" in data:
|
|
1229
|
+
for single_record in data["records"]:
|
|
1098
1230
|
record = PowerDNSRecord(
|
|
1099
|
-
appname=appname,
|
|
1100
|
-
|
|
1101
|
-
|
|
1231
|
+
appname=appname,
|
|
1232
|
+
verbose=verbose,
|
|
1233
|
+
base_dir=base_dir,
|
|
1234
|
+
content=to_str(single_record["content"]),
|
|
1235
|
+
disabled=single_record["disabled"],
|
|
1102
1236
|
)
|
|
1103
1237
|
record.initialized = True
|
|
1104
1238
|
rrset.records.append(record)
|
|
@@ -1111,15 +1245,15 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1111
1245
|
def name_relative(self, reference):
|
|
1112
1246
|
"""Extract the name from the current set name relative to the given reference."""
|
|
1113
1247
|
# current name must be an absolute name
|
|
1114
|
-
if not self.name.endswith(
|
|
1248
|
+
if not self.name.endswith("."):
|
|
1115
1249
|
return self.name
|
|
1116
1250
|
|
|
1117
1251
|
# reference name must be an absolute name
|
|
1118
|
-
if not reference.endswith(
|
|
1252
|
+
if not reference.endswith("."):
|
|
1119
1253
|
return self.name
|
|
1120
1254
|
|
|
1121
|
-
ref_escaped = r
|
|
1122
|
-
rel_name = re.sub(ref_escaped,
|
|
1255
|
+
ref_escaped = r"\." + re.escape(reference) + r"$"
|
|
1256
|
+
rel_name = re.sub(ref_escaped, "", self.name)
|
|
1123
1257
|
return rel_name
|
|
1124
1258
|
|
|
1125
1259
|
# -------------------------------------------------------------------------
|
|
@@ -1137,32 +1271,32 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1137
1271
|
"""
|
|
1138
1272
|
if minimal:
|
|
1139
1273
|
ret = {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1274
|
+
"comments": [],
|
|
1275
|
+
"name": self.name,
|
|
1276
|
+
"records": [],
|
|
1277
|
+
"ttl": self.ttl,
|
|
1278
|
+
"type": self.type,
|
|
1145
1279
|
}
|
|
1146
1280
|
for comment in self.comments:
|
|
1147
|
-
ret[
|
|
1281
|
+
ret["comments"].append(comment.as_dict(minimal=True))
|
|
1148
1282
|
for record in self.records:
|
|
1149
|
-
ret[
|
|
1283
|
+
ret["records"].append(record.as_dict(minimal=True))
|
|
1150
1284
|
return ret
|
|
1151
1285
|
|
|
1152
1286
|
res = super(PowerDNSRecordSet, self).as_dict(short=short)
|
|
1153
|
-
res[
|
|
1154
|
-
res[
|
|
1155
|
-
res[
|
|
1156
|
-
res[
|
|
1157
|
-
res[
|
|
1158
|
-
res[
|
|
1159
|
-
res[
|
|
1287
|
+
res["name"] = self.name
|
|
1288
|
+
res["type"] = self.type
|
|
1289
|
+
res["ttl"] = self.ttl
|
|
1290
|
+
res["ttl_human"] = self.ttl_human
|
|
1291
|
+
res["name_unicode"] = self.name_unicode
|
|
1292
|
+
res["comments"] = []
|
|
1293
|
+
res["records"] = []
|
|
1160
1294
|
|
|
1161
1295
|
for record in self.records:
|
|
1162
|
-
res[
|
|
1296
|
+
res["records"].append(record.as_dict(short))
|
|
1163
1297
|
|
|
1164
1298
|
for comment in self.comments:
|
|
1165
|
-
res[
|
|
1299
|
+
res["comments"].append(comment.as_dict(short=short))
|
|
1166
1300
|
|
|
1167
1301
|
return res
|
|
1168
1302
|
|
|
@@ -1180,11 +1314,20 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1180
1314
|
def __copy__(self):
|
|
1181
1315
|
"""Return a new PowerDNSRecordSet as a deep copy of the current object."""
|
|
1182
1316
|
rrset = PowerDNSRecordSet(
|
|
1183
|
-
appname=self.appname,
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1317
|
+
appname=self.appname,
|
|
1318
|
+
verbose=self.verbose,
|
|
1319
|
+
base_dir=self.base_dir,
|
|
1320
|
+
master_server=self.master_server,
|
|
1321
|
+
port=self.port,
|
|
1322
|
+
key=self.key,
|
|
1323
|
+
use_https=self.use_https,
|
|
1324
|
+
timeout=self.timeout,
|
|
1325
|
+
path_prefix=self.path_prefix,
|
|
1326
|
+
simulate=self.simulate,
|
|
1327
|
+
force=self.force,
|
|
1328
|
+
terminal_has_colors=self.terminal_has_colors,
|
|
1329
|
+
initialized=False,
|
|
1330
|
+
)
|
|
1188
1331
|
|
|
1189
1332
|
rrset._name = self.name
|
|
1190
1333
|
rrset._type = self.type
|
|
@@ -1199,7 +1342,7 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1199
1342
|
def __eq__(self, other):
|
|
1200
1343
|
"""Magic method for using it as the '=='-operator."""
|
|
1201
1344
|
if self.verbose > 4:
|
|
1202
|
-
LOG.debug(_(
|
|
1345
|
+
LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
|
|
1203
1346
|
|
|
1204
1347
|
if not isinstance(other, PowerDNSRecordSet):
|
|
1205
1348
|
return False
|
|
@@ -1215,20 +1358,24 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1215
1358
|
# -------------------------------------------------------------------------
|
|
1216
1359
|
def get_soa_data(self):
|
|
1217
1360
|
"""Extract a PowerDnsSOAData object from record content, if current type is SOA."""
|
|
1218
|
-
if self.type !=
|
|
1219
|
-
msg =
|
|
1220
|
-
o
|
|
1361
|
+
if self.type != "SOA":
|
|
1362
|
+
msg = (
|
|
1363
|
+
_("Cannot create {o} from record set:").format(o="PowerDnsSOAData")
|
|
1364
|
+
+ "\n"
|
|
1365
|
+
+ pp(self.as_dict())
|
|
1366
|
+
)
|
|
1221
1367
|
raise PowerDNSRecordSetError(msg)
|
|
1222
1368
|
|
|
1223
1369
|
if not self.records:
|
|
1224
|
-
msg = _(
|
|
1370
|
+
msg = _("RecordSet has no records:") + "\n" + pp(self.as_dict())
|
|
1225
1371
|
raise PowerDNSRecordSetError(msg)
|
|
1226
1372
|
|
|
1227
1373
|
record = self.records[0]
|
|
1228
1374
|
soa = PowerDnsSOAData.init_from_data(
|
|
1229
|
-
record.content, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir
|
|
1375
|
+
record.content, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir
|
|
1376
|
+
)
|
|
1230
1377
|
if self.verbose > 3:
|
|
1231
|
-
LOG.debug(_(
|
|
1378
|
+
LOG.debug(_("Got SOA:") + "\n" + pp(soa.as_dict()))
|
|
1232
1379
|
return soa
|
|
1233
1380
|
|
|
1234
1381
|
|
|
@@ -1236,7 +1383,7 @@ class PowerDNSRecordSet(BasePowerDNSHandler):
|
|
|
1236
1383
|
class PowerDNSRecordSetList(MutableSequence):
|
|
1237
1384
|
"""A list containing Power DNS Record Sets (of a zone)."""
|
|
1238
1385
|
|
|
1239
|
-
msg_no_pdns_rrset = _(
|
|
1386
|
+
msg_no_pdns_rrset = _("Invalid type {t!r} as an item of a {c}, only {o} objects are allowed.")
|
|
1240
1387
|
|
|
1241
1388
|
# -------------------------------------------------------------------------
|
|
1242
1389
|
def __init__(self, *rrsets):
|
|
@@ -1254,8 +1401,11 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1254
1401
|
|
|
1255
1402
|
if len(args) > 0:
|
|
1256
1403
|
if len(args) > 2:
|
|
1257
|
-
raise TypeError(
|
|
1258
|
-
m
|
|
1404
|
+
raise TypeError(
|
|
1405
|
+
_("{m} takes at most {max} arguments ({n} given).").format(
|
|
1406
|
+
m="index()", max=3, n=len(args) + 1
|
|
1407
|
+
)
|
|
1408
|
+
)
|
|
1259
1409
|
i = int(args[0])
|
|
1260
1410
|
if len(args) > 1:
|
|
1261
1411
|
j = int(args[1])
|
|
@@ -1292,16 +1442,20 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1292
1442
|
if item == rrset:
|
|
1293
1443
|
return index
|
|
1294
1444
|
|
|
1295
|
-
msg = _(
|
|
1296
|
-
n=rrset.name, t=rrset.type
|
|
1445
|
+
msg = _("RecordSet {n!r} ({n}) is not in RecordSet list.").format(
|
|
1446
|
+
n=rrset.name, t=rrset.type
|
|
1447
|
+
)
|
|
1297
1448
|
raise ValueError(msg)
|
|
1298
1449
|
|
|
1299
1450
|
# -------------------------------------------------------------------------
|
|
1300
1451
|
def __contains__(self, rrset):
|
|
1301
1452
|
"""Return whether the given record set is contained in current list."""
|
|
1302
1453
|
if not isinstance(rrset, PowerDNSRecordSet):
|
|
1303
|
-
raise TypeError(
|
|
1304
|
-
|
|
1454
|
+
raise TypeError(
|
|
1455
|
+
self.msg_no_pdns_record.format(
|
|
1456
|
+
t=rrset.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecordSet"
|
|
1457
|
+
)
|
|
1458
|
+
)
|
|
1305
1459
|
|
|
1306
1460
|
if not self._list:
|
|
1307
1461
|
return False
|
|
@@ -1316,8 +1470,11 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1316
1470
|
def count(self, rrset):
|
|
1317
1471
|
"""Return the number of record sets which are equal to the given one in current list."""
|
|
1318
1472
|
if not isinstance(rrset, PowerDNSRecordSet):
|
|
1319
|
-
raise TypeError(
|
|
1320
|
-
|
|
1473
|
+
raise TypeError(
|
|
1474
|
+
self.msg_no_pdns_record.format(
|
|
1475
|
+
t=rrset.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecordSet"
|
|
1476
|
+
)
|
|
1477
|
+
)
|
|
1321
1478
|
|
|
1322
1479
|
if not self._list:
|
|
1323
1480
|
return 0
|
|
@@ -1347,8 +1504,11 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1347
1504
|
def __setitem__(self, key, rrset):
|
|
1348
1505
|
"""Replace the record set at the given numeric index by the given one."""
|
|
1349
1506
|
if not isinstance(rrset, PowerDNSRecordSet):
|
|
1350
|
-
raise TypeError(
|
|
1351
|
-
|
|
1507
|
+
raise TypeError(
|
|
1508
|
+
self.msg_no_pdns_record.format(
|
|
1509
|
+
t=rrset.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecordSet"
|
|
1510
|
+
)
|
|
1511
|
+
)
|
|
1352
1512
|
|
|
1353
1513
|
self._list.__setitem__(key, rrset)
|
|
1354
1514
|
|
|
@@ -1361,8 +1521,11 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1361
1521
|
def append(self, rrset):
|
|
1362
1522
|
"""Append the given record set to the current list."""
|
|
1363
1523
|
if not isinstance(rrset, PowerDNSRecordSet):
|
|
1364
|
-
raise TypeError(
|
|
1365
|
-
|
|
1524
|
+
raise TypeError(
|
|
1525
|
+
self.msg_no_pdns_record.format(
|
|
1526
|
+
t=rrset.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecordSet"
|
|
1527
|
+
)
|
|
1528
|
+
)
|
|
1366
1529
|
|
|
1367
1530
|
self._list.append(rrset)
|
|
1368
1531
|
|
|
@@ -1370,8 +1533,11 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1370
1533
|
def insert(self, index, rrset):
|
|
1371
1534
|
"""Insert the given record set in current list at given index."""
|
|
1372
1535
|
if not isinstance(rrset, PowerDNSRecordSet):
|
|
1373
|
-
raise TypeError(
|
|
1374
|
-
|
|
1536
|
+
raise TypeError(
|
|
1537
|
+
self.msg_no_pdns_record.format(
|
|
1538
|
+
t=rrset.__class__.__name__, c=self.__class__.__name__, o="PowerDNSRecordSet"
|
|
1539
|
+
)
|
|
1540
|
+
)
|
|
1375
1541
|
|
|
1376
1542
|
self._list.insert(index, rrset)
|
|
1377
1543
|
|
|
@@ -1391,7 +1557,7 @@ class PowerDNSRecordSetList(MutableSequence):
|
|
|
1391
1557
|
|
|
1392
1558
|
# =============================================================================
|
|
1393
1559
|
|
|
1394
|
-
if __name__ ==
|
|
1560
|
+
if __name__ == "__main__":
|
|
1395
1561
|
|
|
1396
1562
|
pass
|
|
1397
1563
|
|