2011-08-27 22:06:46 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-29 10:37:01 -05:00
|
|
|
require 'fog/rackspace/models/dns/zone'
|
2011-08-27 22:06:46 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module DNS
|
|
|
|
class Rackspace
|
|
|
|
class Zones < Fog::Collection
|
2013-06-19 11:06:06 -05:00
|
|
|
attribute :total_entries, :aliases => "totalEntries"
|
|
|
|
|
2011-08-27 22:06:46 -04:00
|
|
|
model Fog::DNS::Rackspace::Zone
|
|
|
|
|
2013-03-13 09:35:12 +01:00
|
|
|
# List all domains. Return by default a maximum of 100 items
|
2014-02-19 12:30:59 +00:00
|
|
|
# @param [Hash] options Options to pass to the underlying API call
|
2013-03-13 09:35:12 +01:00
|
|
|
# @option options [String] :name search for domains containing the given substring
|
|
|
|
# @option options [Integer] :limit number of records to return
|
|
|
|
# @option options [Integer] :offset starting offset of records to return
|
2013-01-31 17:55:04 -05:00
|
|
|
def all(options={})
|
2011-08-27 22:06:46 -04:00
|
|
|
clear
|
2013-06-19 11:06:06 -05:00
|
|
|
body = service.list_domains(options).body
|
|
|
|
merge_attributes(body)
|
|
|
|
|
|
|
|
load(body['domains'])
|
2011-08-27 22:06:46 -04:00
|
|
|
end
|
2014-02-19 12:30:59 +00:00
|
|
|
|
2013-01-30 21:01:52 -05:00
|
|
|
alias :each_zone_this_page :each
|
|
|
|
def each
|
2013-06-18 12:42:35 -05:00
|
|
|
return self unless block_given?
|
|
|
|
|
2013-06-20 08:39:14 -05:00
|
|
|
params = { :limit => 100} # prime loop (100 Records is default page size for Rackspace Cloud)
|
2013-06-18 12:42:35 -05:00
|
|
|
while params
|
|
|
|
body = service.list_domains(params).body
|
|
|
|
subset = dup.load(body["domains"])
|
2013-06-19 11:06:06 -05:00
|
|
|
self.merge_attributes(body)
|
|
|
|
|
2013-06-18 12:42:35 -05:00
|
|
|
params = next_params(body)
|
|
|
|
|
|
|
|
subset.each_zone_this_page {|zone| yield zone}
|
2013-01-30 21:01:52 -05:00
|
|
|
end
|
2013-06-18 12:42:35 -05:00
|
|
|
self
|
2013-01-30 21:01:52 -05:00
|
|
|
end
|
2011-08-27 22:06:46 -04:00
|
|
|
|
|
|
|
def get(zone_id)
|
|
|
|
if zone_id.nil? or zone_id.to_s.empty?
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-12-22 23:24:03 +00:00
|
|
|
data = service.list_domain_details(zone_id).body
|
2011-08-27 22:06:46 -04:00
|
|
|
new(data)
|
2013-04-16 15:01:07 -05:00
|
|
|
rescue Fog::DNS::Rackspace::NotFound
|
2011-08-27 22:06:46 -04:00
|
|
|
nil
|
|
|
|
#Accessing a valid (but other customer's) id returns a 503 error
|
|
|
|
rescue Fog::Rackspace::Errors::ServiceUnavailable
|
|
|
|
nil
|
|
|
|
end
|
2013-06-18 12:42:35 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
def next_params(body)
|
|
|
|
# return if we don't have any links
|
|
|
|
return nil unless body && body['links']
|
|
|
|
|
|
|
|
#return if links don't contain a href for the next page
|
|
|
|
next_link = body['links'].find {|h| h['rel'] == 'next'}
|
|
|
|
return nil unless next_link && next_link['href']
|
|
|
|
|
|
|
|
url = next_link['href']
|
|
|
|
uri = URI.parse url
|
|
|
|
return nil unless uri.query
|
|
|
|
CGI.parse uri.query
|
|
|
|
end
|
2011-08-27 22:06:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|