1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #3050 from jsmapr1/master

Add options for Zerigo List Hosts
This commit is contained in:
Wesley Beary 2014-07-14 10:13:13 -05:00
commit 48125b09ce
2 changed files with 49 additions and 12 deletions

View file

@ -2,12 +2,16 @@ module Fog
module DNS
class Zerigo
class Real
require 'fog/zerigo/parsers/dns/list_hosts'
require "fog/zerigo/parsers/dns/list_hosts"
# Get list of all DNS zones hosted on Slicehost (for this account)
#
# ==== Parameters
# * zone_id<~Integer> - the zone ID of the zone from which to get the host records for
# * 'options'<~Hash> - optional parameters
# * 'page' <~Integer>
# * 'per_page' <~Integer>
# * 'fqdn' <~String>
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
@ -24,10 +28,11 @@ module Fog
# * 'updated-at'<~String>
# * 'zone-id'<~String>
# * 'status'<~Integer> - 200 indicates success
def list_hosts(zone_id)
def list_hosts(zone_id, options={})
request(
:query => options,
:expects => 200,
:method => 'GET',
:method => "GET",
:parser => Fog::Parsers::DNS::Zerigo::ListHosts.new,
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
)
@ -35,16 +40,27 @@ module Fog
end
class Mock # :nodoc:all
def list_hosts(zone_id)
def list_hosts(zone_id, options={})
zone = find_by_zone_id(zone_id)
response = Excon::Response.new
if zone
response.status = 200
response.body = {
'hosts' => zone['hosts']
}
if options.empty?
response.status = 200
response.body = {
"hosts" => zone["hosts"]
}
else
hosts = zone["hosts"]
hosts = hosts.select {|h| h["fqdn"] == options["fqdn"]} if options["fqdn"]
hosts = options["per_page"] ? hosts.each_slice(options["per_page"] - 1).to_a : hosts.each_slice(100).to_a
hosts = options["page"] ? hosts[options["page"]] : hosts[0]
response.status = 200
response.body = {
"hosts" => hosts
}
end
else
response.status = 404
end

View file

@ -327,18 +327,39 @@ Shindo.tests('Fog::DNS[:zerigo] | DNS requests', ['zerigo', 'dns']) do
host_count == 4
end
test('list host records') do
test("list host records") do
pending if Fog.mocking?
result = false
response = Fog::DNS[:zerigo].list_hosts( @zone_id)
if response.status == 200
hosts = response.body['hosts']
hosts = response.body["hosts"]
if (hosts.count == 4)
hosts.each { |host|
if (host['id'] > 0) and (host['fqdn'].length > 0) and (host['host-type'].length > 0) and
(host['created-at'].length > 0) and (host['updated-at'].length > 0)
if (host["id"] > 0) and (host["fqdn"].length > 0) and (host["host-type"].length > 0) and
(host["created-at"].length > 0) and (host["updated-at"].length > 0)
result = true
end
}
end
end
result
end
test("list host records with options") do
pending if Fog.mocking?
result = false
response = Fog::DNS[:zerigo].list_hosts(@zone_id, {:per_page=>2, :page=>1})
if response.status == 200
hosts = response.body["hosts"]
if (hosts.count == 2)
hosts.each { |host|
if (host["id"] > 0) and (host["fqdn"].length > 0) and (host["host-type"].length > 0) and
(host["created-at"].length > 0) and (host["updated-at"].length > 0)
result = true
end
}