Automating the ChunkHost DNS

Image

I’ve been using ChunkHost for the past few months. They are a VPS provider and are very cheap, their customer service is excellent and today I was informed about a nascent API for controlling your chunk’s DNS.

This is a really nice tool that they’re releasing, as it allows everything my upcoming project will do, to be automated, which is always nice. If you’ve not checked them out, take a look (disclaimer: this is my referral link).

How do I get started?

So if you’re like me, you’ve never actually seen this page. This is one of the key pages as it’s where we get our data about the domains that we control.

Getting the domain list

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ https://chunkhost.com/domains/

This will get our list of domains that we can can edit, and give us a useable id to use.
[{“domain”:{“name”:”chunkhost.com”,”id”:214305242}}]

Creating a domain

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ -H ‘Content-type: application/json’ –data ‘{“domain”:{“name”:”hi-there.com”}}’ -X POST https://chunkhost.com/domains/

On successfully creating a domain, we will get a 201 response with the value of;
{“domain”:{“name”:”hi-there.com”,”id”:712479003}}

Deleting a domain

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ -X DELETE https://chunkhost.com/domains/214305242

This will (presumably, I haven’t checked and I wasn’t told) delete a domain, if you can believe the title and the -X DELETE parameter.
{“domain”:{“name”:”hi-there.com”,”id”:712479003}}

Get the record listings for a domain (use the id from above)

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ https://chunkhost.com/domains/214305242/records

Gather all of the record listings for a domain using the ID that we either retrieved or created previously. This is our result.
[{“record”:{“name”:null,”kind”:”MX”,”ttl”:3600,”fqdn”:”chunkhost.com”,”priority”:10,
“domain_id”:214305242,”id”:905392221,”content”:”ASPMX.L.GOOGLE.COM.”}},{“record”:
{“name”:null,”kind”:”A”,”ttl”:3600,”fqdn”:”chunkhost.com”,”priority”:10,
“domain_id”:214305242,”id”:71605086,”content”:”72.34.254.3″}}]

Creating a record (with post)

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ -H ‘Content-type: application/json’ –data ‘{“record”:{“name”:”some_new_subdomain”,”kind”:”TXT”,”content”:”Hey fancypants!”}}’ -X POST https://chunkhost.com/domains/712479003/records/

This will allow us to create a record for the domain we are using, we can specify the canonical name, the type of the record (CNAME, TXT, MX, PTR, SPF, A, AAAA etc), and the content.
{“record”:{“name”:”some_new_subdomain”,”kind”:”TXT”,”ttl”:3600,”fqdn”:”some_new_subdomain.hi-there.com”,”priority”:10,”domain_id”:712479003,”id”:1022740758,”content”:”Hey fancypants!”}}

Updating a record (With PUT)

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ -H ‘Content-type: application/json’ –data ‘{“record”:{“kind”:”CNAME”,”content”:”htorry.wordpress.com”}}’ -X PUT https://chunkhost.com/domains/214305242/records/932868131

This will update the record that you specify (record 932868131 on the domain 214305242) so that all of your web traffic will be routed to my blog. Not a bad trade, my knowledge for your users?

Deleting a record (with delete)

curl -u ‘your-email@example.com:yourpasswordhere’ -H ‘Accept: application/json’ -X DELETE https://chunkhost.com/domains/214305242/records/1022740751

Simply delete a record (not a domain), it doesn’t get any simpler than that.

Official Documentation

There is currently no official documentation, although once the api matures it will be released – I’ll blog about it, and ChunkHost will tweet/blog about it.

Upcoming Features

Rumour has it that there may possibly be authentication keys involved, allowing you to give people only certain control to portions of your server. Pesky clients want their mail server updated? Well now they can do it themselves!

Disclaimer: This api is subject to change thus making this post incorrect. It is correct as of 30/10/2013. All information was given by Nate@ChunkHost.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s