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]:
{'credits': None,
 'date_credits_expiration': None,
 'products': None,
 'rating_enabled': True,
 'fullname': 'Jared BUNTING',
 'average_credit_cost': None,
 'handle': 'JB174-GANDI',
 'id': 7163,
 'resources': {'available': None,
  'expired': None,
  'granted': None,
  'used': None},
 'share_definition': None,
 'cycle_day': 1}

In [29]:
[ x for x in api.system.listMethods() if x.startswith("") ]
try:
    api.account.info("blahblah")
except rpc.Fault:
    print("Failed...")


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)