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

1st pass at complete Zerigo provider. Not debugged but all requests are there

added all the methods for handling host DNS records
still need to debug, need to review comments and update example code
This commit is contained in:
Athir Nuaimi 2010-12-12 18:02:02 -05:00
parent e081fac0b5
commit 8837931a0e
27 changed files with 532 additions and 233 deletions

View file

@ -15,15 +15,15 @@ module Fog
request :get_zone
request :get_zone_stats
request :create_zone
# request :update_zone
# request :delete_zone
# request :list_hosts
# request :count_hosts
# request :get_host
# request :get_blank_host
# request :create_host
# request :update_host
# request :delete_host
request :update_zone
request :delete_zone
request :list_hosts
request :find_hosts
request :count_hosts
request :get_host
request :create_host
request :update_host
request :delete_host
class Mock

View file

@ -1,9 +1,9 @@
module Fog
module Parsers
module Slicehost
module Zerigo
module Compute
class CreateRecord < Fog::Parsers::Base
class CountHosts < Fog::Parsers::Base
def reset
@response = {}
@ -11,10 +11,8 @@ module Fog
def end_element(name)
case name
when 'zone-id', 'ttl', 'id'
when 'count'
@response[name] = @value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
@response[name] = @value
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Parsers
module Zerigo
module Compute
class CreateHost < Fog::Parsers::Base
def reset
@host = {}
@response = {}
end
def end_element(name)
case name
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
@host[name] = @value
when 'host'
@response['host'] = @host
end
end
end
end
end
end
end

View file

@ -13,7 +13,7 @@ module Fog
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'
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

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module Zerigo
module Compute
class FindZones < Fog::Parsers::Base
def reset
@host = {}
@response = { 'hosts' => [] }
end
def end_element(name)
case name
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
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

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module Zerigo
module Compute
class GetHost < Fog::Parsers::Base
def reset
@host = {}
@response = { 'hosts' => [] }
end
def end_element(name)
case name
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
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

View file

@ -1,26 +0,0 @@
module Fog
module Parsers
module Slicehost
module Compute
class GetRecord < Fog::Parsers::Base
def reset
@response = { }
end
def end_element(name)
case name
when 'zone-id', 'ttl'
@response[name] = @value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
@response[name] = @value
end
end
end
end
end
end
end

View file

@ -1,30 +0,0 @@
module Fog
module Parsers
module Slicehost
module Compute
class GetRecords < Fog::Parsers::Base
def reset
@record = {}
@response = { 'records' => [] }
end
def end_element(name)
case name
when 'zone-id', 'ttl'
@record[name] = @value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
@record[name] = @value
when 'record'
@response['records'] << @record
@record = {}
end
end
end
end
end
end
end

View file

@ -1,5 +1,3 @@
require 'date'
module Fog
module Parsers
module Zerigo
@ -27,9 +25,9 @@ module Fog
if (@in_hosts)
#in hosts part of response
case name
when 'id', 'priority', 'ttl'
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
when 'data', 'fgdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at type', 'updated-at'
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
@host[name] = @value
when 'host'
@hosts << @host
@ -41,9 +39,9 @@ module Fog
else
#in zone part of data
case name
when 'default-ttl', 'id', 'nx-ttl'
when 'default-ttl', 'id', 'nx-ttl', 'hosts-count'
@response[name] = @value.to_i
when 'created-at', 'updated-at', 'domain', 'hostmaster', 'custom-nameservers', 'slave-nameservers', 'custom-ns', 'ns-type', 'ns1', 'notes'
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

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module Zerigo
module Compute
class ListHosts < Fog::Parsers::Base
def reset
@host = {}
@response = { 'hosts' => [] }
end
def end_element(name)
case name
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
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

View file

@ -12,9 +12,9 @@ module Fog
def end_element(name)
case name
when 'default-ttl', 'id', 'nx-ttl'
when 'default-ttl', 'id', 'nx-ttl', 'hosts-count'
@zone[name] = @value.to_i
when 'created-at', 'updated-at', 'domain', 'hostmaster', 'custom-nameservers', 'slave-nameservers', 'custom-ns', 'ns-type', 'ns1', 'notes'
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

View file

@ -0,0 +1,29 @@
module Fog
module Parsers
module Zerigo
module Compute
class UpdateHost < Fog::Parsers::Base
def reset
@host = {}
@response = {}
end
def end_element(name)
case name
when 'id', 'priority', 'ttl', 'zone-id'
@host[name] = @value.to_i
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
@host[name] = @value
when 'host'
@response['host'] = @host
end
end
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Parsers
module Zerigo
module Compute
class UpdateZone < 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

View file

@ -0,0 +1,34 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/count_hosts'
# 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>:
# * 'count'<~Integer>
def count_hosts( zone_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::CountZones.new,
:path => "/api/1.1/zones/#{zone_id}/hosts/count.xml"
)
end
end
class Mock
def count_hosts( zone_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -5,8 +5,8 @@ module Fog
require 'fog/zerigo/parsers/compute/count_zones'
# Total number of zones available. It is the same value as provided in the X-Query-Count
# header in the list_zones API method
# 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>:
@ -16,7 +16,7 @@ module Fog
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::CountZones.new,
:path => "/api/1.1./zones/count.xml"
:path => "/api/1.1/zones/count.xml"
)
end

View file

@ -0,0 +1,34 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/create_host'
# 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>:
# * 'count'<~Integer>
def create_host( zone_id, hostname, host-type, data, options)
request(
:expects => 200,
:method => 'POST',
:parser => Fog::Parsers::Zerigo::Compute::CreateHost.new,
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
)
end
end
class Mock
def create_host( host_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -1,61 +0,0 @@
module Fog
module Slicehost
class Compute
class Real
require 'fog/slicehost/parsers/compute/create_record'
# Create a new record in a DNS zone - or update an existing one
# ==== Parameters
# * record_type<~String> - type of DNS record to create (A, CNAME, etc)
# * zone_id<~Integer> - ID of the zone to update
# * name<~String> - host name this DNS record is for
# * data<~String> - data for the DNS record (ie for an A record, the IP address)
# * options<~Hash> - extra parameters that are not mandatory
# * ttl<~Integer> - time to live in seconds
# * active<~String> - whether this record is active or not ('Y' or 'N')
# * aux<~String> - extra data required by the record
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'name'<~String> - as above
# * 'id'<~Integer> - Id of zone/domain - used in future API calls for this zone
# * 'ttl'<~Integer> - as above
# * 'data'<~String> - as above
# * 'active'<~String> - as above
# * 'aux'<~String> - as above
def create_record( record_type, zone_id, name, data, options = {})
optional_tags= ''
options.each { |option, value|
case option
when :ttl
optional_tags+= "<ttl type='integer'>#{value}</ttl>"
when :active
optional_tags+= "<active>#{value}</active>"
when :aux
optional_tags+= "<aux>#{value}</aux>"
end
}
request(
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><record><record_type>#{record_type}</record_type><zone_id type="integer">#{zone_id}</zone_id><name>#{name}</name><data>#{data}</data>#{optional_tags}</record>},
:expects => 201,
:method => 'POST',
:parser => Fog::Parsers::Slicehost::Compute::CreateRecord.new,
:path => '/api/1.1./records.xml'
)
end
end
class Mock
def create_record( record_type, zone_id, name, data)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -15,6 +15,13 @@ module Fog
# * 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>:
@ -34,6 +41,20 @@ module Fog
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
}

View file

@ -1,19 +1,19 @@
module Fog
module Slicehost
module Zerigo
class Compute
class Real
# Delete a record from the specified DNS zone
# Delete a zone from Zerigo
# ==== Parameters
# * record_id<~Integer> - Id of DNS record to delete
# * zone_id<~Integer> - Id of zone to delete
#
# ==== Returns
# * response<~Excon::Response>: - HTTP status code will be result
def delete_record(record_id)
def delete_host(host_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "/api/1.1./records/#{record_id}.xml"
:path => "/api/1.1/hosts/#{host_id}.xml"
)
end
@ -21,7 +21,7 @@ module Fog
class Mock
def delete_record(record_id)
def delete_host(host_id)
Fog::Mock.not_implemented
end

View file

@ -1,9 +1,9 @@
module Fog
module Slicehost
module Zerigo
class Compute
class Real
# Delete a zone from Slicehost's DNS
# Delete a zone from Zerigo
# ==== Parameters
# * zone_id<~Integer> - Id of zone to delete
#
@ -13,7 +13,7 @@ module Fog
request(
:expects => 200,
:method => 'DELETE',
:path => "/api/1.1./zones/#{zone_id}.xml"
:path => "/api/1.1/zones/#{zone_id}.xml"
)
end

View file

@ -0,0 +1,48 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/find_hosts'
# Get list of all DNS zones hosted on Slicehost (for this account)
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'origin'<~String> - domain name to host (ie example.com)
# * 'id'<~Integer> - Id of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)
# * 'active'<~String> - whether zone is active in Slicehost DNS server - 'Y' or 'N'
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::Zerigo::Compute::FindHosts.new,
:path => "/api/1.1/hosts.xml"
)
else
#look for hosts in a specific zone
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::FindHosts.new,
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
)
end
end
end
class Mock
def find_hosts( fqdn, zone_id = nil)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/get_hosts'
# 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>:
# * 'count'<~Integer>
def get_host( host_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::GetZone.new,
:path => "/api/1.1/hosts/#{host_id}.xml"
)
end
end
class Mock
def get_host( host_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -1,40 +0,0 @@
module Fog
module Slicehost
class Compute
class Real
require 'fog/slicehost/parsers/compute/get_record'
# Get an individual DNS record from the specified zone
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'record_type'<~String> - type of DNS record to create (A, CNAME, etc)
# * 'zone_id'<~Integer> - ID of the zone to update
# * 'name'<~String> - host name this DNS record is for
# * 'data'<~String> - data for the DNS record (ie for an A record, the IP address)
# * 'ttl'<~Integer> - time to live in seconds
# * 'active'<~String> - whether this record is active or not ('Y' or 'N')
# * 'aux'<~String> - extra data required by the record
def get_record( record_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Slicehost::Compute::GetRecords.new,
:path => "/api/1.1/records/#{record_id}.xml"
)
end
end
class Mock
def get_record(record_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -1,41 +0,0 @@
module Fog
module Slicehost
class Compute
class Real
require 'fog/slicehost/parsers/compute/get_records'
# Get all the DNS records across all the DNS zones for this account
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'addresses'<~Array> - Ip addresses for the slice
# * 'backup-id'<~Integer> - Id of backup slice was booted from
# * 'flavor_id'<~Integer> - Id of flavor slice was booted from
# * 'id'<~Integer> - Id of the slice
# * 'image-id'<~Integer> - Id of image slice was booted from
# * 'name'<~String> - Name of the slice
# * 'progress'<~Integer> - Progress of current action, in percentage
# * 'status'<~String> - Current status of the slice
def get_records
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Slicehost::Compute::GetRecords.new,
:path => "/api/1.1/records.xml"
)
end
end
class Mock
def get_records
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,37 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/list_hosts'
# Get list of all DNS zones hosted on Slicehost (for this account)
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'origin'<~String> - domain name to host (ie example.com)
# * 'id'<~Integer> - Id of the zone
# * 'ttl'<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)
# * 'active'<~String> - whether zone is active in Slicehost DNS server - 'Y' or 'N'
def list_hosts( zone_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Zerigo::Compute::ListHosts.new,
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
)
end
end
class Mock
def list_hosts( zone_id)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/update_host'
# 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>:
# * 'count'<~Integer>
def update_host( host_id, options = {})
request(
:expects => 200,
:method => 'PUT',
:parser => Fog::Parsers::Zerigo::Compute::UpdateHost.new,
:path => "/api/1.1/hosts/#{host_id}.xml"
)
end
end
class Mock
def update_host( host_id, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,85 @@
module Fog
module Zerigo
class Compute
class Real
require 'fog/zerigo/parsers/compute/update_zone'
# 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>:
# * body<~Hash>:
# * 'origin'<~String> - as above
# * 'id'<~Integer> - Id of zone/domain - used in future API calls
# * 'ttl'<~Integer> - as above
# * 'active'<~String> - as above
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><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::Slicehost::Compute::UpdateZone.new,
:path => '/api/1.1/zones.xml'
)
end
end
class Mock
def update_zone(domain, default_ttl, ns_type, options = {})
Fog::Mock.not_implemented
end
end
end
end
end