4.7. TM Tools¶
The tools
module contains utility functions for performing common
and potentially difficult tasks easily.
4.7.1. List Functions¶
-
dyn.tm.tools.
change_ip
(zone, from_ip, to, v6=False, publish=False)[source]¶ Change all occurances of an ip address to a new ip address under the specified zone
Parameters: - zone – The
Zone
you wish to update ips for - from_ip – Either a list of ip addresses or a single ip address that you want updated
- to – Either a list of ip addresses or a single ip address that will overwrite from_ip
- v6 – Boolean flag to specify if we’re replacing ipv4 or ipv6 addresses (ie, whether we’re updating an ARecord or AAAARecord)
- publish – A boolean flag denoting whether or not to publish changes after making them. You can optionally leave this as False and process the returned changeset prior to publishing your changes.
Returns: A list of tuples of the form (fqdn, old, new) where fqdn is the fqdn of the record that was updated, old was the old ip address, and new is the new ip address.
- zone – The
-
dyn.tm.tools.
map_ips
(zone, mapping, v6=False, publish=False)[source]¶ Change all occurances of an ip address to a new ip address under the specified zone
Parameters: - zone – The
Zone
you wish to update ips for - mapping – A dict of the form {‘old_ip’: ‘new_ip’}
- v6 – Boolean flag to specify if we’re replacing ipv4 or ipv6 addresses (ie, whether we’re updating an ARecord or AAAARecord)
- publish – A boolean flag denoting whether or not to publish changes after making them. You can optionally leave this as False and process the returned changeset prior to publishing your changes.
Returns: A list of tuples of the form (fqdn, old, new) where fqdn is the fqdn of the record that was updated, old was the old ip address, and new is the new ip address.
- zone – The
4.7.2. Tools Examples¶
4.7.2.1. change_ip¶
If you find yourself replacing a server with a new one, or in some other situation
where you might want to replace an ip address with a new one, then change_ip()
makes
it straight forward to apply these changes
>>> from dyn.tm.zones import Zone
>>> from dyn.tm.tools import change_ip
>>> my_zone = Zone('example.com')
>>> old = '1.1.1.1'
>>> new = '1.1.1.2'
>>> change_ip(my_zone, old, new, publish=True)
This handles acquiring and ARecords under the provided zone and applying the changes as you’ve specified. Need to shift over a handful of ip addresses?
>>> from dyn.tm.zones import Zone
>>> from dyn.tm.tools import change_ip
>>> my_zone = Zone('example.com')
>>> old = ['1.1.1.1', '1.1.1.3', '1.1.1.5']
>>> new = ['1.1.1.2', '1.1.1.4', '1.1.1.6']
>>> change_ip(my_zone, old, new, publish=True)
Have IPv6 addresses you need to switch over?
>>> from dyn.tm.zones import Zone
>>> from dyn.tm.tools import change_ip
>>> my_zone = Zone('example.com')
>>> old = '::1'
>>> new = '2001:db8:85a3::8a2e:370:7334'
>>> change_ip(my_zone, old, new, v6=True, publish=True)
Don’t want to automatically publish, but rather wait and validate the changes manually?
>>> from dyn.tm.zones import Zone
>>> from dyn.tm.tools import change_ip
>>> my_zone = Zone('example.com')
>>> old = '1.1.1.1'
>>> new = '1.1.1.2'
>>> changeset = change_ip(my_zone, old, new)
>>> changeset
[(u'example.com.', u'1.1.1.1', u'1.1.1.2')]
4.7.2.2. map_ips¶
map_ips()
functions in basically the same manner as change_ip()
, the only difference
being that it accepts a dict with rules on mapping form one ip to another (as well
as the same v6 flag for specifying that you’re working ipv6 addresses.
>>> from dyn.tm.zones import Zone
>>> from dyn.tm.tools import map_ips
>>> my_zone = Zone('example.com')
>>> old = '1.1.1.1'
>>> new = '1.1.1.2'
>>> mapping = {old: new}
>>> map_ips(my_zone, mapping, publish=True)