Skip to content

Commit

Permalink
auroradns: Implement iterator for zones and records
Browse files Browse the repository at this point in the history
By implementing iterate_zones() and iterate_records() you can
iterate over zones and records returned by the API.

The list_zones() and list_records() methods simply talk to the
iteration functions and create a list of it and return that.

The test cases should still match since they call the list functions
and those call the iterators on their turn.

The test case test_list_zones() however has been expanded to iterate
over the result.

The test_list_records case already iterated over the results, so that
verifies that the result is iteratable.
  • Loading branch information
wido committed Jul 5, 2016
1 parent 664bb34 commit d0f5c34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 8 additions & 9 deletions libcloud/dns/drivers/auroradns.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,23 @@ class AuroraDNSDriver(DNSDriver):
AuroraDNSHealthCheckType.TCP: 'TCP'
}

def list_zones(self):
zones = []

def iterate_zones(self):
res = self.connection.request('/zones')
for zone in res.parse_body():
zones.append(self.__res_to_zone(zone))
yield self.__res_to_zone(zone)

return zones
def list_zones(self):
return list(self.iterate_zones())

def list_records(self, zone):
def iterate_records(self, zone):
self.connection.set_context({'resource': 'zone', 'id': zone.id})
records = []
res = self.connection.request('/zones/%s/records' % zone.id)

for record in res.parse_body():
records.append(self.__res_to_record(zone, record))
yield self.__res_to_record(zone, record)

return records
def list_records(self, zone):
return list(self.iterate_records(zone))

def get_zone(self, zone_id):
self.connection.set_context({'resource': 'zone', 'id': zone_id})
Expand Down
2 changes: 2 additions & 0 deletions libcloud/test/dns/test_auroradns.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def test_res_to_record(self):
def test_list_zones(self):
zones = self.driver.list_zones()
self.assertEqual(len(zones), 2)
for zone in zones:
self.assertTrue(zone.domain.startswith('auroradns'))

def test_create_zone(self):
zone = self.driver.create_zone('example.com')
Expand Down

0 comments on commit d0f5c34

Please sign in to comment.