Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 26, 2023
1 parent 4cf1c80 commit 2afcf5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
30 changes: 14 additions & 16 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_id = None
region = None
VERSION = '1.2.0b48'
VERSION = '1.2.0b49'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -629,34 +629,34 @@ def lambda_handler(
default_hostname = '-'.join(['ip'] + private_ip.split('.'))
if tag_data['option_zone'].valid:
if tag_data['option_name'].valid:
LOGGER.info("instance: %s, using tag_option hostname tag %s and tag_option zone tag %s.",
LOGGER.info("instance: %s, using tag_option.zone hostname %s and tag_option.zone zone %s.",
instance_id, tag_data['option_name'].hostname, tag_data['option_zone'].zonename)
f_hostname = tag_data['option_name'].hostname
f_zonename = tag_data['option_zone'].zonename
elif tag_data['name'].valid:
LOGGER.info("instance: %s, using tag_key Name hostname tag %s and tag_option zone tag %s.",
LOGGER.info("instance: %s, using tag_key.Name hostname %s and tag_option.zone zone %s.",
instance_id, tag_data['name'].hostname, tag_data['option_zone'].zonename)
f_hostname = tag_data['name'].hostname
f_zonename = tag_data['option_zone'].zonename
else:
LOGGER.info("instance: %s, using default ip-address %s for hostname and tag_option zone %s.",
LOGGER.info("instance: %s, using default ip-address %s for hostname and tag_option.zone zone %s.",
instance_id, default_hostname, tag_data['option_zone'].zonename)
f_hostname = default_hostname
f_zonename = tag_data['option_zone'].zonename

else:
if tag_data['option_name'].valid:
LOGGER.info("instance: %s, using tag_option hostname %s and and tag_option zone %s.",
LOGGER.info("instance: %s, using tag_option.name hostname %s and and tag_option.name zone %s.",
instance_id, tag_data['option_name'].hostname, tag_data['option_name'].zonename)
f_hostname = tag_data['option_name'].hostname
f_zonename = tag_data['option_name'].zonename
if not tag_data['option_name'].valid and tag_data['option_name'].hostname != '' and tag_data['dhcp_options'].valid:
LOGGER.info("instance: %s, using tag_option hostname %s and and dhcp_options zone %s.",
LOGGER.info("instance: %s, using tag_option.name hostname %s and and dhcp_options zone %s.",
instance_id, tag_data['option_name'].hostname, tag_data['dhcp_options'].zonename)
f_hostname = tag_data['option_name'].hostname
f_zonename = tag_data['dhcp_options'].zonename
elif tag_data['name'].valid:
LOGGER.info("instance: %s, using tag_key Name hostname %s and tag_key Name zone %s.",
LOGGER.info("instance: %s, using tag_key.Name hostname %s and tag_key.Name zone %s.",
instance_id, tag_data['name'].hostname, tag_data['name'].zonename)
f_hostname = tag_data['name'].hostname
f_zonename = tag_data['name'].zonename
Expand Down Expand Up @@ -788,7 +788,7 @@ def lambda_handler(
f"flags=noforward, not adding A and heritage TXT for host {final_private_hostname} zone {zone_data_forward.name} value {private_ip}")

if not flags['noreverse']:
fqdn = create_fqdn(final_private_hostname, final_hosted_zone_name)
# fqdn = create_fqdn(final_private_hostname, final_hosted_zone_name)
try:
if reverse_zone_associated:
create_response = create_resource_record(
Expand All @@ -798,10 +798,10 @@ def lambda_handler(
tag_data['ptr_entry'].hostname,
tag_data['ptr_entry'].zonename,
'PTR',
fqdn,
final_private_dns_name,
)
append_msg = f"PTR record in zone id: {zone_data_reverse.zone_id} owner {zone_data_reverse.owner_account} for hostname {tag_data['ptr_entry'].hostname} " + \
f"zone {tag_data['ptr_entry'].zonename} to value {fqdn}"
f"zone {tag_data['ptr_entry'].zonename} to value {final_private_dns_name}"
count[create_response] += 1
if create_response == 'success':
LOGGER.info("instance: %s, Created %s",
Expand Down Expand Up @@ -852,7 +852,7 @@ def lambda_handler(
instance_id, str(err) + lineno())
else:
LOGGER.info(
f"flags=noreverse, not adding PTR and heritage TXT for host {tag_data['ptr_entry'].hostname} zone {tag_data['ptr_entry'].zonename} value {fqdn}")
f"flags=noreverse, not adding PTR and heritage TXT for host {tag_data['ptr_entry'].hostname} zone {tag_data['ptr_entry'].zonename} value {final_private_dns_name}")

else: # not running so delete the records. Note this may leave orphans around if the flags are set and then the host is shut down. We may want to remove no matter what.
if not flags['noforward']:
Expand Down Expand Up @@ -883,7 +883,7 @@ def lambda_handler(
tag_data['ptr_entry'].hostname,
tag_data['ptr_entry'].zonename,
'PTR',
create_fqdn(final_private_hostname, final_hosted_zone_name),
final_private_dns_name,
heritage_value
)
# only true if existing delete_records and the delete_success from the subroutine is true
Expand Down Expand Up @@ -920,7 +920,7 @@ def lambda_handler(
cname_host_name,
cname_domain_suffix,
'CNAME',
create_fqdn(final_private_hostname, final_hosted_zone_name),
final_private_dns_name
)
append_msg = f"CNAME record in zone id: {cname_domain_suffix_id} owner {phz_collection_by_vpc[cname_domain_suffix]['owner_account']} " + \
f"hostname {cname_host_name} in zone {cname_domain_suffix} with value {final_private_dns_name}"
Expand Down Expand Up @@ -978,7 +978,7 @@ def lambda_handler(
cname_host_name,
cname_domain_suffix,
'CNAME',
create_fqdn(final_private_hostname, final_hosted_zone_name),
final_private_dns_name,
heritage_value
)

Expand Down Expand Up @@ -1520,8 +1520,6 @@ def new_change_resource_recordset(oclient, instance_id, zone_id, host_name, host

LOGGER.debug("Creating %s record %s in zone %s: %s",
record_type, host_name, hosted_zone_name, lineno())
# fqdn = host_name
# fqdn += '.' + hosted_zone_name if hosted_zone_name in host_name else ''

# retry to handle errors in the possible API call
while i < MAX_API_RETRY:
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit 2afcf5c

Please sign in to comment.