In [2]:
import os
apikey = os.environ['GANDI_API_KEY']
if not apikey:
raise "api key NOT available"
In [26]:
import xmlrpc.client as rpc
#api = rpc.ServerProxy('https://rpc.gandi.net/xmlrpc/')
api = rpc.ServerProxy('https://rpc.ote.gandi.net/xmlrpc/')
api.account.info(apikey)
Out[26]:
In [29]:
[ x for x in api.system.listMethods() if x.startswith("") ]
try:
api.account.info("blahblah")
except rpc.Fault:
print("Failed...")
In [11]:
def gandi_record_to_ghdns(record):
return { 'name': record['name'],
'type': record['type'],
'value': record['value'],
'ttl': record['ttl'],
}
In [23]:
import yaml
def init_zone_files(rpc, apikey, basedir):
os.makedirs(os.path.join(basedir, "zones"))
zones = rpc.domain.zone.list(apikey)
for zone in zones:
if not zone['public']:
zone_id = zone['id']
name = zone['name']
records = rpc.domain.zone.record.list(apikey, zone_id, zone['version'])
records = [ gandi_record_to_ghdns(r) for r in records]
filename = "zones/%s.yml" % name
with open(filename, "w") as f:
f.write(yaml.dump(records, default_flow_style=False))
print("Wrote out zone file: ", filename)