Skip to content

Commit

Permalink
prep with new_ reverse routines
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Feb 25, 2022
1 parent b9253db commit 571303b
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
LOGGER = logging.getLogger()
ACCOUNT = None
REGION = None
VERSION = '0.1.17'
VERSION = '0.1.18'

# Adjust the logging level [logging.INFO, logging.DEBUG, logging.WARNING, etc]
LOGGER.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -1470,6 +1470,38 @@ def get_dhcp_configurations(client, dhcp_options_id):
LOGGER.info("unexpected error. %s\n", str(sys.exc_info()[0]) + lineno())


def new_reverse_list(ip_list):
"""
Reverses the order of the instance's IP address and helps construct the reverse lookup zone name.
:param str ip_list: IPv4 address to reverse
:return str: Returns a string in the PTR format
"""
try:
ip = ipaddress.ip_address(ip_list)
reversed_list = ip.reverse_pointer
LOGGER.debug("returning: %s", str(reversed_list) + lineno())
except:
LOGGER.info("unexpected error. %s\n", str(sys.exc_info()[0]) + lineno())
return None

np = '.'.join(p.split('.')[1:])


def new_reverse_domain(ip_list):
"""
Reverses the order of the instance's IP address and helps construct the reverse lookup zone name.
:param str ip_list: IPv4 address to reverse
:return str: Returns a string in the PTR format of the subnet (/24 boundary)
"""
try:
ip = ipaddress.ip_address(ip_list)
reversed_list = '.'.join(ip.reverse_pointer.split('.')[1:])
LOGGER.debug("returning: %s", str(reversed_list) + lineno())
except:
LOGGER.info("unexpected error. %s\n", str(sys.exc_info()[0]) + lineno())
return None


def reverse_list(ip_list):
"""
Reverses the order of the instance's IP address and
Expand Down Expand Up @@ -1730,17 +1762,3 @@ def parse_heritage(info):
return kv_results
except:
return {}

# heritage examples to incorporate
# h=initialize_heritage('dynr53','0.0.9')
# pprint(h)
# add_heritage_item(h,'instance_id','i-123123123123')
# add_heritage_item(h,'account_id','123123123123')
# add_heritage_item(h,'region','west')
# add_heritage_item_timestamp(h,'create_time')
# txt=format_heritage(h)
# print(txt)
# nh=parse_heritage(txt)
# print(dump_heritage(nh))
# nh=parse_heritage('bob'+txt)
# print(dump_heritage(nh))

0 comments on commit 571303b

Please sign in to comment.