Recently I was looking to obtain a couple specific DNS record ID’s for domains with DNS hosted in the RackSpace Cloud so I could use the information to interact with RackSpace Instances through RightScale. Various RightScale ServerTemplates such as the MySQL Cluster ServerTemplates require you to enter the exact DNS record ID as RightScale Inputs for the ServerTemplate. I am not sure why the record ID’s are not listed in a column in the RackSpace Cloud DNS management interface but regardless the below method of querying the RackSpace API make it fairly easy to obtain them regardless.
Steps To Obtain A RackSpace Hosted Domain A Record ID:
To accomplish this you need to have curl installed on your computer and have your RackSpace API key, username, and account ID handy. I was using a terminal window on OSX Mountain Lion in the example outputs below.
Obtain RackSpace Auth Token:
- Alexs-MacBook-Pro:~ alex$ curl -D - -H "X-Auth-Key: RACKSPACE-API-KEY-HERE" -H "X-Auth-User: RACKSPACE-USERNAME-HERE" https://auth.api.rackspacecloud.com/v1.0
- HTTP/1.1 204 No Content
- Server: Apache/2.2.3 (Red Hat)
- vary: X-Auth-User,X-Auth-Key,X-Storage-User,X-Storage-Pass
- X-Storage-Url: https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_XXXXXXX-XXXX-XXXX-XXXXXXXX
- Cache-Control: s-maxage=52554
- Content-Type: text/xml
- Date: Sat, 10 Nov 2012 00:47:46 GMT
- X-Auth-Token: AUTH-TOKEN-OUTPUT-HERE
- X-Server-Management-Url: https://servers.api.rackspacecloud.com/v1.0/ACCOUNT-ID-OUTPUT-HERE
- X-Storage-Token: XXXXXXXX-XXXX-XXXX-XXXXXXXX
- Connection: Keep-Alive
- X-CDN-Management-Url: https://cdn1.clouddrive.com/v1/MossoCloudFS_XXXXXXXX-XXXX-XXXX-XXXXXXXX
- Content-Length: 0
- Alexs-MacBook-Pro:~ alex$
The items to pay attention to in the above example include the curl command itself, RACKSPACE-API-KEY-HERE, RACKSPACE-USERNAME-HERE, AUTH-TOKEN-OUTPUT-HERE, and ACCOUNT-ID-OUTPUT-HERE. To receive valid output via authentication to the RackSpace Cloud API the RackSpace API key and RackSpace username are required. Once you have issued the command you will receive output with two details we need to keep handy which include the Auth Token (provides temporary authorization to the RackSpace Cloud API) and the RackSpace account ID (is the number identifying your RackSpace account). Once you have successfully issued the command and obtained the information needed move on to the next step which will be to list the domains hosted in the RackSpace Cloud and are associated to your account.
List Your RackSpace Accounts Domain ID’s:
- Alexs-MacBook-Pro:~ alex$ curl -D - -H "X-Auth-Token: AUTH-TOKEN-HERE" -H "Accept: application/xml" https://dns.api.rackspacecloud.com/v1.0/ACCOUNT-ID-HERE/domains
- HTTP/1.1 200 OK
- Date: Sat, 10 Nov 2012 00:51:23 GMT
- Content-Length: 414
- X-API-VERSION: 1.0.21
- Content-Type: application/xml
- Server: Jetty(8.0.y.z-SNAPSHOT)
- <?xml version='1.0' encoding='UTF-8'?><ns2:domains xmlns:ns3="http://www.w3.org/2005/Atom" xmlns:ns2="http://docs.rackspacecloud.com/dns/api/v1.0" xmlns="http://docs.rackspacecloud.com/dns/api/management/v1.0" totalEntries="1"><ns2:domain id="RACKSPACE-DOMAIN-ID-OUTPUT-HERE" accountId="ACCOUNT-ID-OUTPUT-HERE" name="DOMAIN-NAME-OUTPUT-HERE" emailAddress="ipadmin@stabletransit.com" updated="2012-11-09T21:52:23Z" created="2012-06-30T20:22:57Z"/></ns2:domains>
- Alexs-MacBook-Pro:~ alex$
Now in the above output we have obtained a list of domains associated to your account which in the above example totals one. We now need to use the RACKSPACE-DOMAIN-ID-OUTPUT-HERE output to query the RackSpace Cloud API one more time and obtain a list of the records associated to the domain where you need to locate the record ID’s as shown in the below example output. We will again be using the same Auth Token, your RackSpace account ID, and now the domain ID.
List RackSpace Cloud DNS Records Associated To A Domain ID’s:
- Alexs-MacBook-Pro:~ alex$ curl -D - -H "X-Auth-Token: AUTH-TOKEN-HERE" -H "Accept: application/xml" https://dns.api.rackspacecloud.com/v1.0/ACCOUNT-ID-HERE/domains/DOMAIN-ID-HERE/records
- HTTP/1.1 200 OK
- Date: Sat, 10 Nov 2012 01:20:05 GMT
- Content-Length: 2667
- X-API-VERSION: 1.0.21
- Content-Type: application/xml
- Server: Jetty(8.0.y.z-SNAPSHOT)
- <?xml version='1.0' encoding='UTF-8'?><ns2:recordsList xmlns:ns3="http://www.w3.org/2005/Atom" xmlns:ns2="http://docs.rackspacecloud.com/dns/api/v1.0" xmlns="http://docs.rackspacecloud.com/dns/api/management/v1.0" totalEntries="14"><ns2:record id="A-93XXXX" type="A" name="sub1.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T21:13:46Z" created="2012-10-29T17:27:49Z"/><ns2:record id="A-932XXXX" type="A" name="sub2.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-29T22:32:12Z" created="2012-10-29T17:28:16Z"/><ns2:record id="A-932XXXX" type="A" name="sub3.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-29T22:42:41Z" created="2012-10-29T22:32:57Z"/><ns2:record id="A-932XXXX" type="A" name="sub4.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-11T12:42:25Z" created="2012-10-10T18:17:11Z"/><ns2:record id="A-932XXXX" type="A" name="sub5.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-11T12:42:35Z" created="2012-10-10T18:18:10Z"/><ns2:record id="A-932XXXX" type="A" name="sub6.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-11T12:42:54Z" created="2012-10-10T18:19:33Z"/><ns2:record id="A-932XXXX" type="A" name="sub7.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T20:51:57Z" created="2012-10-13T20:51:36Z"/><ns2:record id="A-932XXXX" type="A" name="sub8.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T21:11:19Z" created="2012-10-13T20:52:52Z"/><ns2:record id="A-932XXXX" type="A" name="sub9.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T20:53:28Z" created="2012-10-13T20:53:28Z"/><ns2:record id="A-932XXXX" type="A" name="sub10.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T20:53:47Z" created="2012-10-13T20:53:47Z"/><ns2:record id="A-932XXXX" type="A" name="sub11.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T20:57:09Z" created="2012-10-13T20:54:11Z"/><ns2:record id="A-932XXXX" type="A" name="sub12.domain-name-rackspace.com" data="192.168.1.1" ttl="300" updated="2012-10-13T21:52:23Z" created="2012-10-13T21:52:23Z"/><ns2:record id="NS-78XXXXX" type="NS" name="domain-name-rackspace.com" data="dns1.stabletransit.com" ttl="3600" updated="2012-06-30T20:22:57Z" created="2012-06-30T20:22:57Z"/><ns2:record id="NS-78XXXXX" type="NS" name="domain-name-rackspace.com" data="dns2.stabletransit.com" ttl="3600" updated="2012-06-30T20:22:57Z" created="2012-06-30T20:22:57Z"/></ns2:recordsList></ns2:recordsList>
- Alexs-MacBook-Pro:~ alex$
While the above output is not pretty if you are viewing this from a terminal window it does provide the data necessary. If you are wondering why there are more records output that you have entered into the RackSpace DNS management GUI it is likely because the name server records are going to be entered by default. The number you need is preceded by “record id” and in the above example output starts with A-93. The real DNS entry record ID will be something like A-1234567 and when using somewhere like the RightScale inputs make sure you keep the A- portion of the ID intact.
There you have it! The RackSpace Cloud API is powerful and will allow you to pull all sorts of information quickly if you become familiar with it.