-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dns-edit): update to new cloudflare module
- Loading branch information
Showing
1 changed file
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
import CloudFlare | ||
from cloudflare import Cloudflare | ||
import os | ||
from configparser import ConfigParser | ||
import sys | ||
|
||
if len(sys.argv) != 4: | ||
raise ValueError("Usage: dns-edit IPV4 IPV6 NAME") | ||
|
||
cf = CloudFlare.CloudFlare() | ||
zone = cf.zones.get(params={"name": "weblate.cloud"})[0] | ||
zone_id = zone["id"] | ||
zone_name = zone["name"] | ||
print("editing zone_id=%s zone_name=%s" % (zone_id, zone_name)) | ||
cp = ConfigParser() | ||
cp.read([os.path.expanduser("~/.cloudflare/cloudflare.cfg")]) | ||
token = cp.get("Cloudflare", "token") | ||
|
||
cf.zones.dns_records.post( | ||
zone_id, | ||
data={"name": sys.argv[3], "type": "A", "content": sys.argv[1]}, | ||
cf = Cloudflare(api_token=token) | ||
zone = cf.zones.list(name="weblate.cloud").result[0] | ||
print("editing zone_id=%s zone_name=%s" % (zone.id, zone.name)) | ||
|
||
cf.dns.records.create( | ||
zone_id=zone.id, | ||
name=sys.argv[3], | ||
type="A", | ||
content=sys.argv[1], | ||
) | ||
cf.zones.dns_records.post( | ||
zone_id, | ||
data={"name": sys.argv[3], "type": "AAAA", "content": sys.argv[2]}, | ||
cf.dns.records.create( | ||
zone_id=zone.id, | ||
name=sys.argv[3], | ||
type="AAAA", | ||
content=sys.argv[2], | ||
) |