mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Drop Zerigo
This commit is contained in:
parent
a4cdb7390a
commit
94a86e03e1
39 changed files with 0 additions and 2056 deletions
|
@ -59,7 +59,6 @@ require 'fog/vmfusion'
|
|||
require 'fog/vsphere'
|
||||
require 'fog/voxel'
|
||||
require 'fog/xenserver'
|
||||
require 'fog/zerigo'
|
||||
require 'fog/cloudsigma'
|
||||
require 'fog/openvz'
|
||||
require 'fog/opennebula'
|
||||
|
|
|
@ -91,7 +91,6 @@ require 'fog/bin/vmfusion'
|
|||
require 'fog/bin/vsphere'
|
||||
require 'fog/bin/voxel'
|
||||
require 'fog/bin/xenserver'
|
||||
require 'fog/bin/zerigo'
|
||||
require 'fog/bin/cloudsigma'
|
||||
require 'fog/bin/openvz'
|
||||
require 'fog/bin/opennebula'
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
class Zerigo < Fog::Bin
|
||||
class << self
|
||||
def class_for(key)
|
||||
case key
|
||||
when :dns
|
||||
Fog::DNS::Zerigo
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :dns
|
||||
Fog::Logger.warning("Zerigo[:dns] is not recommended, use DNS[:zerigo] for portability")
|
||||
Fog::DNS.new(:provider => 'Zerigo')
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key.inspect}"
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
def services
|
||||
Fog::Zerigo.services
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
require 'fog/zerigo/dns'
|
|
@ -1,10 +0,0 @@
|
|||
require 'fog/core'
|
||||
require 'fog/xml'
|
||||
|
||||
module Fog
|
||||
module Zerigo
|
||||
extend Fog::Provider
|
||||
|
||||
service(:dns, 'DNS')
|
||||
end
|
||||
end
|
|
@ -1,114 +0,0 @@
|
|||
require 'fog/zerigo/core'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Zerigo < Fog::Service
|
||||
requires :zerigo_email, :zerigo_token
|
||||
recognizes :host, :persistent, :port, :scheme, :timeout
|
||||
|
||||
model_path 'fog/zerigo/models/dns'
|
||||
model :record
|
||||
collection :records
|
||||
model :zone
|
||||
collection :zones
|
||||
|
||||
request_path 'fog/zerigo/requests/dns'
|
||||
request :count_hosts
|
||||
request :count_zones
|
||||
request :create_host
|
||||
request :create_zone
|
||||
request :delete_host
|
||||
request :delete_zone
|
||||
request :find_hosts
|
||||
request :get_host
|
||||
request :get_zone
|
||||
request :get_zone_stats
|
||||
request :list_zones
|
||||
request :list_hosts
|
||||
request :update_host
|
||||
request :update_zone
|
||||
|
||||
class Mock
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = key == :zones ? [] : {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@zerigo_email = options[:zerigo_email]
|
||||
@zerigo_token = options[:zerigo_token]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.reset
|
||||
end
|
||||
|
||||
def find_by_zone_id(zone_id)
|
||||
self.data[:zones].find { |z| z['id'] == zone_id }
|
||||
end
|
||||
|
||||
def find_by_domain(domain)
|
||||
self.data[:zones].find { |z| z['domain'] == domain }
|
||||
end
|
||||
|
||||
def find_host(host_id)
|
||||
self.data[:zones].map { |z| z['hosts'].find { |h| h['id'] == host_id } }.compact.first
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
|
||||
@zerigo_email = options[:zerigo_email]
|
||||
@zerigo_token = options[:zerigo_token]
|
||||
@connection_options = options[:connection_options] || {}
|
||||
@host = options[:host] || "ns.zerigo.com"
|
||||
@persistent = options[:persistent] || false
|
||||
@port = options[:port] || 80
|
||||
@scheme = options[:scheme] || 'http'
|
||||
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:headers] ||= {}
|
||||
key= "#{@zerigo_email}:#{@zerigo_token}"
|
||||
params[:headers].merge!({
|
||||
'Authorization' => "Basic #{Base64.encode64(key).delete("\r\n")}"
|
||||
})
|
||||
case params[:method]
|
||||
when 'DELETE', 'GET', 'HEAD'
|
||||
params[:headers]['Accept'] = 'application/xml'
|
||||
when 'POST', 'PUT'
|
||||
params[:headers]['Content-Type'] = 'application/xml'
|
||||
end
|
||||
|
||||
begin
|
||||
response = @connection.request(params)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::DNS::Zerigo::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,66 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Record < Fog::Model
|
||||
extend Fog::Deprecation
|
||||
deprecate :ip, :value
|
||||
deprecate :ip=, :value=
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :created_at, :aliases => 'created-at'
|
||||
attribute :value, :aliases => 'data'
|
||||
attribute :domain, :aliases => 'fqdn'
|
||||
attribute :name, :aliases => 'hostname'
|
||||
attribute :description, :aliases => 'notes'
|
||||
attribute :priority
|
||||
attribute :ttl
|
||||
attribute :type, :aliases => 'host-type'
|
||||
attribute :updated_at, :aliases => 'updated-at'
|
||||
attribute :zone_id, :aliases => 'zone-id'
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_host(identity)
|
||||
true
|
||||
end
|
||||
|
||||
def zone
|
||||
@zone
|
||||
end
|
||||
|
||||
def save
|
||||
requires :zone, :type, :value
|
||||
options = {}
|
||||
options[:hostname] = name if name
|
||||
options[:notes] = description if description
|
||||
options[:priority] = priority if priority
|
||||
options[:ttl] = ttl if ttl
|
||||
|
||||
if persisted?
|
||||
options[:host_type] = type
|
||||
options[:data] = value
|
||||
service.update_host(identity, options)
|
||||
else
|
||||
data = service.create_host(@zone.id, type, value, options)
|
||||
merge_attributes(data.body)
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def zone=(new_zone)
|
||||
@zone = new_zone
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,45 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/zerigo/models/dns/record'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Records < Fog::Collection
|
||||
attribute :zone
|
||||
|
||||
model Fog::DNS::Zerigo::Record
|
||||
|
||||
# List all domains
|
||||
# @param [Hash] options Options to pass to the underlying API call
|
||||
# @option options [String] :fqdn search for the given fqdn
|
||||
def all(options = {})
|
||||
requires :zone
|
||||
if options[:fqdn]
|
||||
hosts = service.find_hosts(options[:fqdn], zone.id).body['hosts']
|
||||
load(hosts)
|
||||
else
|
||||
parent = zone.collection.get(zone.identity)
|
||||
if parent
|
||||
merge_attributes(parent.records.attributes)
|
||||
load(parent.records.map {|record| record.attributes})
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get(record_id)
|
||||
data = service.get_host(record_id).body
|
||||
new(data)
|
||||
rescue Fog::Service::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :zone
|
||||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/zerigo/models/dns/records'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Zone < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :created_at, :aliases => 'created-at'
|
||||
attribute :domain
|
||||
attribute :ttl, :aliases => 'default-ttl'
|
||||
attribute :type, :aliases => 'ns-type'
|
||||
attribute :updated_at, :aliases => 'updated-at'
|
||||
|
||||
# <custom-nameservers>ns1.example.com,ns2.example.com</custom-nameservers>
|
||||
# <custom-ns type="boolean">true</custom-ns>
|
||||
# <hostmaster>dnsadmin@example.com</hostmaster>
|
||||
# <notes nil="true"/>
|
||||
# <ns1 nil="true"/>
|
||||
# <nx-ttl nil="true"></nx-ttl>
|
||||
# <slave-nameservers nil="true"/>
|
||||
# <tag-list>one two</tag-list>
|
||||
# <hosts-count>1</hosts-count>
|
||||
|
||||
def initialize(attributes={})
|
||||
self.type ||= 'pri_sec'
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_zone(identity)
|
||||
true
|
||||
end
|
||||
|
||||
def records
|
||||
@records ||= begin
|
||||
Fog::DNS::Zerigo::Records.new(
|
||||
:zone => self,
|
||||
:service => service
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def nameservers
|
||||
[
|
||||
'a.ns.zerigo.net',
|
||||
'b.ns.zerigo.net',
|
||||
'c.ns.zerigo.net',
|
||||
'd.ns.zerigo.net',
|
||||
'e.ns.zerigo.net'
|
||||
]
|
||||
end
|
||||
|
||||
def save
|
||||
self.ttl ||= 3600
|
||||
requires :domain, :type, :ttl
|
||||
options = {}
|
||||
# * options<~Hash> - optional paramaters
|
||||
# * ns1<~String> - required if ns_type == sec
|
||||
# * nx_ttl<~Integer> -
|
||||
# * slave_nameservers<~String> - required if ns_type == pri
|
||||
# * axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
|
||||
# * custom_nameservers<~String> - comma-separated list of custom nameservers
|
||||
# * custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
|
||||
# * hostmaster<~String> - email of the DNS administrator or hostmaster
|
||||
# * notes<~String> - notes about the domain
|
||||
# * restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
|
||||
# * tag_list<~String> - List of all tags associated with this domain
|
||||
data = unless identity
|
||||
service.create_zone(domain, ttl, type, options)
|
||||
else
|
||||
options[:default_ttl] = ttl
|
||||
options[:ns_type] = type
|
||||
service.update_zone(identity, options)
|
||||
end
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/zerigo/models/dns/zone'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Zones < Fog::Collection
|
||||
model Fog::DNS::Zerigo::Zone
|
||||
|
||||
def all(options = {})
|
||||
data = service.list_zones(options).body['zones']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(zone_id_or_domain)
|
||||
data = service.get_zone(zone_id_or_domain).body
|
||||
zone = new(data)
|
||||
zone.records.load(data['hosts'])
|
||||
zone
|
||||
rescue Fog::Service::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class CountHosts < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'count'
|
||||
@response[name] = value.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class CountZones < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'count'
|
||||
@response[name] = value.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class CreateHost < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'id', 'zone-id'
|
||||
@response[name] = value.to_i
|
||||
when 'priority', 'ttl'
|
||||
@response[name] = value.to_i if value
|
||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class CreateZone < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'default-ttl', 'id', 'nx-ttl', 'hosts-count'
|
||||
@response[name] = value.to_i
|
||||
when 'created-at', 'custom-nameservers', 'custom-ns', 'domain', 'hostmaster', 'notes', 'ns1', 'ns-type', 'slave-nameservers', 'tag-list', 'updated-at', 'hosts', 'axfr-ips', 'restrict-axfr'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class FindHosts < Fog::Parsers::Base
|
||||
def reset
|
||||
@host = {}
|
||||
@response = { 'hosts' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'id', 'zone-id'
|
||||
@host[name] = value.to_i
|
||||
when 'priority', 'ttl'
|
||||
@host[name] = value.to_i if value
|
||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||
@host[name] = value
|
||||
when 'host'
|
||||
@response['hosts'] << @host
|
||||
@host = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class GetHost < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'id', 'zone-id'
|
||||
@response[name] = value.to_i
|
||||
when 'priority', 'ttl'
|
||||
@response[name] = value.to_i if value
|
||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class GetZone < Fog::Parsers::Base
|
||||
def reset
|
||||
@host = {}
|
||||
@hosts = []
|
||||
@response = {}
|
||||
@in_hosts = false
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super(name, attrs)
|
||||
#look out for start of <hosts> section
|
||||
#needed as some of the tags have the same name as the parent <zone> section
|
||||
if name == 'hosts'
|
||||
@in_hosts= true
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
if (@in_hosts)
|
||||
#in hosts part of response
|
||||
case name
|
||||
when 'id', 'zone-id'
|
||||
@host[name] = value.to_i
|
||||
when 'priority', 'ttl'
|
||||
@host[name] = value.to_i if value
|
||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||
@host[name] = value
|
||||
when 'host'
|
||||
@hosts << @host
|
||||
@host = {}
|
||||
when 'hosts'
|
||||
@response[name] = @hosts
|
||||
@in_hosts = false
|
||||
end
|
||||
else
|
||||
#in zone part of data
|
||||
case name
|
||||
when 'default-ttl', 'id', 'nx-ttl', 'hosts-count'
|
||||
@response[name] = value.to_i
|
||||
when 'created-at', 'custom-nameservers', 'custom-ns', 'domain', 'hostmaster', 'notes', 'ns1', 'ns-type', 'slave-nameservers', 'tag-list', 'updated-at', 'hosts', 'axfr-ips', 'restrict-axfr'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class GetZoneStats < Fog::Parsers::Base
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'id', 'queries'
|
||||
@response[name] = value.to_i
|
||||
when 'domain', 'period-begin', 'period-end'
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class ListHosts < Fog::Parsers::Base
|
||||
def reset
|
||||
@host = {}
|
||||
@response = { 'hosts' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'id', 'zone-id'
|
||||
@host[name] = value.to_i
|
||||
when 'priority', 'ttl'
|
||||
@host[name] = value.to_i if value
|
||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||
@host[name] = value
|
||||
when 'host'
|
||||
@response['hosts'] << @host
|
||||
@host = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module DNS
|
||||
module Zerigo
|
||||
class ListZones < Fog::Parsers::Base
|
||||
def reset
|
||||
@zone = {}
|
||||
@response = { 'zones' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'default-ttl', 'id', 'nx-ttl', 'hosts-count'
|
||||
@zone[name] = value.to_i
|
||||
when 'created-at', 'custom-nameservers', 'custom-ns', 'domain', 'hostmaster', 'notes', 'ns1', 'ns-type', 'slave-nameservers', 'tag-list', 'updated-at', 'hosts', 'axfr-ips', 'restrict-axfr'
|
||||
@zone[name] = value
|
||||
when 'zone'
|
||||
@response['zones'] << @zone
|
||||
@zone = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,45 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/count_hosts'
|
||||
|
||||
# total number of hosts available for the specified zone. It is the same value as provided
|
||||
# in the X-Query-Count header in the list_hosts API method
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# * 'count'<~Integer>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def count_hosts(zone_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::CountHosts.new,
|
||||
:path => "/api/1.1/zones/#{zone_id}/hosts/count.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def count_hosts(zone_id)
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'count' => zone['hosts'].size
|
||||
}
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/count_zones'
|
||||
|
||||
# Total number of zones hosted Zerigo for this account. It is the same value as provided
|
||||
# in the X-Query-Count header in the list_zones API method
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# * 'count'<~Integer>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def count_zones
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::CountZones.new,
|
||||
:path => "/api/1.1/zones/count.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def count_zones
|
||||
response = Excon::Response.new
|
||||
|
||||
response.status = 200
|
||||
response.body = { 'count' => self.data[:zones].size }
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,125 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/create_host'
|
||||
|
||||
# Create a new host in the specified zone
|
||||
#
|
||||
# ==== Parameters
|
||||
# * zone_id<~Integer>
|
||||
# * host_type<~String>
|
||||
# * data<~String>
|
||||
# * options<~Hash> - optional parameters
|
||||
# * hostname<~String> - Note: normally this is set/required!!
|
||||
# * notes<~String>
|
||||
# * priority<~Integer> - Note: required for MX or SRV records
|
||||
# * ttl<~Integer>
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>
|
||||
# * 'created-at'<~String>
|
||||
# * 'data'<~String>
|
||||
# * 'fqdn'<~String>
|
||||
# * 'host-type'<~String>
|
||||
# * 'hostname'<~String>
|
||||
# * 'id'<~Integer>
|
||||
# * 'notes'<~String>
|
||||
# * 'priority'<~Integer>
|
||||
# * 'ttl'<~Integer>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'zone-id'<~String>
|
||||
# * 'status'<~Integer> - 201 if successful
|
||||
def create_host(zone_id, host_type, data, options = {})
|
||||
optional_tags= ''
|
||||
options.each { |option, value|
|
||||
case option
|
||||
when :hostname
|
||||
optional_tags+= "<hostname>#{value}</hostname>"
|
||||
when :notes
|
||||
optional_tags+= "<notes>#{value}</notes>"
|
||||
when :priority
|
||||
optional_tags+= "<priority>#{value}</priority>"
|
||||
when :ttl
|
||||
optional_tags+= "<ttl>#{value}</ttl>"
|
||||
end
|
||||
}
|
||||
|
||||
request(
|
||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{optional_tags}</host>},
|
||||
:expects => 201,
|
||||
:method => 'POST',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::CreateHost.new,
|
||||
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def valid_host_types
|
||||
%w[A AAAA CNAME GEO MX NS SPF SRV TXT URL PTR CNAME NS]
|
||||
end
|
||||
|
||||
def create_host(zone_id, host_type, data, options = {})
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
# Handle error cases.
|
||||
|
||||
# Zone doesn't exist.
|
||||
unless zone
|
||||
response.status = 404
|
||||
return response
|
||||
end
|
||||
|
||||
# Bad host type.
|
||||
unless valid_host_types.include?(host_type)
|
||||
response.status = 422
|
||||
response.body = {
|
||||
'errors' => [
|
||||
'error' => 'Host type is not included in the list'
|
||||
]
|
||||
}
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
# Missing or bad priority value for MX or SRV records.
|
||||
if %w[MX SRV].include?(host_type) && options['priority'].to_s !~ /\d+/
|
||||
response.status = 422
|
||||
response.body = {
|
||||
'errors' => [
|
||||
'error' => 'Priority is not a number'
|
||||
]
|
||||
}
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
# Successful case.
|
||||
now = Time.now
|
||||
host = {
|
||||
'id' => rand(10000000),
|
||||
'fqdn' => options[:hostname] ? "#{options[:hostname]}.#{zone['domain']}" : zone['domain'],
|
||||
'data' => data,
|
||||
'hostname' => options[:hostname],
|
||||
'ttl' => options[:ttl].to_i,
|
||||
'host-type' => host_type,
|
||||
'created-at' => now,
|
||||
'updated-at' => now,
|
||||
'notes' => options[:notes],
|
||||
'priority' => options[:priority].to_i,
|
||||
'zone-id' => zone_id
|
||||
}
|
||||
|
||||
zone['hosts'] << host
|
||||
response.status = 201
|
||||
response.body = host
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,128 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/create_zone'
|
||||
|
||||
# Create a new zone for Zerigo's DNS servers to serve/host
|
||||
# ==== Parameters
|
||||
#
|
||||
# * domain<~String>
|
||||
# * default_ttl<~Integer>
|
||||
# * ns_type<~String>
|
||||
# * options<~Hash> - optional paramaters
|
||||
# * ns1<~String> - required if ns_type == sec
|
||||
# * nx_ttl<~Integer> -
|
||||
# * slave_nameservers<~String> - required if ns_type == pri
|
||||
# * axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
|
||||
# * custom_nameservers<~String> - comma-separated list of custom nameservers
|
||||
# * custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
|
||||
# * hostmaster<~String> - email of the DNS administrator or hostmaster
|
||||
# * notes<~String> - notes about the domain
|
||||
# * restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
|
||||
# * tag_list<~String> - List of all tags associated with this domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~Integer> - zone ID to use for future calls
|
||||
# * 'default-ttl'<~Integer>
|
||||
# * 'nx-ttl'<~Integer>
|
||||
# * 'hosts-count'<~Integer>
|
||||
# * 'created-at'<~String>
|
||||
# * 'custom-nameservers'<~String>
|
||||
# * 'custom-ns'<~String>
|
||||
# * 'domain'<~String>
|
||||
# * 'hostmaster'<~String>
|
||||
# * 'notes'<~String>
|
||||
# * 'ns1'<~String>
|
||||
# * 'ns-type'<~String>
|
||||
# * 'slave-nameservers'<~String>
|
||||
# * 'tag-list'<~String>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'hosts'<~String>
|
||||
# * 'axfr-ips'<~String>
|
||||
# * 'restrict-axfr'<~String>
|
||||
# * 'status'<~Integer> - 201 if successful
|
||||
|
||||
def create_zone(domain, default_ttl, ns_type, options = {})
|
||||
optional_tags= ''
|
||||
options.each { |option, value|
|
||||
case option
|
||||
when :ns1
|
||||
optional_tags+= "<ns1>#{value}</ns1>"
|
||||
when :nx_ttl
|
||||
optional_tags+= "<nx-ttl type='interger'>#{value}</nx-ttl>"
|
||||
when :slave_nameservers
|
||||
optional_tags+= "<slave-nameservers>#{value}</slave-nameservers>"
|
||||
when :axfr_ips
|
||||
optional_tags+= "<axfr-ips>#{value}</axfr-ips>"
|
||||
when :custom_nameservers
|
||||
optional_tags+= "<custom-nameservers>#{value}</custom-nameservers>"
|
||||
when :custom_ns
|
||||
optional_tags+= "<custom-ns>#{value}</custom-ns>"
|
||||
when :hostmaster
|
||||
optional_tags+= "<hostmaster>#{value}</hostmaster>"
|
||||
when :notes
|
||||
optional_tags+= "<notes>#{value}</notes>"
|
||||
when :restrict_axfr
|
||||
optional_tags+= "<restrict-axfr>#{value}</restrict-axfr>"
|
||||
when :tag_list
|
||||
optional_tags+= "<tag-list>#{value}</tag-list>"
|
||||
end
|
||||
}
|
||||
|
||||
request(
|
||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone><domain>#{domain}</domain><default-ttl type="integer">#{default_ttl}</default-ttl><ns-type>#{ns_type}</ns-type>#{optional_tags}</zone>},
|
||||
:expects => 201,
|
||||
:method => 'POST',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::CreateZone.new,
|
||||
:path => '/api/1.1/zones.xml'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def create_zone(domain, default_ttl, ns_type, options = {})
|
||||
now = Time.now
|
||||
zone = {
|
||||
'id' => rand(10000000),
|
||||
'domain' => domain,
|
||||
'created-at' => now,
|
||||
'updated-at' => now,
|
||||
'ns1' => options[:ns1],
|
||||
'nx-ttl' => options[:nx_ttl].to_i,
|
||||
'default-ttl' => default_ttl.to_i,
|
||||
'ns-type' => ns_type,
|
||||
'hosts' => options[:hosts] || [],
|
||||
'hosts-count' => (options[:hosts] || []).size,
|
||||
'notes' => options[:notes],
|
||||
'slave-nameservers' => options[:slave_nameservers],
|
||||
'tag-list' => options[:tag_list]
|
||||
}
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if self.data[:zones].any? {|z| z['domain'] == zone['domain'] }
|
||||
response.status = 422
|
||||
response.body = {
|
||||
'errors' => [
|
||||
'error' => 'Domain is already associated to another account',
|
||||
'error' => 'Domain already exists. If it was just deleted, wait a minute and try again'
|
||||
]
|
||||
}
|
||||
|
||||
else
|
||||
self.data[:zones] << zone
|
||||
|
||||
response.status = 201
|
||||
response.headers = { 'Location' => "http://ns.zerigo.com/api/1.1/zones/#{zone['id']}" }
|
||||
response.body = zone['hosts'].empty? ? zone.merge(:hosts => nil) : zone # Zerigo returns nil, not an empty list only on the create command.
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
# Delete a host record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * host_id<~Integer> - Id of host record to delete
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def delete_host(host_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "/api/1.1/hosts/#{host_id}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def delete_host(host_id)
|
||||
host = find_host(host_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if host
|
||||
zone = find_by_zone_id(host['zone-id'])
|
||||
zone['hosts'].delete(host)
|
||||
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
# Delete a zone from Zerigo
|
||||
#
|
||||
# ==== Parameters
|
||||
# * zone_id<~Integer> - Id of zone to delete
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
|
||||
def delete_zone(zone_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "/api/1.1/zones/#{zone_id}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def delete_zone(zone_id)
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
self.data[:zones].delete(zone)
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/find_hosts'
|
||||
|
||||
# Get list of all the host records that match the FQDN. If desired, can limit
|
||||
# search to a specific zone
|
||||
#
|
||||
#
|
||||
# ==== Parameters
|
||||
# * fqdn<~String> - domain to look for
|
||||
# * zone_id<~Integer> - if want to limit search to specific zone
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'hosts'<~Hash>
|
||||
# * 'created-at'<~String>
|
||||
# * 'data'<~String>
|
||||
# * 'fqdn'<~String>
|
||||
# * 'host-type'<~String>
|
||||
# * 'hostname'<~String>
|
||||
# * 'id'<~Integer>
|
||||
# * 'notes'<~String>
|
||||
# * 'priority'<~Integer>
|
||||
# * 'ttl'<~Integer>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'zone-id'<~String>
|
||||
# * 'status'<~Integer> - 200 indicated success
|
||||
#
|
||||
def find_hosts(fqdn, zone_id = nil)
|
||||
if zone_id.nil?
|
||||
#look for matching host across all zones
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::FindHosts.new,
|
||||
:path => "/api/1.1/hosts.xml?fqdn=#{fqdn}"
|
||||
)
|
||||
else
|
||||
#look for hosts in a specific zone
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::FindHosts.new,
|
||||
:path => "/api/1.1/zones/#{zone_id}/hosts.xml?fqdn=#{fqdn}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def find_hosts(fqdn, zone_id = nil)
|
||||
response = Excon::Response.new
|
||||
|
||||
zone = find_by_zone_id(zone_id)
|
||||
if zone_id && !zone
|
||||
response.status = 404
|
||||
else
|
||||
hosts = zone ? zone['hosts'].select { |z| z['fqdn'] == fqdn } :
|
||||
self.data[:zones].map { |z| z['hosts'].find { |h| h['fqdn'] == fqdn } }.compact
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'hosts' => hosts
|
||||
}
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/get_host'
|
||||
|
||||
# get details about a given host record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * host_id<~Integer> - ID of the host record to retrieve
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'created-at'<~String>
|
||||
# * 'data'<~String>
|
||||
# * 'fqdn'<~String>
|
||||
# * 'host-type'<~String>
|
||||
# * 'hostname'<~String>
|
||||
# * 'id'<~Integer>
|
||||
# * 'notes'<~String>
|
||||
# * 'priority'<~Integer>
|
||||
# * 'ttl'<~Integer>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'zone-id'<~String>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def get_host(host_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::GetHost.new,
|
||||
:path => "/api/1.1/hosts/#{host_id}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def get_host(host_id)
|
||||
host = find_host(host_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if host
|
||||
response.status = 200
|
||||
response.body = host
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/get_zone'
|
||||
|
||||
# Get details of a DNS zone. The response is similar to list_zones, with the
|
||||
# addition of hosts-count and possibly hosts.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * zone<~String> - Either the zone ID or the zone name (ie sample-domain.com)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'default-ttl'<~Integer>
|
||||
# * 'id'<~Integer>
|
||||
# * 'nx-ttl'<~Integer>
|
||||
# * 'hosts-count'<~Integer>
|
||||
# * 'created-at'<~String>
|
||||
# * 'custom-nameservers'<~String>
|
||||
# * 'custom-ns'<~String>
|
||||
# * 'domain'<~String>
|
||||
# * 'hostmaster'<~String>
|
||||
# * 'notes'<~String>
|
||||
# * 'ns1'<~String>
|
||||
# * 'ns-type'<~String>
|
||||
# * 'slave-nameservers'<~String>
|
||||
# * 'tag-list'<~String>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'hosts'<~Array> - a list of all host records. For the format of host info, see get_host()
|
||||
# * 'axfr-ips'<~String>
|
||||
# * 'restrict-axfr'<~String>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
|
||||
def get_zone(zone_id_or_domain)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::GetZone.new,
|
||||
:path => "/api/1.1/zones/#{zone_id_or_domain}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def get_zone(zone_id_or_domain)
|
||||
zone = find_by_zone_id(zone_id_or_domain) || find_by_domain(zone_id_or_domain)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
response.status = 200
|
||||
response.body = zone
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/get_zone_stats'
|
||||
|
||||
# returns current traffic statistics about this zone. Queries is measured from the
|
||||
# beginning of the current period through the time of the API call.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * zone_id<~Integer> - the zone ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'domain'<~String> - domain name (ie example.com)
|
||||
# * 'id'<~Integer> - Id of the zone
|
||||
# * 'period-being'<~String> - date in following format 2010-07-01
|
||||
# * 'period-end'<~String> - date
|
||||
# * 'queries'<~Integer> - # of queries for the zone during period
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
|
||||
def get_zone_stats(zone_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::GetZoneStats.new,
|
||||
:path => "/api/1.1/zones/#{zone_id}/stats.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def get_zone_stats(zone_id)
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'id' => zone,
|
||||
'domain' => zone['domain'],
|
||||
'period-begin' => zone['created-at'].strftime("%F"),
|
||||
'period-end' => Date.today.to_s,
|
||||
'queries' => 0
|
||||
}
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,73 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
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>:
|
||||
# * 'hosts'<~Array>
|
||||
# * 'created-at'<~String>
|
||||
# * 'data'<~String>
|
||||
# * 'fqdn'<~String>
|
||||
# * 'host-type'<~String>
|
||||
# * 'hostname'<~String>
|
||||
# * 'id'<~Integer>
|
||||
# * 'notes'<~String>
|
||||
# * 'priority'<~Integer>
|
||||
# * 'ttl'<~Integer>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'zone-id'<~String>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def list_hosts(zone_id, options={})
|
||||
request(
|
||||
:query => options,
|
||||
:expects => 200,
|
||||
:method => "GET",
|
||||
:parser => Fog::Parsers::DNS::Zerigo::ListHosts.new,
|
||||
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def list_hosts(zone_id, options={})
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
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
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,62 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
require 'fog/zerigo/parsers/dns/list_zones'
|
||||
|
||||
# Get list of all DNS zones hosted on Slicehost (for this account)
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>
|
||||
# * page<~Integer> - Indicates where to begin in your list of zones.
|
||||
# * per_page<~Integer> - The maximum number of zones to be included in the response body
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'zones'<~Array>
|
||||
# * 'default-ttl'<~Integer>
|
||||
# * 'id'<~Integer>
|
||||
# * 'nx-ttl'<~Integer>
|
||||
# * 'hosts-count'<~Integer>
|
||||
# * 'created-at'<~String>
|
||||
# * 'custom-nameservers'<~String>
|
||||
# * 'custom-ns'<~String>
|
||||
# * 'domain'<~String>
|
||||
# * 'hostmaster'<~String>
|
||||
# * 'notes'<~String>
|
||||
# * 'ns1'<~String>
|
||||
# * 'ns-type'<~String>
|
||||
# * 'slave-nameservers'<~String>
|
||||
# * 'tag-list'<~String>
|
||||
# * 'updated-at'<~String>
|
||||
# * 'hosts'<~String>
|
||||
# * 'axfr-ips'<~String>
|
||||
# * 'restrict-axfr'<~String>
|
||||
# * 'status'<~Integer> - 200 indicates success
|
||||
def list_zones(options = {})
|
||||
request(
|
||||
:query => options,
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::DNS::Zerigo::ListZones.new,
|
||||
:path => '/api/1.1/zones.xml'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def list_zones
|
||||
response = Excon::Response.new
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'zones' => self.data[:zones]
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,68 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
# Update a host record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * host_id<~Integer> - host ID of the record to update
|
||||
# * options<~Hash> - optional paramaters
|
||||
# * host_type<~String>
|
||||
# * data<~String>
|
||||
# * hostname<~String> - Note: normally this is set/required!!
|
||||
# * notes<~String>
|
||||
# * priority<~Integer> - Note: required for MX or SRV records
|
||||
# * ttl<~Integer>
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'status'<~Integer> - 200 for success
|
||||
#
|
||||
def update_host(host_id, options = {})
|
||||
optional_tags= ''
|
||||
options.each { |option, value|
|
||||
case option
|
||||
when :host_type
|
||||
optional_tags+= "<host-type>#{value}</host-type>"
|
||||
when :data
|
||||
optional_tags+= "<data>#{value}</data>"
|
||||
when :hostname
|
||||
optional_tags+= "<hostname>#{value}</hostname>"
|
||||
when :notes
|
||||
optional_tags+= "<notes>#{value}</notes>"
|
||||
when :priority
|
||||
optional_tags+= "<priority>#{value}</priority>"
|
||||
when :ttl
|
||||
optional_tags+= "<ttl>#{value}</ttl>"
|
||||
end
|
||||
}
|
||||
|
||||
request(
|
||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host>#{optional_tags}</host>},
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "/api/1.1/hosts/#{host_id}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def update_host(host_id, options = {})
|
||||
host = find_host(host_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if host
|
||||
options.each { |k, v| host[k.to_s] = v } # Deal with symbols in requests but strings in responses.
|
||||
host['updated-at'] = Time.now
|
||||
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,86 +0,0 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Zerigo
|
||||
class Real
|
||||
# Update the parameters of a zone
|
||||
# ==== Parameters
|
||||
#
|
||||
# * zone_id<~Integer>
|
||||
# * options<~Hash> - optional paramaters
|
||||
# * default_ttl<~Integer>
|
||||
# * ns_type<~String>
|
||||
# * ns1<~String> - required if ns_type == sec
|
||||
# * nx_ttl<~Integer> -
|
||||
# * slave_nameservers<~String> - required if ns_type == pri
|
||||
# * axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
|
||||
# * custom_nameservers<~String> - comma-separated list of custom nameservers
|
||||
# * custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
|
||||
# * hostmaster<~String> - email of the DNS administrator or hostmaster
|
||||
# * notes<~String> - notes about the domain
|
||||
# * restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
|
||||
# * tag_list<~String> - List of all tags associated with this domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'status'<~Integer> - 200 for success
|
||||
def update_zone(zone_id, options = {})
|
||||
optional_tags= ''
|
||||
options.each { |option, value|
|
||||
case option
|
||||
when :default_ttl
|
||||
optional_tags+= "<default-ttl>#{value}</default-ttl>"
|
||||
when :ns_type
|
||||
optional_tags+= "<ns-type>#{value}</ns-type>"
|
||||
when :ns1
|
||||
optional_tags+= "<ns1>#{value}</ns1>"
|
||||
when :nx_ttl
|
||||
optional_tags+= "<nx-ttl type='interger'>#{value}</nx-ttl>"
|
||||
when :slave_nameservers
|
||||
optional_tags+= "<slave-nameservers>#{value}</slave-nameservers>"
|
||||
when :axfr_ips
|
||||
optional_tags+= "<axfr-ips>#{value}</axfr-ips>"
|
||||
when :custom_nameservers
|
||||
optional_tags+= "<custom-nameservers>#{value}</custom-nameservers>"
|
||||
when :custom_ns
|
||||
optional_tags+= "<custom-ns>#{value}</custom-ns>"
|
||||
when :hostmaster
|
||||
optional_tags+= "<hostmaster>#{value}</hostmaster>"
|
||||
when :notes
|
||||
optional_tags+= "<notes>#{value}</notes>"
|
||||
when :restrict_axfr
|
||||
optional_tags+= "<restrict-axfr>#{value}</restrict-axfr>"
|
||||
when :tag_list
|
||||
optional_tags+= "<tag-list>#{value}</tag-list>"
|
||||
end
|
||||
}
|
||||
|
||||
request(
|
||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone>#{optional_tags}</zone>},
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "/api/1.1/zones/#{zone_id}.xml"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def update_zone(zone_id, options = {})
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
options.each { |k, v| zone[k.to_s] = v } # Deal with symbols in requests but strings in responses.
|
||||
zone['updated-at'] = Time.now
|
||||
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
require "minitest/autorun"
|
||||
require "fog"
|
||||
require "fog/bin"
|
||||
require "helpers/bin"
|
||||
|
||||
describe Zerigo do
|
||||
include Fog::BinSpec
|
||||
|
||||
let(:subject) { Zerigo }
|
||||
end
|
|
@ -46,7 +46,6 @@ describe Fog do
|
|||
assert_equal "Voxel", Fog.providers[:voxel]
|
||||
assert_equal "Vsphere", Fog.providers[:vsphere]
|
||||
assert_equal "XenServer", Fog.providers[:xenserver]
|
||||
assert_equal "Zerigo", Fog.providers[:zerigo]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -94,7 +93,6 @@ describe Fog do
|
|||
assert_includes Fog.registered_providers, "Voxel"
|
||||
assert_includes Fog.registered_providers, "Vsphere"
|
||||
assert_includes Fog.registered_providers, "XenServer"
|
||||
assert_includes Fog.registered_providers, "Zerigo"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -142,7 +140,6 @@ describe Fog do
|
|||
assert_includes Fog.available_providers, "Voxel" if Voxel.available?
|
||||
assert_includes Fog.available_providers, "Vsphere" if Vsphere.available?
|
||||
assert_includes Fog.available_providers, "XenServer" if XenServer.available?
|
||||
assert_includes Fog.available_providers, "Zerigo" if Zerigo.available?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,9 +27,6 @@ def dns_providers
|
|||
:email => 'fog@example.com'
|
||||
}
|
||||
},
|
||||
:zerigo => {
|
||||
:mocked => false
|
||||
},
|
||||
:rackspace => {
|
||||
:mocked => false,
|
||||
:zone_attributes => {
|
||||
|
|
|
@ -71,8 +71,6 @@ if Fog.mock?
|
|||
:vcloud_director_host => 'vcloud-director-host',
|
||||
:vcloud_director_password => 'vcloud_director_password',
|
||||
:vcloud_director_username => 'vcd_user@vcd_org_name',
|
||||
:zerigo_email => 'zerigo_email',
|
||||
:zerigo_token => 'zerigo_token',
|
||||
:dynect_customer => 'dynect_customer',
|
||||
:dynect_username => 'dynect_username',
|
||||
:dynect_password => 'dynect_password',
|
||||
|
|
|
@ -1,440 +0,0 @@
|
|||
Shindo.tests('Fog::DNS[:zerigo] | DNS requests', ['zerigo', 'dns']) do
|
||||
|
||||
# tests assume have a free acccount - ie need to limit # of zones to max of 3
|
||||
MAX_ZONE_COUNT = 3
|
||||
@domain = ''
|
||||
@org_zone_count = 0
|
||||
@new_zones = []
|
||||
@new_records =[]
|
||||
|
||||
def generate_unique_domain( with_trailing_dot = false)
|
||||
#get time (with 1/100th of sec accuracy)
|
||||
#want unique domain name and if provider is fast, this can be called more than once per second
|
||||
time= (Time.now.to_f * 100).to_i
|
||||
domain = 'test-' + time.to_s + '.com'
|
||||
if with_trailing_dot
|
||||
domain+= '.'
|
||||
end
|
||||
|
||||
domain
|
||||
end
|
||||
|
||||
tests( 'success') do
|
||||
|
||||
test('get current zone count') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
@org_zone_count= 0
|
||||
response = Fog::DNS[:zerigo].count_zones()
|
||||
if response.status == 200
|
||||
@org_zone_count = response.body['count']
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test('create zone - simple') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
options = { :nx_ttl => 1800 }
|
||||
domain = generate_unique_domain
|
||||
response = Fog::DNS[:zerigo].create_zone( domain, 3600, 'pri_sec', options)
|
||||
if response.status == 201
|
||||
zone_id = response.body['id']
|
||||
#worked so can now delete
|
||||
response = Fog::DNS[:zerigo].delete_zone( zone_id)
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test('create zone - set zerigo as slave') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
options = { :active => 'N', :ns1=> '2.3.4.5' }
|
||||
domain= generate_unique_domain
|
||||
response = Fog::DNS[:zerigo].create_zone( domain, 14400, 'sec', options )
|
||||
if response.status == 201
|
||||
zone_id = response.body['id']
|
||||
#worked so can now delete
|
||||
response = Fog::DNS[:zerigo].delete_zone( zone_id)
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test('create zone - set zerigo as master') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
domain= generate_unique_domain
|
||||
options = { :active => 'N', :slave_nameservers=> "ns1.#{domain},ns2.#{domain}" }
|
||||
response = Fog::DNS[:zerigo].create_zone( domain, 14400, 'pri', options )
|
||||
if response.status == 201
|
||||
zone_id = response.body['id']
|
||||
#worked so can now delete
|
||||
response = Fog::DNS[:zerigo].delete_zone( zone_id)
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test('create zone - set all parameters') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
@domain = generate_unique_domain
|
||||
options = { :nx_ttl => 1800, :active => 'N', :hostmaster => "netops@#{@domain}",
|
||||
:notes => 'for client ABC', :tag_list=> 'sample-tag' }
|
||||
response = Fog::DNS[:zerigo].create_zone( @domain, 14400, 'pri', options )
|
||||
if response.status == 201
|
||||
@zone_id = response.body['id']
|
||||
@new_zones << @zone_id
|
||||
end
|
||||
|
||||
response.status == 201
|
||||
end
|
||||
|
||||
test("get zone #{@zone_id} for #{@domain}- check all parameters") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= false
|
||||
|
||||
response = Fog::DNS[:zerigo].get_zone( @zone_id)
|
||||
if response.status == 200
|
||||
zone = response.body
|
||||
if (zone['ns-type'] == 'pri') and (zone['tag-list'] == 'sample-tag') and
|
||||
(zone['default-ttl'] == 14400) and (zone['nx-ttl'] == 1800) and
|
||||
(zone['updated-at'].length > 0) and (zone['created-at'].length > 0) and
|
||||
(zone['domain'] == @domain) and (zone['notes'] == 'for client ABC') and
|
||||
(zone['id'] == @zone_id)
|
||||
result = true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
test("update zone #{@zone_id} - set notes & tags") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
options = { :notes => 'for client XYZ', :tag_list=> 'testing-tag' }
|
||||
response = Fog::DNS[:zerigo].update_zone( @zone_id, options )
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test("get zone #{@zone_id} - check updated parameters") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= false
|
||||
|
||||
response = Fog::DNS[:zerigo].get_zone( @zone_id)
|
||||
if response.status == 200
|
||||
zone = response.body
|
||||
if (zone['tag-list'] == 'testing-tag') and (zone['notes'] == 'for client XYZ')
|
||||
result = true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
test("get zone stats for #{@zone_id}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= false
|
||||
|
||||
response = Fog::DNS[:zerigo].get_zone_stats( @zone_id)
|
||||
if response.status == 200
|
||||
zone = response.body
|
||||
if (zone['domain'] == @domain) and (zone['id'] == @zone_id) and
|
||||
(zone['period-begin'].length > 0) and (zone['period-end'].length > 0)
|
||||
result= true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
test("list zones - make sure total count is #{@org_zone_count+1}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= false
|
||||
|
||||
response = Fog::DNS[:zerigo].list_zones()
|
||||
if response.status == 200
|
||||
zones = response.body['zones']
|
||||
if (@org_zone_count+1) == zones.count
|
||||
result= true;
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test('list zones with pagination') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
# make enough zones to paginate
|
||||
number_zones_to_create = MAX_ZONE_COUNT-@org_zone_count-1
|
||||
number_zones_to_create.times do |i|
|
||||
domain = generate_unique_domain
|
||||
options = { :nx_ttl => 1800, :active => 'N', :hostmaster => "netops@#{domain}",
|
||||
:notes => 'for client ABC', :tag_list=> "sample-tag-#{i}" }
|
||||
response = Fog::DNS[:zerigo].create_zone( domain, 14400, 'pri', options )
|
||||
if response.status == 201
|
||||
@new_zones << response.body['id']
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
total_zone_count_response = Fog::DNS[:zerigo].list_zones()
|
||||
if total_zone_count_response.status == 200
|
||||
if number_zones_to_create > 0
|
||||
zones_we_should_see = @new_zones.dup
|
||||
total_zone_count = total_zone_count_response.headers['X-Query-Count'].to_i
|
||||
else
|
||||
zones_we_should_see = total_zone_count_response.body['zones'].map {|z| z['id']}
|
||||
total_zone_count = zones_we_should_see.count
|
||||
end
|
||||
|
||||
total_zone_count.times do |i|
|
||||
# zerigo pages are 1-indexed, not 0-indexed
|
||||
response = Fog::DNS[:zerigo].list_zones(:per_page => 1, :page => i+1)
|
||||
zones = response.body['zones']
|
||||
if 1 == zones.count
|
||||
zones_we_should_see.delete(zones.first['id'])
|
||||
end
|
||||
end
|
||||
|
||||
if zones_we_should_see.empty?
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test('create record - simple A record') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
host= 'www'
|
||||
options = { :hostname => host }
|
||||
response = Fog::DNS[:zerigo].create_host( @zone_id, 'A', '1.2.3.4', options)
|
||||
if response.status == 201
|
||||
record_id = response.body['id']
|
||||
@new_records << record_id
|
||||
end
|
||||
|
||||
response.status == 201
|
||||
end
|
||||
|
||||
test('create record - CNAME record') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
host = 'mail'
|
||||
options = { :hostname => host }
|
||||
response = Fog::DNS[:zerigo].create_host( @zone_id, 'CNAME', @domain, options)
|
||||
if response.status == 201
|
||||
record_id = response.body['id']
|
||||
@new_records << record_id
|
||||
end
|
||||
|
||||
response.status == 201
|
||||
end
|
||||
|
||||
test('create record - NS record') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
#note, when use create_host for a NS record, it needs to be a delation
|
||||
#rather than a NS record for the main domain (those NS records are setup
|
||||
#using the zone methods)
|
||||
sub_domain = 'subdomain' # that we want to delete DNS for
|
||||
ns_host = 'ns.' + @domain
|
||||
options = { :hostname => sub_domain}
|
||||
response = Fog::DNS[:zerigo].create_host( @zone_id, 'NS', ns_host, options)
|
||||
if response.status == 201
|
||||
record_id = response.body['id']
|
||||
@new_records << record_id
|
||||
end
|
||||
|
||||
response.status == 201
|
||||
end
|
||||
|
||||
test('create record - MX record') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
mail_domain = 'mail.' + @domain
|
||||
options = { :hostname => @domain, :ttl => 3600, :priority => '3'}
|
||||
response = Fog::DNS[:zerigo].create_host( @zone_id, 'MX', mail_domain, options)
|
||||
if response.status == 201
|
||||
@record_id = response.body['id']
|
||||
@new_records << @record_id
|
||||
end
|
||||
|
||||
response.status == 201
|
||||
end
|
||||
|
||||
test("get host #{@record_id}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
response = Fog::DNS[:zerigo].get_host( @record_id)
|
||||
if response.status == 200
|
||||
host = response.body
|
||||
if (host['id'] == @record_id) and (host['host-type'] == 'MX') and
|
||||
(host['created-at'].length > 0) and (host['updated-at'].length > 0)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("update host #{@record_id}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
options = { :priority => 7 }
|
||||
response = Fog::DNS[:zerigo].update_host( @record_id, options)
|
||||
if response.status == 200
|
||||
response = Fog::DNS[:zerigo].get_host( @record_id)
|
||||
if response.status == 200
|
||||
host= response.body
|
||||
if (host['priority'] == 7)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test('count host records') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
host_count = 0
|
||||
response = Fog::DNS[:zerigo].count_hosts( @zone_id)
|
||||
if response.status == 200
|
||||
host_count = response.body['count']
|
||||
end
|
||||
|
||||
host_count == 4
|
||||
end
|
||||
|
||||
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"]
|
||||
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)
|
||||
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
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("find host: mail.#{@domain}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
host = 'mail.' + @domain
|
||||
response = Fog::DNS[:zerigo].find_hosts( host)
|
||||
if response.status == 200
|
||||
hosts = response.body['hosts']
|
||||
host_count = hosts.count
|
||||
if (host_count == 1)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("find host: mail.#{@domain} - method 2") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
host = 'mail.' + @domain
|
||||
response = Fog::DNS[:zerigo].find_hosts( host, @zone_id)
|
||||
if response.status == 200
|
||||
hosts = response.body['hosts']
|
||||
host_count = hosts.count
|
||||
if (host_count == 1)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("delete #{@new_records.count} records created") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= true
|
||||
@new_records.each { |record_id|
|
||||
response = Fog::DNS[:zerigo].delete_host( record_id)
|
||||
if response.status != 200
|
||||
result= false;
|
||||
end
|
||||
}
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("delete #{@new_zones.count} zones created") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result= true
|
||||
@new_zones.each { |zone_id|
|
||||
response = Fog::DNS[:zerigo].delete_zone( zone_id)
|
||||
if response.status != 200
|
||||
result= false;
|
||||
end
|
||||
}
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests( 'failure') do
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue