Add a modify function to the floating ip dns api.

Removed the dns driver function rename_entry().  Since 'name'
is the unique identifier for an entry, trying to rename things
causes various confusions.  Better to leave the user to
delete and recreate.

For blueprint public-and-private-dns.

Change-Id: I766af01299b7b28ad8d9f6c072a8f3e049bd286b
This commit is contained in:
Andrew Bogott 2012-01-02 17:31:36 -06:00
parent 5165320257
commit 4c5586a28f
8 changed files with 87 additions and 27 deletions

View File

@ -115,6 +115,25 @@ Create a DNS entry:
Failure Response Code: 409 (indicates an entry with name & zone already exists.)
Change the ip address of an existing DNS entry:
PUT /v1.1/<tenant_id>/os-floating-ip-dns/<domain>
# Sample body:
{ 'dns_entry' :
{ 'name': 'instance1',
'ip': '192.168.53.99'}}
# Sample Response (success):
{ 'dns_entry' :
{ 'ip' : '192.168.53.99',
'name' : 'instance1',
'zone' : 'example.org'}}
Failure Response Code: 404 (Entry to be modified not found)
Find DNS entries for a given domain and name:
GET /v1.1/<tenant_id>/os-floating-ip-dns/<domain>?name=<name>

View File

@ -168,6 +168,28 @@ class FloatingIPDNSController(object):
'type': dns_type,
'zone': zone})
def update(self, req, id, body):
"""Modify a dns entry."""
context = req.environ['nova.context']
zone = _unquote_zone(id)
try:
entry = body['dns_entry']
name = entry['name']
new_ip = entry['ip']
except (TypeError, KeyError):
raise webob.exc.HTTPUnprocessableEntity()
try:
self.network_api.modify_dns_entry(context, name,
new_ip, zone)
except exception.NotFound:
return webob.Response(status_int=404)
return _translate_dns_entry_view({'ip': new_ip,
'name': name,
'zone': zone})
def delete(self, req, id):
"""Delete the entry identified by req and id. """
context = req.environ['nova.context']

View File

@ -220,6 +220,15 @@ class API(base.Base):
{'method': 'add_dns_entry',
'args': args})
def modify_dns_entry(self, context, name, address, dns_zone):
"""Create specified DNS entry for address"""
args = {'address': address,
'dns_name': name,
'dns_zone': dns_zone}
return rpc.call(context, FLAGS.network_topic,
{'method': 'modify_dns_entry',
'args': args})
def delete_dns_entry(self, context, name, zone):
"""Delete the specified dns entry."""
args = {'dns_name': name, 'dns_zone': zone}

View File

@ -28,9 +28,6 @@ class DNSDriver(object):
def delete_entry(self, _name, _dnszone=""):
pass
def rename_entry(self, _address, _name, _dnszone):
pass
def modify_address(self, _name, _address, _dnszone):
pass

View File

@ -462,6 +462,10 @@ class FloatingIP(object):
self.floating_dns_manager.create_entry(dns_name, address,
dns_type, dns_zone)
def modify_dns_entry(self, context, address, dns_name, dns_zone):
self.floating_dns_manager.modify_address(dns_name, address,
dns_zone)
def delete_dns_entry(self, context, dns_name, dns_zone):
self.floating_dns_manager.delete_entry(dns_name, dns_zone)

View File

@ -90,21 +90,11 @@ class MiniDNS(object):
if not deleted:
raise exception.NotFound
def rename_entry(self, address, name, dnszone):
infile = open(self.filename, 'r')
outfile = tempfile.NamedTemporaryFile('w', delete=False)
for line in infile:
entry = self.parse_line(line)
if entry and entry['address'] == address.lower():
outfile.write("%s %s %s\n" %
(address, self.qualify(name, dnszone), entry['type']))
else:
outfile.write(line)
infile.close()
outfile.close()
shutil.move(outfile.name, self.filename)
def modify_address(self, name, address, dnszone):
if not self.get_entries_by_name(name, dnszone):
raise exception.NotFound
infile = open(self.filename, 'r')
outfile = tempfile.NamedTemporaryFile('w', delete=False)
for line in infile:

View File

@ -75,6 +75,12 @@ def network_add_dns_entry(self, context, address, name, dns_type, zone):
'zone': zone}}
def network_modify_dns_entry(self, context, address, name, zone):
return {'dns_entry': {'name': name,
'ip': address,
'zone': zone}}
class FloatingIpDNSTest(test.TestCase):
def _create_floating_ip(self):
"""Create a floating ip object."""
@ -98,6 +104,8 @@ class FloatingIpDNSTest(test.TestCase):
network_api_get_floating_ip)
self.stubs.Set(network.api.API, "add_dns_entry",
network_add_dns_entry)
self.stubs.Set(network.api.API, "modify_dns_entry",
network_modify_dns_entry)
self.context = context.get_admin_context()
@ -183,6 +191,16 @@ class FloatingIpDNSTest(test.TestCase):
self.assertTrue(self.called)
self.assertEquals(self.deleted_zone, zone)
def test_modify(self):
body = {'dns_entry':
{'name': name,
'ip': testaddress2}}
req = fakes.HTTPRequest.blank('/v2/123/os-floating-ip-dns/%s' %
zone)
entry = self.dns_controller.update(req, zone, body)
self.assertEqual(entry['dns_entry']['ip'], testaddress2)
class FloatingIpDNSSerializerTest(test.TestCase):
def test_default_serializer(self):

View File

@ -305,21 +305,22 @@ class FlatNetworkTestCase(test.TestCase):
driver.create_entry("hostthree", "10.0.0.3", 0, zone1)
driver.create_entry("hostfour", "10.0.0.4", 0, zone1)
driver.create_entry("hostfive", "10.0.0.5", 0, zone2)
driver.create_entry("hostsix", "10.0.0.6", 0, zone2)
driver.delete_entry("hosttwo", zone1)
driver.rename_entry("10.0.0.3", "hostone", zone1)
driver.delete_entry("hostone", zone1)
driver.modify_address("hostfour", "10.0.0.1", zone1)
driver.modify_address("hostthree", "10.0.0.1", zone1)
names = driver.get_entries_by_address("10.0.0.1", zone1)
self.assertEqual(len(names), 2)
self.assertIn('hostone', names)
self.assertIn('hostthree', names)
self.assertIn('hostfour', names)
names = driver.get_entries_by_address("10.0.0.6", zone2)
names = driver.get_entries_by_address("10.0.0.5", zone2)
self.assertEqual(len(names), 1)
self.assertIn('hostsix', names)
addresses = driver.get_entries_by_name("hostone", zone1)
self.assertEqual(len(addresses), 2)
self.assertIn('10.0.0.1', addresses)
self.assertIn('10.0.0.3', addresses)
self.assertIn('hostfive', names)
addresses = driver.get_entries_by_name("hosttwo", zone1)
self.assertEqual(len(addresses), 1)
self.assertIn('10.0.0.2', addresses)
def test_instance_dns(self):
fixedip = '192.168.0.101'