dyninc / dyn-python

Dyn SDK for Python
Other
36 stars 52 forks source link

Function change_ip throws error if the zone does not have any A records #136

Open bigbigblake opened 5 years ago

bigbigblake commented 5 years ago

If you have a zone that does not actually contain any A records this function will fail.

my_zones = get_all_zones()

oldIP = ['10.1.2.3', '10.1.2.4']
newIP = ['10.1.2.6', '10.1.2.8']

for zone in my_zones:
    if (zone.name != 'problem zone'):
        changedRecords = change_ip(zone, oldIP, newIP, v6=False, publish=True)

The utility fails with this error:

Traceback (most recent call last): File "C:/Users/blahblah/PycharmProjects/DynReader/DynModifier.py", line 26, in changedRecords = change_ip(zone, oldIP, newIP, v6=False, publish=True) File "C:\Users\blahblah\PycharmProjects\DynReader\venv\lib\site-packages\dyn\tm\tools.py", line 30, in change_ip records = records['aaaa_records'] if v6 else records['a_records'] KeyError: 'a_records'

bigbigblake commented 5 years ago

Additionally the publish=True does not seem to work correctly in this iteration. Right after i run the change_ip i have to do a zone.publish() for it to actually write to DYN.