Skip to content

Commit 2676fe5

Browse files
committed
added reverse-dns capabilities for cloud servers
1 parent 2461704 commit 2676fe5

File tree

4 files changed

+159
-4
lines changed

4 files changed

+159
-4
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ You'll find the complete documentation on the shell by running ``rackdns help``:
4646
domain-modify Modify a domain.
4747
domain-show Show details about the given domain
4848
limits List all applicable limits.
49+
rdns-create Add a reverse DNS record to the specified domain.
50+
rdns-delete Remove one or all PTR records associated with a
51+
Rackspace Cloud device. Use the optional ip parameter
52+
to specify a specific record to delete. Omitting this
53+
parameter removes all PTR records associated with the
54+
specified device.
55+
rdns-list List all PTR records configured for the specified
56+
Cloud Server.
57+
rdns-modify Modify a reverse DNS record to the specified domain.
4958
record-create Add new record to the specified domain.
5059
record-delete Delete a record of the specified domain.
5160
record-list Print a list of records for the given domain.

dnsclient/v1_0/records.py

+66-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,28 @@ def create(self, args, domainId):
7373
"priority" : args.priority
7474
} ]
7575
}
76-
return self._create_async('/domains/%s/records' % base.getid(domainId), body, return_raw=False, response_key="")
76+
url = '/domains/%s/records' % base.getid(domainId)
77+
78+
if args.type == "PTR":
79+
url = '/rdns'
80+
body = {
81+
"recordsList" : {
82+
"records" : [ {
83+
"name" : args.name,
84+
"comment" : args.comment,
85+
"ttl" : int(args.ttl),
86+
"type" : args.type,
87+
"data" : args.data
88+
} ]
89+
},
90+
"link" : {
91+
"content" : "",
92+
"href" : args.server_href,
93+
"rel" : "cloudServersOpenStack"
94+
}
95+
}
96+
97+
return self._create_async(url, body, return_raw=False, response_key="")
7798

7899
def modify(self, args, domainId):
79100
"""
@@ -98,7 +119,30 @@ def modify(self, args, domainId):
98119
"data" : args.data,
99120
"priority" : args.priority
100121
}
101-
return self._update('/domains/%s/records/%s' % (base.getid(domainId), base.getid(args.record_id)) , body, return_raw=False, response_key="")
122+
url = '/domains/%s/records/%s' % (base.getid(domainId), base.getid(args.record_id))
123+
124+
if hasattr(args, 'type'):
125+
if args.type == "PTR":
126+
url = '/rdns'
127+
body = {
128+
"recordsList" : {
129+
"records" : [ {
130+
"name" : args.name,
131+
"id" : args.record_id,
132+
"comment" : args.comment,
133+
"ttl" : int(args.ttl),
134+
"type" : args.type,
135+
"data" : args.data
136+
} ]
137+
},
138+
"link" : {
139+
"content" : "",
140+
"href" : args.server_href,
141+
"rel" : "cloudServersOpenStack"
142+
}
143+
}
144+
145+
return self._update(url, body, return_raw=False, response_key="")
102146

103147
def delete(self, domainId, recordId):
104148
"""
@@ -108,3 +152,23 @@ def delete(self, domainId, recordId):
108152
:param recordId: The ID of the :class:`Record` to delete.
109153
"""
110154
self._delete("/domains/%s/records/%s" % (base.getid(domainId), base.getid(recordId)))
155+
156+
def rdns_list(self, href):
157+
"""
158+
List all PTR records configured for the specified Cloud device.
159+
160+
:param href: The href of the device to get .
161+
:rtype: :class:`Record`
162+
"""
163+
return self._list("/rdns/cloudServersOpenStack?href=%s" % href, "records")
164+
165+
def rdns_delete(self, href, ip):
166+
"""
167+
Remove one or all PTR records associated with a Rackspace Cloud device.
168+
Use the optional ip query parameter to specify a specific record to delete.
169+
Omitting this parameter removes all PTR records associated with the specified device.
170+
171+
:param href: The ID of the device to delete.
172+
:param ip: The ip of the specific record to delete.
173+
"""
174+
self._delete("/rdns/cloudServersOpenStack?href=%s&ip=%s" % (href, ip))

dnsclient/v1_0/shell.py

+83-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def do_record_list(cs, args):
117117
utils.print_list(record_list, columns)
118118

119119
@utils.arg('domain',
120-
metavar='name',
120+
metavar='domain',
121121
help="Specifies the domain or subdomain. Must be a valid existing domain (example.com)")
122122
@utils.arg('--name',
123123
metavar='<name>',
@@ -190,3 +190,85 @@ def do_record_delete(cs, args):
190190
"""Delete a record of the specified domain."""
191191
domainId = utils.find_resource(cs.domains, args.domain)
192192
cs.records.delete(domainId, args.record_id)
193+
194+
@utils.arg('domain',
195+
metavar='domain',
196+
help="Specifies the domain or subdomain. Must be a valid existing domain (example.com)")
197+
@utils.arg('--name',
198+
metavar='<name>',
199+
required=True,
200+
help="The full name of the new record (ftp.example.com)")
201+
@utils.arg('--data',
202+
metavar='<data>',
203+
required=True,
204+
help="The data field, must be a valid IPv4 or IPv6 IP address")
205+
@utils.arg('--server-href',
206+
metavar='<server_href>',
207+
required=True,
208+
help="The link to the Rackspace Cloud Server that this will reference.")
209+
@utils.arg('--ttl',
210+
default=3600,
211+
metavar='<ttl>',
212+
help="If specified, must be greater than 300. The default value, if not specified, is 3600.")
213+
@utils.arg('--comment',
214+
default=None,
215+
metavar='<comment>',
216+
help="If included, its length must be less than or equal to 160 characters.")
217+
def do_rdns_create(cs, args):
218+
"""Add a reverse DNS record to the specified domain."""
219+
args.priority = None
220+
args.type = "PTR"
221+
do_record_create(cs, args)
222+
223+
@utils.arg('href',
224+
metavar='href',
225+
help="The link to the Rackspace Cloud Server that this will reference.")
226+
def do_rdns_list(cs, args):
227+
"""List all PTR records configured for the specified Cloud Server."""
228+
record_list = cs.records.rdns_list(args.href)
229+
columns = ['ID', 'Name', 'Type', "Data", "TTL", "Comment"]
230+
utils.print_list(record_list, columns)
231+
232+
@utils.arg('domain',
233+
metavar='domain',
234+
help="Specifies the domain or subdomain. Must be a valid existing domain (example.com)")
235+
@utils.arg('--record-id',
236+
metavar='<record_id>',
237+
required=True,
238+
help="The id of the PTR record to modify.")
239+
@utils.arg('--name',
240+
metavar='<name>',
241+
required=True,
242+
help="The full name of the new record (ftp.example.com)")
243+
@utils.arg('--data',
244+
metavar='<data>',
245+
required=True,
246+
help="The data field, must be a valid IPv4 or IPv6 IP address")
247+
@utils.arg('--server-href',
248+
metavar='<server_href>',
249+
required=True,
250+
help="The link to the Rackspace Cloud Server that this will reference.")
251+
@utils.arg('--ttl',
252+
default=3600,
253+
metavar='<ttl>',
254+
help="If specified, must be greater than 300. The default value, if not specified, is 3600.")
255+
@utils.arg('--comment',
256+
default=None,
257+
metavar='<comment>',
258+
help="If included, its length must be less than or equal to 160 characters.")
259+
def do_rdns_modify(cs, args):
260+
"""Modify a reverse DNS record to the specified domain."""
261+
args.priority = None
262+
args.type = "PTR"
263+
do_record_modify(cs, args)
264+
265+
@utils.arg('href',
266+
metavar='href',
267+
help="The link to the Rackspace Cloud Server that this will reference.")
268+
@utils.arg('--ip',
269+
metavar='<ip>',
270+
default="",
271+
help="Use the optional ip parameter to specify a specific record to delete. Omitting this parameter removes all PTR records associated with the specified device.")
272+
def do_rdns_delete(cs, args):
273+
"""Remove one or all PTR records associated with a Rackspace Cloud device. Use the optional ip parameter to specify a specific record to delete. Omitting this parameter removes all PTR records associated with the specified device."""
274+
cs.records.rdns_delete(args.href, args.ip)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def read_file(file_name):
3636
#test_suite="nose.collector",
3737
cmdclass=setup.get_cmdclass(),
3838
classifiers=[
39-
"Development Status :: 5 - Production/Stable",
39+
"Development Status :: 4 - Beta",
4040
"Environment :: Console",
4141
"Intended Audience :: Developers",
4242
"Intended Audience :: Information Technology",

0 commit comments

Comments
 (0)