Created
September 22, 2021 21:19
-
-
Save f5-rahm/116b6d3ad1d04171124b37fbaa6aa08b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bigsuds | |
b = bigsuds.BIGIP(hostname='ltm3.test.local') | |
zone_view = {'view_name': 'external', | |
'zone_name': 'dctest1.local.' | |
} | |
b.Management.Zone.zone_exist([zone_view]) | |
# [0] | |
zone_add_info = {'view_name': 'external', | |
'zone_name': 'dctest1.local.', | |
'zone_type': 'MASTER', | |
'zone_file': 'db.external.dctest1.local.', | |
'option_seq': ['allow-update { localhost;};']} | |
zone_add_records = 'dctest1.local. 500 IN SOA ns1.dctest1.local. hostmaster.ns1.dctest1.local. 2021092201 10800 3600 604800 60;\n' \ | |
'dctest1.local. 3600 IN NS ns1.dctest1.local.;\n' \ | |
'ns1.dctest1.local. 3600 IN A 10.0.2.1;' | |
b.Management.Zone.add_zone_text([zone_add_info], | |
[[zone_add_records]], | |
[0]) | |
b.Management.Zone.zone_exist([zone_view]) | |
# [1] | |
zone = b.Management.Zone.get_zone_v2([zone_view]) | |
for k, v in zone[0].items(): | |
print(f'{k}: {v}') | |
# view_name: external | |
# zone_name: dctest1.local. | |
# zone_type: MASTER | |
# zone_file: "db.external.dctest1.local." | |
# option_seq: ['allow-update { localhost;};'] | |
rrs = b.Management.ResourceRecord.get_rrs([zone_view]) | |
for rr in rrs[0]: | |
print(rr) | |
# dctest1.local. 500 IN SOA ns1.dctest1.local. hostmaster.ns1.dctest1.local. 2021092201 10800 3600 604800 60 | |
# dctest1.local. 3600 IN NS ns1.dctest1.local. | |
# ns1.dctest1.local. 3600 IN A 10.0.2.1 | |
a1 = {'domain_name': 'mail.dctest1.local.', | |
'ip_address': '10.0.2.25', | |
'ttl': 86400} | |
a2 = {'domain_name': 'www.dctest1.local.', | |
'ip_address': '10.0.2.80', | |
'ttl': 3600} | |
b.Management.ResourceRecord.add_a(view_zones=[zone_view], | |
a_records=[[a1, a2]], | |
sync_ptrs=[0]) | |
rrs = b.Management.ResourceRecord.get_rrs([zone_view]) | |
for rr in rrs[0]: | |
print(rr) | |
# dctest1.local. 500 IN SOA ns1.dctest1.local. hostmaster.ns1.dctest1.local. 2021092203 10800 3600 604800 86400 | |
# dctest1.local. 3600 IN NS ns1.dctest1.local. | |
# mail.dctest1.local. 86400 IN A 10.0.2.25 | |
# ns1.dctest1.local. 3600 IN A 10.0.2.1 | |
# www.dctest1.local. 3600 IN A 10.0.2.80 | |
a1_update = {'domain_name': 'mail.dctest1.local.', | |
'ip_address': '10.0.2.110', | |
'ttl': 900} | |
b.Management.ResourceRecord.update_a([zone_view], | |
[[a1]], | |
[[a1_update]], | |
[0]) | |
rrs = b.Management.ResourceRecord.get_rrs([zone_view]) | |
for rr in rrs[0]: | |
print(rr) | |
# dctest1.local. 500 IN SOA ns1.dctest1.local. hostmaster.ns1.dctest1.local. 2021092205 10800 3600 604800 86400 | |
# dctest1.local. 3600 IN NS ns1.dctest1.local. | |
# mail.dctest1.local. 900 IN A 10.0.2.110 | |
# ns1.dctest1.local. 3600 IN A 10.0.2.1 | |
# www.dctest1.local. 3600 IN A 10.0.2.80 | |
b.Management.ResourceRecord.delete_a([zone_view], | |
[[a2]], | |
[0]) | |
rrs = b.Management.ResourceRecord.get_rrs([zone_view]) | |
for rr in rrs[0]: | |
print(rr) | |
# dctest1.local. 500 IN SOA ns1.dctest1.local. hostmaster.ns1.dctest1.local. 2021092206 10800 3600 604800 86400 | |
# dctest1.local. 3600 IN NS ns1.dctest1.local. | |
# mail.dctest1.local. 900 IN A 10.0.2.110 | |
# ns1.dctest1.local. 3600 IN A 10.0.2.1 | |
b.Management.Zone.delete_zone([zone_view]) | |
# [0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment