#1 2013-03-25 20:17:40

bsd
Member
Registered: 2013-03-25
Posts: 3

linode api's python bindings

Just a short blog post:

Thanks to @linode‘s API and @tjfontaine & co’s linode-python api tool, there’s now an quick and easy way to programmatically manage the many services offered by Linode.

You’ll want to grab pycurl first: sudo pip install pycurl

Check out the official Linode API Documentation first, to make sure you know what does what.

I use Linode’s nameservers as slaves to my hidden master NSD3 server, and I’ve got a bunch of active zones that need updating. All of the domains that need to be migrated have the same MASTER_IPS value, let’s use 127.0.0.1 for example.

Let’s take a look at what the output looks like for each domain request:

    from linode import api
    linode = api.Api('topsekritkey')
     
    for domain in linode.domain_list():
    print domain

This outputs something like:


{u'STATUS': 1, u'RETRY_SEC': 0, u'DOMAIN': u'example.com', u'DOMAINID': 1337, u'DESCRIPTION': u'', u'MASTER_IPS': u'1.2.3.4;', u'SOA_EMAIL': u'', u'AXFR_IPS': u'1.2.3.4;', u'REFRESH_SEC': 0, u'TYPE': u'slave', u'EXPIRE_SEC': 0, u'TTL_SEC': 0}
{u'STATUS': 1, u'RETRY_SEC': 0, u'DOMAIN': u'example.net', u'DOMAINID': 1338, u'DESCRIPTION': u'', u'MASTER_IPS': u'1.2.3.4;', u'SOA_EMAIL': u'', u'AXFR_IPS': u'1.2.3.4;', u'REFRESH_SEC': 0, u'TYPE': u'slave', u'EXPIRE_SEC': 0, u'TTL_SEC': 0}
...

So on and so forth.

If the domain is of the type ‘slave’, then I’ll want to grab that domain’s ID number, and then update that domain’s MASTER_IPS value to my new master, 127.0.0.1.

    from linode import api
    linode = api.Api('topsekritkey')
     
    for domain in linode.domain_list(): # for each domain entry in the list,
    if domain['TYPE'] == 'slave': # check if the domain is a slave entry, as I have some master entries mixed in,
    targetID = domain['DOMAINID'] # grab the domain ID,
    linode.domain_update(DomainID=targetID, MASTER_IPS='127.0.0.1') # update the MASTERS_IPS value for $DomainID,
    print domain # look pretty sorta.

That quick and dirty snippet should do the trick.

Here are all the api actions available from tjfontaine‘s linode-python api tool:

Offline

Board footer

Powered by FluxBB