mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added support for 4 more zerigo dns methods: count_zones, get_zone, get_zone_stats, create_zone
items added but not yet tested. Will continue to add the rest of the methods and then do a big testing cycle
This commit is contained in:
parent
15d35d3e0c
commit
e081fac0b5
17 changed files with 601 additions and 5 deletions
|
@ -11,11 +11,10 @@ module Fog
|
|||
|
||||
request_path 'fog/zerigo/requests/compute'
|
||||
request :list_zones
|
||||
# request :count_zones
|
||||
# request :get_zone
|
||||
# request :get_zone_stats
|
||||
# request :get_blank_zone
|
||||
# request :create_zone
|
||||
request :count_zones
|
||||
request :get_zone
|
||||
request :get_zone_stats
|
||||
request :create_zone
|
||||
# request :update_zone
|
||||
# request :delete_zone
|
||||
# request :list_hosts
|
||||
|
|
24
lib/fog/zerigo/parsers/compute/count_zones.rb
Normal file
24
lib/fog/zerigo/parsers/compute/count_zones.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Zerigo
|
||||
module Compute
|
||||
|
||||
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
|
26
lib/fog/zerigo/parsers/compute/create_record.rb
Normal file
26
lib/fog/zerigo/parsers/compute/create_record.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Slicehost
|
||||
module Compute
|
||||
|
||||
class CreateRecord < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'zone-id', 'ttl', 'id'
|
||||
@response[name] = @value.to_i
|
||||
when 'record-type', 'name', 'data', 'active', 'aux'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/zerigo/parsers/compute/create_zone.rb
Normal file
26
lib/fog/zerigo/parsers/compute/create_zone.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Zerigo
|
||||
module Compute
|
||||
|
||||
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'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/zerigo/parsers/compute/get_record.rb
Normal file
26
lib/fog/zerigo/parsers/compute/get_record.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
30
lib/fog/zerigo/parsers/compute/get_records.rb
Normal file
30
lib/fog/zerigo/parsers/compute/get_records.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
58
lib/fog/zerigo/parsers/compute/get_zone.rb
Normal file
58
lib/fog/zerigo/parsers/compute/get_zone.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require 'date'
|
||||
|
||||
module Fog
|
||||
module Parsers
|
||||
module Zerigo
|
||||
module Compute
|
||||
|
||||
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', 'priority', 'ttl'
|
||||
@host[name] = @value.to_i
|
||||
when 'data', 'fgdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at type', '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'
|
||||
@response[name] = @value.to_i
|
||||
when 'created-at', 'updated-at', 'domain', 'hostmaster', 'custom-nameservers', 'slave-nameservers', 'custom-ns', 'ns-type', 'ns1', 'notes'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/zerigo/parsers/compute/get_zone_stats.rb
Normal file
26
lib/fog/zerigo/parsers/compute/get_zone_stats.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Zerigo
|
||||
module Compute
|
||||
|
||||
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
|
34
lib/fog/zerigo/requests/compute/count_zones.rb
Normal file
34
lib/fog/zerigo/requests/compute/count_zones.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module Zerigo
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
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
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * 'count'<~Integer>
|
||||
def count_zones()
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Zerigo::Compute::CountZones.new,
|
||||
:path => "/api/1.1./zones/count.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def count_zones()
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
61
lib/fog/zerigo/requests/compute/create_record.rb
Normal file
61
lib/fog/zerigo/requests/compute/create_record.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
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
|
60
lib/fog/zerigo/requests/compute/create_zone.rb
Normal file
60
lib/fog/zerigo/requests/compute/create_zone.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
module Fog
|
||||
module Zerigo
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
require 'fog/zerigo/parsers/compute/create_zone'
|
||||
|
||||
# Create a new zone for Slicehost'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
|
||||
#
|
||||
# ==== 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 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>"
|
||||
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::CreateZone.new,
|
||||
:path => '/api/1.1/zones.xml'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_zone(domain, default_ttl, ns_type, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/zerigo/requests/compute/delete_record.rb
Normal file
31
lib/fog/zerigo/requests/compute/delete_record.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Slicehost
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Delete a record from the specified DNS zone
|
||||
# ==== Parameters
|
||||
# * record_id<~Integer> - Id of DNS record to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>: - HTTP status code will be result
|
||||
def delete_record(record_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "/api/1.1./records/#{record_id}.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_record(record_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/zerigo/requests/compute/delete_zone.rb
Normal file
31
lib/fog/zerigo/requests/compute/delete_zone.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Slicehost
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Delete a zone from Slicehost's DNS
|
||||
# ==== Parameters
|
||||
# * zone_id<~Integer> - Id of zone to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>: - HTTP status code will be result
|
||||
def delete_zone(zone_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "/api/1.1./zones/#{zone_id}.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_zone(zone_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
lib/fog/zerigo/requests/compute/get_record.rb
Normal file
40
lib/fog/zerigo/requests/compute/get_record.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
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
|
41
lib/fog/zerigo/requests/compute/get_records.rb
Normal file
41
lib/fog/zerigo/requests/compute/get_records.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
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
|
41
lib/fog/zerigo/requests/compute/get_zone.rb
Normal file
41
lib/fog/zerigo/requests/compute/get_zone.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module Zerigo
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
require 'fog/zerigo/parsers/compute/get_zone'
|
||||
|
||||
# Get details of a DNS zone. This 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>:
|
||||
# * '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 get_zone(zone)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Zerigo::Compute::GetZone.new,
|
||||
:path => "/api/1.1/zones/#{zone}.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_zone(zone)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/zerigo/requests/compute/get_zone_stats.rb
Normal file
42
lib/fog/zerigo/requests/compute/get_zone_stats.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module Zerigo
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
require 'fog/zerigo/parsers/compute/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<~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
|
||||
def get_zone_stats(zone_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Zerigo::Compute::GetZoneStats.new,
|
||||
:path => "/api/1.1/zones/#{zone}/stats.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_zone_stats(zone_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue