mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
completed work on Zerigo provider. all methods supported and tested
updated all parameter and return values tested all functions update sample in examples directory to show how to use provider note: no mocks or test cases
This commit is contained in:
parent
65e6c49757
commit
5ff4551adc
18 changed files with 150 additions and 59 deletions
|
@ -1,10 +1,13 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'fog'
|
# require 'fog'
|
||||||
|
require '/Users/anuaimi/code/fog/lib/fog'
|
||||||
|
|
||||||
LINODE_API_KEY = '--put-your-key-here--'
|
LINODE_API_KEY = '--put-your-key-here--'
|
||||||
SLICEHOST_PASSWORD = '--put-your-key-here--'
|
SLICEHOST_PASSWORD = '--put-your-key-here--'
|
||||||
|
ZERIGO_USER = '--put-your-username-here--'
|
||||||
|
ZERIGO_PASSWORD = '--put-your-password-here--'
|
||||||
|
|
||||||
|
|
||||||
# example of how to use Linode DNS calls
|
# example of how to use Linode DNS calls
|
||||||
|
@ -155,6 +158,111 @@ def show_slicehost_dns_usage( password)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# example of how to use Zerigo DNS calls
|
||||||
|
def show_zerigo_dns_usage( username, password)
|
||||||
|
|
||||||
|
#check if we have a value api key for this cloud
|
||||||
|
if username == '--put-your-username-here--'
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
#connect to Zerigo
|
||||||
|
options = { :zerigo_user => username, :zerigo_password => password }
|
||||||
|
cloud = Fog::Zerigo::Compute.new( options)
|
||||||
|
|
||||||
|
#create a domain
|
||||||
|
options = { :nx_ttl => 1800 }
|
||||||
|
response = cloud.create_zone( "sample-domain.com", 3600, 'pri_sec', options)
|
||||||
|
if response.status == 201
|
||||||
|
zone_id = response.body['id']
|
||||||
|
end
|
||||||
|
|
||||||
|
#update zone
|
||||||
|
options = { :notes => "domain for client ABC"}
|
||||||
|
response = cloud.update_zone( zone_id, options)
|
||||||
|
if response.status == 200
|
||||||
|
puts "update of zone #{zone_id} worked"
|
||||||
|
end
|
||||||
|
|
||||||
|
#get details on the zone
|
||||||
|
response = cloud.get_zone( zone_id)
|
||||||
|
if response.status == 200
|
||||||
|
domain = response.body['domain']
|
||||||
|
hosts = response.body['hosts']
|
||||||
|
end
|
||||||
|
|
||||||
|
#get zone stats
|
||||||
|
response = cloud.get_zone_stats( zone_id)
|
||||||
|
if response.status == 200
|
||||||
|
queries = response.body['queries']
|
||||||
|
end
|
||||||
|
|
||||||
|
#list all domains on this accont
|
||||||
|
response= cloud.list_zones()
|
||||||
|
if response.status == 200
|
||||||
|
zone_count = response.headers['X-Query-Count'].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
#add an A record to the zone
|
||||||
|
options = { :hostname => 'www' }
|
||||||
|
response = cloud.create_host( zone_id, 'A', '1.2.3.4', options )
|
||||||
|
if response.status == 201
|
||||||
|
host_id = response.body['id']
|
||||||
|
end
|
||||||
|
|
||||||
|
#add an MX record to the zone
|
||||||
|
options = { :priority => 5 }
|
||||||
|
response = cloud.create_host( zone_id, 'MX', 'mail.sample-domain.com', options)
|
||||||
|
if response.status == 201
|
||||||
|
mail_host_id = response.body['id']
|
||||||
|
end
|
||||||
|
|
||||||
|
#update the record
|
||||||
|
options = { :priority => 10 }
|
||||||
|
response = cloud.update_host( mail_host_id, options)
|
||||||
|
if response.status == 200
|
||||||
|
#updated priority
|
||||||
|
end
|
||||||
|
|
||||||
|
#find a specific record
|
||||||
|
response = cloud.find_hosts( "sample-domain.com" )
|
||||||
|
if response.status == 200
|
||||||
|
hosts= response.body['hosts']
|
||||||
|
num_records = hosts.count
|
||||||
|
end
|
||||||
|
|
||||||
|
#get host record
|
||||||
|
response = cloud.get_host( host_id)
|
||||||
|
if response.status == 200
|
||||||
|
fqdn = response.body['fqdn']
|
||||||
|
end
|
||||||
|
|
||||||
|
#list hosts
|
||||||
|
response = cloud.list_hosts( zone_id)
|
||||||
|
if response.status == 200
|
||||||
|
hosts = response.body['hosts']
|
||||||
|
end
|
||||||
|
|
||||||
|
#delete the host record
|
||||||
|
response = cloud.delete_host( host_id)
|
||||||
|
if response.status == 200
|
||||||
|
puts "host record #{host_id} deleted from zone"
|
||||||
|
end
|
||||||
|
|
||||||
|
#delete the zone we created
|
||||||
|
response = cloud.delete_zone( zone_id)
|
||||||
|
if response.status == 200
|
||||||
|
puts "deleted zone #{zone_id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
rescue
|
||||||
|
#opps, ran into a problem
|
||||||
|
puts $!.message
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
@ -162,3 +270,4 @@ end
|
||||||
|
|
||||||
show_linode_dns_usage( LINODE_API_KEY)
|
show_linode_dns_usage( LINODE_API_KEY)
|
||||||
show_slicehost_dns_usage( SLICEHOST_PASSWORD)
|
show_slicehost_dns_usage( SLICEHOST_PASSWORD)
|
||||||
|
show_zerigo_dns_usage( ZERIGO_USER, ZERIGO_PASSWORD)
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
||||||
module Zerigo
|
module Zerigo
|
||||||
module Compute
|
module Compute
|
||||||
|
|
||||||
class FindZones < Fog::Parsers::Base
|
class FindHosts < Fog::Parsers::Base
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
@host = {}
|
@host = {}
|
||||||
|
|
|
@ -12,11 +12,9 @@ module Fog
|
||||||
def end_element(name)
|
def end_element(name)
|
||||||
case name
|
case name
|
||||||
when 'id', 'priority', 'ttl', 'zone-id'
|
when 'id', 'priority', 'ttl', 'zone-id'
|
||||||
@host[name] = @value.to_i
|
@response[name] = @value.to_i
|
||||||
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
when 'data', 'fqdn', 'host-type', 'hostname', 'notes', 'zone-id', 'created-at', 'updated-at'
|
||||||
@host[name] = @value
|
@response[name] = @value
|
||||||
when 'host'
|
|
||||||
@response['host'] = @host
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
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
|
|
|
@ -10,7 +10,9 @@ module Fog
|
||||||
#
|
#
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>
|
||||||
# * 'count'<~Integer>
|
# * 'count'<~Integer>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def count_hosts( zone_id)
|
def count_hosts( zone_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -12,6 +12,7 @@ module Fog
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * body<~Hash>
|
# * body<~Hash>
|
||||||
# * 'count'<~Integer>
|
# * 'count'<~Integer>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def count_zones()
|
def count_zones()
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -18,6 +18,7 @@ module Fog
|
||||||
# * ttl<~Integer>
|
# * ttl<~Integer>
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>
|
||||||
# * 'created-at'<~String>
|
# * 'created-at'<~String>
|
||||||
# * 'data'<~String>
|
# * 'data'<~String>
|
||||||
# * 'fqdn'<~String>
|
# * 'fqdn'<~String>
|
||||||
|
@ -29,6 +30,7 @@ module Fog
|
||||||
# * 'ttl'<~Integer>
|
# * 'ttl'<~Integer>
|
||||||
# * 'updated-at'<~String>
|
# * 'updated-at'<~String>
|
||||||
# * 'zone-id'<~String>
|
# * 'zone-id'<~String>
|
||||||
|
# * 'status'<~Integer> - 201 if successful
|
||||||
def create_host( zone_id, host_type, data, options = {} )
|
def create_host( zone_id, host_type, data, options = {} )
|
||||||
|
|
||||||
optional_tags= ''
|
optional_tags= ''
|
||||||
|
@ -47,7 +49,7 @@ module Fog
|
||||||
|
|
||||||
request(
|
request(
|
||||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{optional_tags}</host>},
|
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{optional_tags}</host>},
|
||||||
:expects => 200,
|
:expects => 201,
|
||||||
:method => 'POST',
|
:method => 'POST',
|
||||||
:parser => Fog::Parsers::Zerigo::Compute::CreateHost.new,
|
:parser => Fog::Parsers::Zerigo::Compute::CreateHost.new,
|
||||||
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
|
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"
|
||||||
|
|
|
@ -44,6 +44,8 @@ module Fog
|
||||||
# * 'hosts'<~String>
|
# * 'hosts'<~String>
|
||||||
# * 'axfr-ips'<~String>
|
# * 'axfr-ips'<~String>
|
||||||
# * 'restrict-axfr'<~String>
|
# * 'restrict-axfr'<~String>
|
||||||
|
# * 'status'<~Integer> - 201 if successful
|
||||||
|
|
||||||
def create_zone( domain, default_ttl, ns_type, options = {})
|
def create_zone( domain, default_ttl, ns_type, options = {})
|
||||||
|
|
||||||
optional_tags= ''
|
optional_tags= ''
|
||||||
|
|
|
@ -7,9 +7,9 @@ module Fog
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * host_id<~Integer> - Id of host record to delete
|
# * host_id<~Integer> - Id of host record to delete
|
||||||
#
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>: - HTTP status code will be result
|
# * response<~Excon::Response>:
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def delete_host(host_id)
|
def delete_host(host_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -7,9 +7,10 @@ module Fog
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * zone_id<~Integer> - Id of zone to delete
|
# * zone_id<~Integer> - Id of zone to delete
|
||||||
#
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>: - HTTP status code will be result
|
# * response<~Excon::Response>:
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
|
|
||||||
def delete_zone(zone_id)
|
def delete_zone(zone_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -27,6 +27,8 @@ module Fog
|
||||||
# * 'ttl'<~Integer>
|
# * 'ttl'<~Integer>
|
||||||
# * 'updated-at'<~String>
|
# * 'updated-at'<~String>
|
||||||
# * 'zone-id'<~String>
|
# * 'zone-id'<~String>
|
||||||
|
# * 'status'<~Integer> - 200 indicated success
|
||||||
|
#
|
||||||
def find_hosts( fqdn, zone_id = nil)
|
def find_hosts( fqdn, zone_id = nil)
|
||||||
if zone_id.nil?
|
if zone_id.nil?
|
||||||
#look for matching host across all zones
|
#look for matching host across all zones
|
||||||
|
|
|
@ -23,6 +23,7 @@ module Fog
|
||||||
# * 'ttl'<~Integer>
|
# * 'ttl'<~Integer>
|
||||||
# * 'updated-at'<~String>
|
# * 'updated-at'<~String>
|
||||||
# * 'zone-id'<~String>
|
# * 'zone-id'<~String>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def get_host( host_id)
|
def get_host( host_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -32,6 +32,8 @@ module Fog
|
||||||
# * 'hosts'<~Array> - a list of all host records. For the format of host info, see get_host()
|
# * 'hosts'<~Array> - a list of all host records. For the format of host info, see get_host()
|
||||||
# * 'axfr-ips'<~String>
|
# * 'axfr-ips'<~String>
|
||||||
# * 'restrict-axfr'<~String>
|
# * 'restrict-axfr'<~String>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
|
|
||||||
def get_zone(zone)
|
def get_zone(zone)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -19,6 +19,8 @@ module Fog
|
||||||
# * 'period-being'<~String> - date in following format 2010-07-01
|
# * 'period-being'<~String> - date in following format 2010-07-01
|
||||||
# * 'period-end'<~String> - date
|
# * 'period-end'<~String> - date
|
||||||
# * 'queries'<~Integer> - # of queries for the zone during period
|
# * 'queries'<~Integer> - # of queries for the zone during period
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
|
|
||||||
def get_zone_stats(zone_id)
|
def get_zone_stats(zone_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * body<~Hash>:
|
# * body<~Hash>:
|
||||||
# * 'hosts'<~Hash>
|
# * 'hosts'<~Array>
|
||||||
# * 'created-at'<~String>
|
# * 'created-at'<~String>
|
||||||
# * 'data'<~String>
|
# * 'data'<~String>
|
||||||
# * 'fqdn'<~String>
|
# * 'fqdn'<~String>
|
||||||
|
@ -24,6 +24,7 @@ module Fog
|
||||||
# * 'ttl'<~Integer>
|
# * 'ttl'<~Integer>
|
||||||
# * 'updated-at'<~String>
|
# * 'updated-at'<~String>
|
||||||
# * 'zone-id'<~String>
|
# * 'zone-id'<~String>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def list_hosts( zone_id)
|
def list_hosts( zone_id)
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -29,6 +29,7 @@ module Fog
|
||||||
# * 'hosts'<~String>
|
# * 'hosts'<~String>
|
||||||
# * 'axfr-ips'<~String>
|
# * 'axfr-ips'<~String>
|
||||||
# * 'restrict-axfr'<~String>
|
# * 'restrict-axfr'<~String>
|
||||||
|
# * 'status'<~Integer> - 200 indicates success
|
||||||
def list_zones
|
def list_zones
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
|
|
|
@ -3,8 +3,6 @@ module Fog
|
||||||
class Compute
|
class Compute
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
require 'fog/zerigo/parsers/compute/update_host'
|
|
||||||
|
|
||||||
# Update a host record
|
# Update a host record
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
|
@ -18,6 +16,7 @@ module Fog
|
||||||
# * ttl<~Integer>
|
# * ttl<~Integer>
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
|
# * 'status'<~Integer> - 200 for success
|
||||||
#
|
#
|
||||||
def update_host( host_id, options = {})
|
def update_host( host_id, options = {})
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ module Fog
|
||||||
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host>#{optional_tags}</host>},
|
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><host>#{optional_tags}</host>},
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:method => 'PUT',
|
:method => 'PUT',
|
||||||
:parser => Fog::Parsers::Zerigo::Compute::UpdateHost.new,
|
|
||||||
:path => "/api/1.1/hosts/#{host_id}.xml"
|
:path => "/api/1.1/hosts/#{host_id}.xml"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,9 +23,7 @@ module Fog
|
||||||
#
|
#
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * header<~Hash>
|
|
||||||
# * 'status'<~Integer> - 200 for success
|
# * 'status'<~Integer> - 200 for success
|
||||||
#
|
|
||||||
def update_zone( zone_id, options = {})
|
def update_zone( zone_id, options = {})
|
||||||
|
|
||||||
optional_tags= ''
|
optional_tags= ''
|
||||||
|
|
Loading…
Reference in a new issue