-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdsf.py
More file actions
4299 lines (3761 loc) · 170 KB
/
dsf.py
File metadata and controls
4299 lines (3761 loc) · 170 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""This module contains wrappers for interfacing with every element of a
Traffic Director (DSF) service.
"""
from collections import Iterable
from dyn.compat import force_unicode, string_types
from dyn.tm.utils import APIList, Active
from dyn.tm.errors import DynectInvalidArgumentError
from dyn.tm.records import (ARecord, AAAARecord, ALIASRecord, CAARecord,
CDSRecord, CDNSKEYRecord, CSYNCRecord, CERTRecord,
CNAMERecord, DHCIDRecord, DNAMERecord,
DNSKEYRecord, DSRecord, KEYRecord, KXRecord,
LOCRecord, IPSECKEYRecord, MXRecord, NAPTRRecord,
PTRRecord, PXRecord, NSAPRecord, RPRecord,
NSRecord, SOARecord, SPFRecord, SRVRecord,
TLSARecord, TXTRecord, SSHFPRecord, UNKNOWNRecord)
from dyn.tm.session import DynectSession
from dyn.tm.accounts import Notifier
__author__ = 'jnappi'
__all__ = ['get_all_dsf_services', 'get_all_record_sets',
'get_all_failover_chains', 'get_all_response_pools',
'get_all_rulesets', 'get_all_dsf_monitors', 'get_all_records',
'get_all_notifiers', 'DSFARecord', 'DSFSSHFPRecord', 'get_record',
'get_record_set', 'get_failover_chain', 'get_response_pool',
'get_ruleset', 'get_dsf_monitor', 'DSFNotifier', 'DSFAAAARecord',
'DSFALIASRecord', 'DSFCERTRecord', 'DSFCNAMERecord',
'DSFDHCIDRecord', 'DSFDNAMERecord', 'DSFDNSKEYRecord',
'DSFDSRecord', 'DSFKEYRecord', 'DSFKXRecord', 'DSFLOCRecord',
'DSFIPSECKEYRecord', 'DSFMXRecord', 'DSFNAPTRRecord',
'DSFPTRRecord', 'DSFPXRecord', 'DSFNSAPRecord', 'DSFRPRecord',
'DSFNSRecord', 'DSFSPFRecord', 'DSFSRVRecord', 'DSFTXTRecord',
'DSFRecordSet', 'DSFFailoverChain', 'DSFResponsePool',
'DSFRuleset', 'DSFMonitorEndpoint', 'DSFMonitor', 'DSFNode',
'TrafficDirector']
def get_dsf(service):
"""
:param service: a dsf_id string, or :class:`TrafficDirector`
:return: :class:`TrafficDirector` Service
"""
_service_id = _check_type(service)
uri = '/DSF/{}'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
director = TrafficDirector(None, api=False, **response['data'])
return director
def get_all_dsf_services():
""":return: A ``list`` of :class:`TrafficDirector` Services"""
uri = '/DSF/'
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
directors = []
for dsf in response['data']:
directors.append(TrafficDirector(None, api=False, **dsf))
return directors
def get_all_notifiers():
""":return: A ``list`` of :class:`DSFNotifier` Services"""
uri = '/Notifier/'
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
notifiers = []
for notify in response['data']:
notifiers.append(DSFNotifier(None, api=False, **notify))
return notifiers
def get_all_records(service):
"""
:param service: a dsf_id string, or :class:`TrafficDirector`
:return: A ``list`` of :class:`DSFRecord`s from the passed in `service`
Warning! This query may take a long time to run with services with many
records!
"""
_service_id = _check_type(service)
uri = '/DSFRecord/{}/'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
record_ids = [record['dsf_record_id'] for record in response['data']]
records = list()
for record_id in record_ids:
uri = '/DSFRecord/{}/{}'.format(_service_id, record_id)
response = DynectSession.get_session().execute(uri, 'GET', api_args)
records += _constructor(response['data'])
return records
def get_all_record_sets(service):
""":param service: a dsf_id string, or :class:`TrafficDirector`
:return: A ``list`` of :class:`DSFRecordSets` from the passed in `service`
"""
_service_id = _check_type(service)
uri = '/DSFRecordSet/{}/'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
recordSets = list()
for pool in response['data']:
recordSets.append(
DSFRecordSet(pool.pop('rdata_class'), api=False, **pool))
return recordSets
def get_all_failover_chains(service):
""":param service: a dsf_id string, or :class:`TrafficDirector`
:return: A ``list`` of :class:`DSFFailoverChains` from the passed in
`service`
"""
_service_id = _check_type(service)
uri = '/DSFRecordSetFailoverChain/{}/'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
failoverChains = list()
for pool in response['data']:
failoverChains.append(
DSFFailoverChain(pool.pop('label'), api=False, **pool))
return failoverChains
def get_all_response_pools(service):
""":param service: a dsf_id string, or :class:`TrafficDirector`
:return: A ``list`` of :class:`DSFResponsePools` from the passed in
`service`
"""
_service_id = _check_type(service)
uri = '/DSFResponsePool/{}/'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
responsePools = list()
for pool in response['data']:
responsePools.append(
DSFResponsePool(pool.pop('label'), api=False, **pool))
return responsePools
def get_all_rulesets(service):
""":param service: a dsf_id string, or :class:`TrafficDirector`
:return: A ``list`` of :class:`DSFRulesets` from the passed in `service`
"""
_service_id = _check_type(service)
uri = '/DSFRuleset/{}/'.format(_service_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
ruleset = list()
for rule in response['data']:
ruleset.append(DSFRuleset(rule.pop('label'), api=False, **rule))
return ruleset
def get_all_dsf_monitors():
""":return: A ``list`` of :class:`DSFMonitor` Services"""
uri = '/DSFMonitor/'
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
mons = []
for dsf in response['data']:
mons.append(DSFMonitor(api=False, **dsf))
return mons
def get_record(record_id, service, always_list=False):
"""
returns :class:`DSFRecord`
:param record_id: id of record you wish to pull up
:param service: id of service which this record belongs. Can either be
the service_id or a :class:`TrafficDirector` Object
:param always_list: Force the returned record to always be in a list.
:return returns single record, unless this is a special record type, then
a list is returned
"""
_service_id = _check_type(service)
uri = '/DSFRecord/{}/{}'.format(_service_id, record_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
record = _constructor(response['data'])
if len(record) > 1 or always_list:
return record
else:
return record[0]
def get_record_set(record_set_id, service):
"""
returns :class:`DSFRecordSet`
:param record_set_id: id of record set you wish to pull up
:param service: id of service which this record belongs. Can either be
the service_id or a :class:`TrafficDirector` Object
:return returns :class:`DSFRecordSet` Object
"""
_service_id = _check_type(service)
uri = '/DSFRecordSet/{}/{}'.format(_service_id, record_set_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
return DSFRecordSet(response['data'].pop('rdata_class'), api=False,
**response['data'])
def get_failover_chain(failover_chain_id, service):
"""
returns :class:`DSFFailoverChain`
:param failover_chain_id: id of :class:`DSFFailoverChain` you wish to pull
up
:param service: id of service which this record belongs. Can either be
the service_id or a :class:`TrafficDirector` Object
:return returns :class:`DSFFailoverChain` Object
"""
_service_id = _check_type(service)
uri = '/DSFRecordSetFailoverChain/{}/{}'.format(_service_id,
failover_chain_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
return DSFFailoverChain(response['data'].pop('label'), api=False,
**response['data'])
def get_response_pool(response_pool_id, service):
"""
returns :class:`DSFResponsePool`
:param response_pool_id: id of :class:`DSFResponsePool` you wish to pull up
:param service: id of service which this record belongs. Can either be
the service_id or a :class:`TrafficDirector` Object
:return returns :class:`DSFResponsePool` Object
"""
_service_id = _check_type(service)
uri = '/DSFResponsePool/{}/{}'.format(_service_id, response_pool_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
return DSFResponsePool(response['data'].pop('label'), api=False,
**response['data'])
def get_ruleset(ruleset_id, service):
"""
returns :class:`DSFRuleset`
:param ruleset_id: id of :class:`DSFRuleset` you wish to pull up
:param service: id of service which this record belongs. Can either be
the service_id or a :class:`TrafficDirector` Object
:return returns :class:`DSFRuleset` Object
"""
_service_id = _check_type(service)
uri = '/DSFRuleset/{}/{}'.format(_service_id, ruleset_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
return DSFRuleset(response['data'].pop('label'), api=False,
**response['data'])
def get_dsf_monitor(monitor_id):
""" A quick :class:`DSFmonitor` getter, for consistency sake.
:param monitor_id: id of :class:`DSFmonitor` you wish to pull up
:return returns :class:`DSFmonitor` Object"""
uri = '/DSFMonitor/{}'.format(monitor_id)
api_args = {'detail': 'Y'}
response = DynectSession.get_session().execute(uri, 'GET', api_args)
return DSFMonitor(api=False, **response['data'])
def _check_type(service):
if isinstance(service, TrafficDirector):
_service_id = service.service_id
elif isinstance(service, string_types):
_service_id = service
else:
raise Exception('Value must be string, or TrafficDirector Object')
return _service_id
def _constructor(record):
return_records = []
constructors = {'a': DSFARecord, 'aaaa': DSFAAAARecord,
'alias': DSFALIASRecord, 'cert': DSFCERTRecord,
'cname': DSFCNAMERecord, 'dhcid': DSFDHCIDRecord,
'dname': DSFDNAMERecord,
'dnskey': DSFDNSKEYRecord, 'ds': DSFDSRecord,
'key': DSFKEYRecord, 'kx': DSFKXRecord,
'loc': DSFLOCRecord,
'ipseckey': DSFIPSECKEYRecord,
'mx': DSFMXRecord, 'naptr': DSFNAPTRRecord,
'ptr': DSFPTRRecord, 'px': DSFPXRecord,
'nsap': DSFNSAPRecord, 'rp': DSFRPRecord,
'ns': DSFNSRecord, 'spf': DSFSPFRecord,
'srv': DSFSRVRecord, 'txt': DSFTXTRecord,
'sshfp': DSFSSHFPRecord}
rec_type = record['rdata_class'].lower()
constructor = constructors[rec_type]
rdata_key = 'rdata_{}'.format(rec_type)
kws = ('ttl', 'label', 'weight', 'automation', 'endpoints',
'endpoint_up_count', 'eligible', 'dsf_record_id',
'dsf_record_set_id', 'status', 'torpidity', 'service_id')
for data in record['rdata']:
record_data = data['data'][rdata_key]
for kw in kws:
record_data[kw] = record[kw]
if constructor is DSFSRVRecord:
record_data['rr_weight'] = record_data.pop('weight')
return_records.append(constructor(**record_data))
return return_records
class _DSFRecord(object):
"""Super Class for DSF Records."""
def __init__(self, label=None, weight=1, automation='auto', endpoints=None,
endpoint_up_count=None, eligible=True, **kwargs):
"""Create a :class:`_DSFRecord` object.
:param label: A unique label for this :class:`DSFRecord`
:param weight: Weight for this :class:`DSFRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
self.valid_automation = ('auto', 'auto_down', 'manual')
self._label = label
self._weight = weight
if automation not in self.valid_automation:
raise DynectInvalidArgumentError('automation', automation,
self.valid_automation)
self._automation = automation
self._endpoints = endpoints
self._endpoint_up_count = endpoint_up_count
self._eligible = eligible
self._service_id = self._dsf_record_set_id = self.uri = None
self._dsf_record_id = self._status = self._note = None
self._implicitPublish = True
for key, val in kwargs.items():
setattr(self, '_' + key, val)
def _post(self, dsf_id, record_set_id, publish=True, notes=None):
"""Create a new :class:`DSFRecord` on the DynECT System
:param dsf_id: The unique system id for the DSF service associated with
this :class:`DSFRecord`
:param record_set_id: The unique system id for the record set
associated with this :class:`DSFRecord`
"""
self._service_id = dsf_id
self._record_set_id = record_set_id
self.uri = '/DSFRecord/{}/{}/'.format(self._service_id,
self._record_set_id)
api_args = {}
api_args = self.to_json(skip_svc=True)
if publish:
api_args['publish'] = 'Y'
if notes:
api_args['notes'] = notes
response = DynectSession.get_session().execute(self.uri, 'POST',
api_args)
self._build(response['data'])
def _get(self, dsf_id, dsf_record_id):
"""Get an existing :class:`DSFRecord` from the DynECT System
:param dsf_id: The unique system id for the DSF service associated with
this :class:`DSFRecord`
:param dsf_record_id: The unique system id for the record set
associated with this :class:`DSFRecord`
"""
self._service_id = dsf_id
self._dsf_record_id = dsf_record_id
self.uri = '/DSFRecord/{}/{}/'.format(self._service_id,
self._dsf_record_id)
api_args = {}
response = DynectSession.get_session().execute(self.uri, 'GET',
api_args)
self._build(response['data'])
def _update_record(self, api_args, publish=True):
"""Make the API call to update the current record type
:param api_args: arguments to be pased to the API call
"""
record_rdata = '{}_rdata'.format(
self._record_type.replace('Record', '').replace('DSF', '').lower())
new_api_args = {'rdata': {record_rdata: api_args['rdata']}}
if not self._record_type.endswith('Record'):
self._record_type += 'Record'
if publish and self._implicitPublish:
new_api_args['publish'] = 'Y'
if self._note:
new_api_args['notes'] = self._note
self.uri = 'DSFRecord/{}/{}'.format(self._service_id,
self._dsf_record_id)
response = DynectSession.get_session().execute(self.uri, 'PUT',
new_api_args)
self._build(response['data'])
# We hose the note if a publish was requested
if new_api_args.get('publish') == 'Y':
self._note = None
def _update(self, api_args, publish=True):
"""API call to update non superclass record type parameters
:param api_args: arguments to be pased to the API call
"""
if publish and self._implicitPublish:
api_args['publish'] = 'Y'
if self._note:
api_args['notes'] = self._note
self.uri = 'DSFRecord/{}/{}'.format(self._service_id,
self._dsf_record_id)
response = DynectSession.get_session().execute(self.uri, 'PUT',
api_args)
self._build(response['data'])
# We hose the note if a publish was requested
if api_args.get('publish') == 'Y':
self._note = None
def _build(self, data):
"""Private build method
:param data: API Response data
"""
for key, val in data.items():
if key == 'rdata':
for rdata in val:
if isinstance(rdata, dict):
for rdatas, rdata_data in rdata.items():
# necessary due to unicode!
try:
for rtype, rdata_v in rdata_data.items():
if rtype == 'rdata_{}'.format(
self._rdata_class.lower()):
for k, v in rdata_v.items():
setattr(self, '_' + k, v)
except Exception:
pass
else:
setattr(self, '_' + key, val)
def publish(self, notes=None):
"""Publish changes to :class:`TrafficDirector`.
:param notes: Optional Note that will be added to the
zone notes of zones attached to this service.
"""
uri = '/DSF/{}/'.format(self._service_id)
api_args = {'publish': 'Y'}
if self._note:
api_args['notes'] = self._note
self._note = None
# if notes are passed in, we override.
if notes:
api_args['notes'] = notes
DynectSession.get_session().execute(uri, 'PUT', api_args)
self.refresh()
@property
def publish_note(self):
"""Returns Current Publish Note, which will be used on the next
publish action"""
return self._note
@publish_note.setter
def publish_note(self, note):
"""Adds this note to the next action which also performs a publish
"""
self._note = note
def refresh(self):
"""Pulls data down from Dynect System and repopulates
:class:`DSFRecord`
"""
self._get(self._service_id, self._dsf_record_id)
def add_to_record_set(self, record_set, service=None,
publish=True, notes=None):
"""Creates and links this :class:`DSFRecord` to passed in
:class:`DSFRecordSet` Object
:param record_set: Can either be the _dsf_record_set_id or a
:class:`DSFRecordSet` Object.
:param service: Only necessary if record_set is passed in as a string.
This can be a :class:`TrafficDirector` Object. or the _service_id
:param publish: Publish on execution (Default = True)
:param notes: Optional Zone publish Notes
"""
if self._dsf_record_id:
raise Exception('The record already exists in the system!')
if isinstance(record_set, DSFRecordSet):
_record_set_id = record_set._dsf_record_set_id
_service_id = record_set._service_id
elif isinstance(record_set, string_types):
if service is None:
msg = ('When record_set as a string, you must provide the '
'service_id as service=')
raise Exception(msg)
_record_set_id = record_set
else:
raise Exception('Could not make sense of Record Set Type')
if service:
_service_id = _check_type(service)
self._post(_service_id, _record_set_id, publish=True,
notes=notes)
@property
def dsf_id(self):
"""The unique system id of the :class:`TrafficDirector` This
:class:`DSFRecord` is attached to
"""
return self._service_id
@property
def record_id(self):
"""The unique system id for this :class:`DSFRecord`
"""
return self._dsf_record_id
@property
def record_set_id(self):
"""The unique system id of the :class:`DSFRecordSet` This
:class:`DSFRecord` is attached to
"""
return self._record_set_id
@property
def label(self):
"""A unique label for this :class:`DSFRecord`"""
return self._label
@label.setter
def label(self, value):
api_args = {'label': value}
self._update(api_args)
if self._implicitPublish:
self._label = value
@property
def weight(self):
"""Weight for this :class:`DSFRecord`"""
return self._weight
@weight.setter
def weight(self, value):
api_args = {'weight': value}
self._update(api_args)
if self._implicitPublish:
self._weight = value
@property
def automation(self):
"""Defines how eligiblity can be changed in response to monitoring.
Must be one of 'auto', 'auto_down', or 'manual'
"""
return self._automation
@automation.setter
def automation(self, value):
api_args = {'automation': value}
self._update(api_args)
if self._implicitPublish:
self._automation = value
@property
def endpoints(self):
"""Endpoints are used to determine status, torpidity, and eligible in
response to monitor data
"""
return self._endpoints
@endpoints.setter
def endpoints(self, value):
api_args = {'endpoints': value}
self._update(api_args)
if self._implicitPublish:
self._endpoints = value
@property
def endpoint_up_count(self):
"""Number of endpoints that must be up for the Record status to be 'up'
"""
return self._endpoint_up_count
@endpoint_up_count.setter
def endpoint_up_count(self, value):
api_args = {'endpoint_up_count': value}
self._update(api_args)
if self._implicitPublish:
self._endpoint_up_count = value
@property
def eligible(self):
"""Indicates whether or not the Record can be served"""
return self._eligible
@eligible.setter
def eligible(self, value):
api_args = {'eligible': value}
self._update(api_args)
if self._implicitPublish:
self._eligible = value
@property
def status(self):
"""Status of Record"""
self.refresh()
return self._status
def to_json(self, svc_id=None, skip_svc=False):
"""Convert this DSFRecord to a json blob"""
if self._service_id and not svc_id:
svc_id = self._service_id
json = {'label': self._label, 'weight': self._weight,
'automation': self._automation, 'endpoints': self._endpoints,
'eligible': self._eligible,
'endpoint_up_count': self._endpoint_up_count}
json_blob = {x: json[x] for x in json if json[x] is not None}
if hasattr(self, '_record_type'):
rdata = self.rdata()
outer_key = list(rdata.keys())[0]
inner_data = rdata[outer_key]
real_data = {x: inner_data[x] for x in inner_data
if x not in json_blob and x not in self.__dict__ and
x[1:] not in self.__dict__ and
inner_data[x] is not None and x != 'record_set_id' and
x != 'service_id' and x != 'implicitPublish'}
json_blob['rdata'] = {outer_key: real_data}
if svc_id and not skip_svc:
json_blob['service_id'] = svc_id
return json_blob
@property
def implicit_publish(self):
"""Toggle for this specific :class:`DSFRecord` for turning on and off
implicit Publishing for record Updates."""
return self._implicitPublish
@implicit_publish.setter
def implicit_publish(self, value):
if not isinstance(value, bool):
raise Exception('Value must be True or False')
self._implicitPublish = value
implicitPublish = implicit_publish # NOQA
def delete(self, notes=None, publish=True):
"""Delete this :class:`DSFRecord`
:param notes: Optional zone publish notes
:param publish: Publish at run time. Default is True
"""
api_args = {}
if publish and self._implicitPublish:
api_args['publish'] = 'Y'
if notes:
api_args['notes'] = notes
uri = '/DSFRecord/{}/{}'.format(self._service_id, self._dsf_record_id)
DynectSession.get_session().execute(uri, 'DELETE', api_args)
class DSFARecord(_DSFRecord, ARecord):
"""An :class:`ARecord` object which is able to store additional data for
use by a :class:`TrafficDirector` service.
"""
def __init__(self, address, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFARecord` object
:param address: IPv4 address for the record
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFARecord`
:param weight: Weight for this :class:`DSFARecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
ARecord.__init__(self, None, None, address=address, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFARecord'
class DSFAAAARecord(_DSFRecord, AAAARecord):
"""An :class:`AAAARecord` object which is able to store additional data for
use by a :class:`TrafficDirector` service.
"""
def __init__(self, address, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFAAAARecord` object
:param address: IPv6 address for the record
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFAAAARecord`
:param weight: Weight for this :class:`DSFAAAARecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
AAAARecord.__init__(self, None, None, address=address, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFAAAARecord'
class DSFALIASRecord(_DSFRecord, ALIASRecord):
"""An :class:`AliasRecord` object which is able to store additional data
for use by a :class:`TrafficDirector` service.
"""
def __init__(self, alias, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFALIASRecord` object
:param alias: alias target name
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFALIASRecord`
:param weight: Weight for this :class:`DSFALIASRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
ALIASRecord.__init__(self, None, None, alias=alias, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFALIASRecord'
class DSFCERTRecord(_DSFRecord, CERTRecord):
"""An :class:`CERTRecord` object which is able to store additional data for
use by a :class:`TrafficDirector` service.
"""
def __init__(self, format, tag, algorithm, certificate, ttl=0, label=None,
weight=1, automation='auto', endpoints=None,
endpoint_up_count=None, eligible=True, **kwargs):
"""Create a :class:`DSFCERTRecord` object
:param format: Numeric value for the certificate type
:param tag: Numeric value for the public key certificate
:param algorithm: Public key algorithm number used to generate the
certificate
:param certificate: The public key certificate
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFCERTRecord`
:param weight: Weight for this :class:`DSFCERTRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
CERTRecord.__init__(self, None, None, format=format, tag=tag,
algorithm=algorithm, certificate=certificate,
ttl=ttl, create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFCERTRecord'
def _update_record(self, api_args, publish=True):
"""Make the API call to update the current record type
:param api_args: arguments to be pased to the API call
"""
keys = ['format', 'tag', 'algorithm', 'certificate']
self.refresh()
for key in keys:
if key not in api_args:
api_args['rdata'][key] = getattr(self, key)
super(DSFCERTRecord, self)._update_record(api_args, publish=publish)
class DSFCNAMERecord(_DSFRecord, CNAMERecord):
"""An :class:`CNAMERecord` object which is able to store additional data
for use by a :class:`TrafficDirector` service.
"""
def __init__(self, cname, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFCNAMERecord` object
:param cname: Hostname
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFCNAMERecord`
:param weight: Weight for this :class:`DSFCNAMERecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
CNAMERecord.__init__(self, None, None, cname=cname, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFCNAMERecord'
class DSFDHCIDRecord(_DSFRecord, DHCIDRecord):
"""An :class:`DHCIDRecord` object which is able to store additional data
for use by a :class:`TrafficDirector` service.
"""
def __init__(self, digest, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFDHCIDRecord` object
:param digest: Base-64 encoded digest of DHCP data
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFDHCIDRecord`
:param weight: Weight for this :class:`DSFDHCIDRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
DHCIDRecord.__init__(self, None, None, digest=digest, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFDHCIDRecord'
class DSFDNAMERecord(_DSFRecord, DNAMERecord):
"""An :class:`DNAMERecord` object which is able to store additional data
for use by a :class:`TrafficDirector` service.
"""
def __init__(self, dname, ttl=0, label=None, weight=1, automation='auto',
endpoints=None, endpoint_up_count=None, eligible=True,
**kwargs):
"""Create a :class:`DSFDNAMERecord` object
:param dname: Target Hostname
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFDNAMERecord`
:param weight: Weight for this :class:`DSFDNAMERecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
DNAMERecord.__init__(self, None, None, dname=dname, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFDNAMERecord'
class DSFDNSKEYRecord(_DSFRecord, DNSKEYRecord):
"""An :class:`DNSKEYRecord` object which is able to store additional data
for use by a :class:`TrafficDirector` service.
"""
def __init__(self, protocol, public_key, algorithm=5, flags=256, ttl=0,
label=None, weight=1, automation='auto', endpoints=None,
endpoint_up_count=None, eligible=True, **kwargs):
"""Create a :class:`DSFDNSKEYRecord` object
:param protocol: Numeric value for protocol
:param public_key: The public key for the DNSSEC signed zone
:param algorithm: Numeric value representing the public key encryption
algorithm which will sign the zone. Must be one of 1 (RSA-MD5), 2
(Diffie-Hellman), 3 (DSA/SHA-1), 4 (Elliptic Curve), or
5 (RSA-SHA-1)
:param flags: Numeric value confirming this is the zone's DNSKEY
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFDNSKEYRecord`
:param weight: Weight for this :class:`DSFDNSKEYRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
DNSKEYRecord.__init__(self, None, None, protocol=protocol,
public_key=public_key, algorithm=algorithm,
flags=flags, ttl=ttl, create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFDNSKEYRecord'
def _update_record(self, api_args, publish=True):
"""Make the API call to update the current record type
:param api_args: arguments to be pased to the API call
"""
keys = ['flags', 'algorithm', 'protocol', 'public_key']
self.refresh()
for key in keys:
if key not in api_args:
api_args['rdata'][key] = getattr(self, key)
super(DSFDNSKEYRecord, self)._update_record(api_args, publish=publish)
class DSFDSRecord(_DSFRecord, DSRecord):
"""An :class:`DSRecord` object which is able to store additional data for
use by a :class:`TrafficDirector` service.
"""
def __init__(self, digest, keytag, algorithm=5, digtype=1, ttl=0,
label=None, weight=1, automation='auto', endpoints=None,
endpoint_up_count=None, eligible=True, **kwargs):
"""Create a :class:`DSFDSRecord` object
:param digest: The digest in hexadecimal form. 20-byte,
hexadecimal-encoded, one-way hash of the DNSKEY record surrounded
by parenthesis characters '(' & ')'
:param keytag: The digest mechanism to use to verify the digest
:param algorithm: Numeric value representing the public key encryption
algorithm which will sign the zone. Must be one of 1 (RSA-MD5), 2
(Diffie-Hellman), 3 (DSA/SHA-1), 4 (Elliptic Curve), or
5 (RSA-SHA-1)
:param digtype: the digest mechanism to use to verify the digest. Valid
values are SHA1, SHA256
:param ttl: TTL for this record
:param label: A unique label for this :class:`DSFDSRecord`
:param weight: Weight for this :class:`DSFDSRecord`
:param automation: Defines how eligible can be changed in response to
monitoring. Must be one of 'auto', 'auto_down', or 'manual'
:param endpoints: Endpoints are used to determine status, torpidity,
and eligible in response to monitor data
:param endpoint_up_count: Number of endpoints that must be up for the
Record status to be 'up'
:param eligible: Indicates whether or not the Record can be served
"""
DSRecord.__init__(self, None, None, digest=digest, keytag=keytag,
algorithm=algorithm, digtype=digtype, ttl=ttl,
create=False)
_DSFRecord.__init__(self, label, weight, automation, endpoints,
endpoint_up_count, eligible, **kwargs)
self._record_type = 'DSFDSRecord'
def _update_record(self, api_args, publish=True):
"""Make the API call to update the current record type
:param api_args: arguments to be pased to the API call
"""
keys = ['digest', 'algorithm', 'digtype', 'key_tag']
self.refresh()
for key in keys:
if key not in api_args:
api_args['rdata'][key] = getattr(self, key)
super(DSFDSRecord, self)._update_record(api_args, publish=publish)
class DSFKEYRecord(_DSFRecord, KEYRecord):
"""An :class:`KEYRecord` object which is able to store additional data for
use by a :class:`TrafficDirector` service.
"""
def __init__(self, algorithm, flags, protocol, public_key, ttl=0,
label=None, weight=1, automation='auto', endpoints=None,
endpoint_up_count=None, eligible=True, **kwargs):
"""Create a :class:`DSFKEYRecord` object
:param algorithm: Numeric value representing the public key encryption
algorithm which will sign the zone. Must be one of 1 (RSA-MD5), 2
(Diffie-Hellman), 3 (DSA/SHA-1), 4 (Elliptic Curve), or
5 (RSA-SHA-1)
:param flags: See RFC 2535 for information on KEY record flags