Using Curl to Interact with Resource Records in Rackspace Cloud DNS

Using Curl to Interact with Resource Records in Rackspace Cloud DNS

In this article we will be using curl to interact with Rackspace’s Cloud DNS to manipulate resource records in zones which already exist.  For details on how to use curl against Rackspace’s Cloud DNS API please see part one in this series “Using Curl to Access Rackspace Cloud DNS” in part two I documented the creation of DNS zones “Using Curl to Interact with Zones in Rackspace Cloud DNS” please refer to these for the lead up to this article.

List All Records for a Zone

# curl -D - -H "X-Auth-Token: <your x-auth-token here>;" -H "Accept: application/xml" https://dns.api.rackspacecloud.com/v1.0/<your user number here>/domains/<your domain id here>/records

In case you aren’t sure your x-auth-token and your user number are given to you as part of the authentication process in the first part of the series.  You can get your domain id, by listing all the domains and reviewing the output, we went over this in the second part of the series.

List One Record With Detail

# curl -D - -H "X-Auth-Token: <your x-auth-token here>" -H "Accept: application/xml" https://dns.api.rackspacecloud.com/v1.0/<your user number here>/domains/<your domain id here>/records/&lt;your record id here&gt;

Create New Record(s)

# cat records.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recordsList xmlns:ns2="http://docs.rackspacecloud.com/dns/api/management/v1.0" xmlns="http://docs.rackspacecloud.com/dns/api/v1.0" xmlns:ns3="http://www.w3.org/2005/Atom">
<record type="A" name="www.itfromallangles.com" data="192.168.1.1"/>
<record type="A" name="www2.itfromallangles.com" data="192.168.1.2"/>
</recordsList>

Using the above XML format we can create as many records as we need, in the specified domain.

# curl -X POST -D - -H "X-Auth-Token: <your x-auth-token here>" -H "Accept: application/xml" -H "Content-Type: application/xml" -T records.xml https://dns.api.rackspacecloud.com/v1.0/<your user number here>/domains/<your domain id here>/records

Modify Existing Record(s)

# cat records-update.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recordsList xmlns:ns2="http://docs.rackspacecloud.com/dns/api/management/v1.0" xmlns="http://docs.rackspacecloud.com/dns/api/v1.0" xmlns:ns3="http://www.w3.org/2005/Atom">
<record type="A" name="www.itfromallangles.com" data="192.168.1.3"/>
</recordsList>

The XML we use is essentially the same as with the create, however here we reference a specific record in our curl command, so we can only define a single record in the XML.

# curl -X PUT -D - -H "X-Auth-Token: <your x-auth-token here>" -H "Accept: application/xml" -H "Content-Type: application/xml" -T records-update.xml https://dns.api.rackspacecloud.com/v1.0/<your user number here>/domains/<your domain id here>/records/&lt;your record id here&gt;

Delete Existing Record(s)

# curl -X DELETE -D - -H "X-Auth-Token: <your x-auth-token here>" -H "Accept: application/xml" -H "Content-Type: application/xml" https://dns.api.rackspacecloud.com/v1.0/<your user number here>/domains/<your domain id here>/records/&lt;your record id here&gt;

Combine this with part one and part two of this series and you will be able to appropriately manage your DNS infrastructure which is hosted (or soon might be) on Rackspace Cloud DNS.  There is more to know of course, importing and exporting zones, as well as some cool ways of limiting what data comes back when listing your domains and records, but this is all for now.  Enjoy.