Skip to content

Commit

Permalink
Merge pull request #24 from Danamir/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Danamir authored May 22, 2021
2 parents c91a769 + e138537 commit 7371a27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config.ini-dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[api]
url = https://dns.api.gandi.net/api/v5
url = https://api.gandi.net/v5/livedns/
; Generate your Gandi API key via : https://account.gandi.net/en/users/<user>/security
key =

Expand Down
12 changes: 6 additions & 6 deletions dyn_gandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,33 @@ def livedns_handle(domain, ip, records):
if r_snap is None:
raise RuntimeWarning("Could not create snapshot." % domain)

snapshot_uuid = r_snap['uuid']
snapshot_id = r_snap['id']

if verbose:
print("Backup snapshot created, uuid: %s." % snapshot_uuid)
print("Backup snapshot created, id: %s." % snapshot_id)

# update DNS records
for rec in records:
try:
r_update = ldns.put_domain_record(domain=domain, record_name=rec['name'], record_type=rec['type'], value=ip, ttl=int(config['dns']['ttl']))
except Exception as e:
print(
"%s, Error: %s. Backup snapshot uuid: %s."
% (message, repr(e), snapshot_uuid),
"%s, Error: %s. Backup snapshot id: %s."
% (message, repr(e), snapshot_id),
file=sys.stderr,
)
raise e

if r_update is None:
message = "%s, Error when updating: %s/%s. Backup snapshot uuid: %s." % (message, rec['name'], rec['type'], snapshot_uuid)
message = "%s, Error when updating: %s/%s. Backup snapshot id: %s." % (message, rec['name'], rec['type'], snapshot_id)
return "ERROR", message

if verbose:
print("Updated record %s/%s from %s to %s" % (rec['name'], rec['type'], dns_ip, ip))
print("API response: %s" % json.dumps(r_update, indent=2))

# delete snapshot
ldns.delete_domain_snapshot(domain, uuid=snapshot_uuid)
ldns.delete_domain_snapshot(domain, sid=snapshot_id)
if verbose:
print("Backup snapshot deleted.")

Expand Down
8 changes: 4 additions & 4 deletions livedns_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _query_api(self, method, query, json_data=None):
url = "%s%s" % (self.url, urllib.parse.quote(query))

headers = {
"x-api-key": self.key,
"Authorization": "Apikey %s" % self.key,
"Accept": "application/json",
}

Expand Down Expand Up @@ -171,13 +171,13 @@ def post_domain_snapshot(self, domain, name=None):
}
return self._query_api(method="POST", query="domains/%s/snapshots" % domain, json_data=json_data)

def delete_domain_snapshot(self, domain, uuid):
def delete_domain_snapshot(self, domain, sid):
"""POST a domain snapshot.
:param str domain: The domain.
:param str uuid: The snapshot uuid.
:param str sid: The snapshot id.
:return: The API response, or ``None`` on error.
:rtype: dict|list|None
"""

return self._query_api(method="DELETE", query="domains/%s/snapshots/%s" % (domain, uuid))
return self._query_api(method="DELETE", query="domains/%s/snapshots/%s" % (domain, sid))

0 comments on commit 7371a27

Please sign in to comment.