Skip to content

Commit

Permalink
Create records if not exist when syncing ip address.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Lin committed Mar 28, 2017
1 parent ed81970 commit e3878ab
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cloudflare_ddns/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,21 @@ def sync_dns_from_my_ip(self, dns_type='A'):
print('None of public ip finder is working. Please try later')
sys.exit(1)

record = self.get_record(dns_type, self.domain) \
if len(self.domain.split('.')) == 3 \
else self.get_record(dns_type, self.domain)

if record['content'] != ip_address:
self.update_record(dns_type, self.domain, ip_address)
print('Successfully updated IP address from {old_ip} to {new_ip}'
.format(old_ip=record['content'], new_ip=ip_address))
try:
record = self.get_record(dns_type, self.domain) \
if len(self.domain.split('.')) == 3 \
else self.get_record(dns_type, self.domain)
except RecordNotFound:
self.create_record(dns_type, self.domain, ip_address)
print('Successfully created new record with IP address {new_ip}'
.format(new_ip=ip_address))
else:
print('IP address on CloudFlare is same as your current address')
if record['content'] != ip_address:
self.update_record(dns_type, self.domain, ip_address)
print('Successfully updated IP address from {old_ip} to {new_ip}'
.format(old_ip=record['content'], new_ip=ip_address))
else:
print('IP address on CloudFlare is same as your current address')

@staticmethod
def process_json_for_cloudflare(data_dict):
Expand Down

0 comments on commit e3878ab

Please sign in to comment.