From ca7d6f61c800560525b6acfeb800e850b56cd8ef Mon Sep 17 00:00:00 2001 From: "H. Wade Minter" Date: Wed, 30 Jan 2013 21:01:52 -0500 Subject: [PATCH 1/2] Add initial support for pulling in >100 zones via Zones.each. Uses the hypermedia links returned by the response body to determine whether or not there are more results available. --- lib/fog/rackspace/models/dns/zones.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/fog/rackspace/models/dns/zones.rb b/lib/fog/rackspace/models/dns/zones.rb index 38b00e4f8..74a50f854 100644 --- a/lib/fog/rackspace/models/dns/zones.rb +++ b/lib/fog/rackspace/models/dns/zones.rb @@ -22,6 +22,28 @@ module Fog data = service.list_domains(:name => substring).body['domains'] load(data) end + + alias :each_zone_this_page :each + def each + if !block_given? + self + else + body = service.list_domains.body + subset = load(body['domains']) + + subset.each_zone_this_page {|f| yield f} + while !body['links'].select{|l| l['rel'] == 'next'}.empty? + url = body['links'].select{|l| l['rel'] == 'next'}.first['href'] + query = url.match(/\?(.+)/) + parsed = CGI.parse($1) + + body = service.list_domains(:offset => parsed['offset'], :limit => parsed['limit']).body + subset = load(body['domains']) + subset.each_zone_this_page {|f| yield f} + end + self + end + end def get(zone_id) if zone_id.nil? or zone_id.to_s.empty? From d35e389f0257cd3b17563908b553a7a354cc556f Mon Sep 17 00:00:00 2001 From: "H. Wade Minter" Date: Thu, 31 Jan 2013 17:55:04 -0500 Subject: [PATCH 2/2] Get rid of the extra load() calls. --- lib/fog/rackspace/models/dns/zones.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/rackspace/models/dns/zones.rb b/lib/fog/rackspace/models/dns/zones.rb index 74a50f854..21b070b89 100644 --- a/lib/fog/rackspace/models/dns/zones.rb +++ b/lib/fog/rackspace/models/dns/zones.rb @@ -8,9 +8,9 @@ module Fog model Fog::DNS::Rackspace::Zone - def all + def all(options={}) clear - data = service.list_domains.body['domains'] + data = service.list_domains(options).body['domains'] load(data) end @@ -29,7 +29,7 @@ module Fog self else body = service.list_domains.body - subset = load(body['domains']) + subset = dup.all subset.each_zone_this_page {|f| yield f} while !body['links'].select{|l| l['rel'] == 'next'}.empty? @@ -38,7 +38,7 @@ module Fog parsed = CGI.parse($1) body = service.list_domains(:offset => parsed['offset'], :limit => parsed['limit']).body - subset = load(body['domains']) + subset = dup.all(:offset => parsed['offset'], :limit => parsed['limit']) subset.each_zone_this_page {|f| yield f} end self