1
0
Fork 0
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:
Athir Nuaimi 2010-12-13 08:51:04 -05:00
parent 65e6c49757
commit 5ff4551adc
18 changed files with 150 additions and 59 deletions

View file

@ -1,10 +1,13 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
# require 'fog'
require '/Users/anuaimi/code/fog/lib/fog'
LINODE_API_KEY = '--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
@ -155,6 +158,111 @@ def show_slicehost_dns_usage( password)
true
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_slicehost_dns_usage( SLICEHOST_PASSWORD)
show_zerigo_dns_usage( ZERIGO_USER, ZERIGO_PASSWORD)

View file

@ -3,7 +3,7 @@ module Fog
module Zerigo
module Compute
class FindZones < Fog::Parsers::Base
class FindHosts < Fog::Parsers::Base
def reset
@host = {}

View file

@ -12,11 +12,9 @@ module Fog
def end_element(name)
case name
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'
@host[name] = @value
when 'host'
@response['host'] = @host
@response[name] = @value
end
end

View file

@ -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

View file

@ -10,7 +10,9 @@ module Fog
#
# ==== Returns
# * response<~Excon::Response>:
# * 'count'<~Integer>
# * body<~Hash>
# * 'count'<~Integer>
# * 'status'<~Integer> - 200 indicates success
def count_hosts( zone_id)
request(
:expects => 200,

View file

@ -12,6 +12,7 @@ module Fog
# * response<~Excon::Response>:
# * body<~Hash>
# * 'count'<~Integer>
# * 'status'<~Integer> - 200 indicates success
def count_zones()
request(
:expects => 200,

View file

@ -18,17 +18,19 @@ module Fog
# * ttl<~Integer>
# ==== Returns
# * response<~Excon::Response>:
# * '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>
# * 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= ''
@ -47,7 +49,7 @@ module Fog
request(
: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',
:parser => Fog::Parsers::Zerigo::Compute::CreateHost.new,
:path => "/api/1.1/zones/#{zone_id}/hosts.xml"

View file

@ -44,6 +44,8 @@ module Fog
# * 'hosts'<~String>
# * 'axfr-ips'<~String>
# * 'restrict-axfr'<~String>
# * 'status'<~Integer> - 201 if successful
def create_zone( domain, default_ttl, ns_type, options = {})
optional_tags= ''

View file

@ -7,9 +7,9 @@ module Fog
#
# ==== Parameters
# * host_id<~Integer> - Id of host record to delete
#
# ==== Returns
# * response<~Excon::Response>: - HTTP status code will be result
# * response<~Excon::Response>:
# * 'status'<~Integer> - 200 indicates success
def delete_host(host_id)
request(
:expects => 200,

View file

@ -7,9 +7,10 @@ module Fog
#
# ==== Parameters
# * zone_id<~Integer> - Id of zone to delete
#
# ==== Returns
# * response<~Excon::Response>: - HTTP status code will be result
# * response<~Excon::Response>:
# * 'status'<~Integer> - 200 indicates success
def delete_zone(zone_id)
request(
:expects => 200,

View file

@ -27,6 +27,8 @@ module Fog
# * '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

View file

@ -23,6 +23,7 @@ module Fog
# * 'ttl'<~Integer>
# * 'updated-at'<~String>
# * 'zone-id'<~String>
# * 'status'<~Integer> - 200 indicates success
def get_host( host_id)
request(
:expects => 200,

View file

@ -32,6 +32,8 @@ module Fog
# * '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)
request(
:expects => 200,

View file

@ -19,6 +19,8 @@ module Fog
# * '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,

View file

@ -12,7 +12,7 @@ module Fog
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'hosts'<~Hash>
# * 'hosts'<~Array>
# * 'created-at'<~String>
# * 'data'<~String>
# * 'fqdn'<~String>
@ -24,6 +24,7 @@ module Fog
# * 'ttl'<~Integer>
# * 'updated-at'<~String>
# * 'zone-id'<~String>
# * 'status'<~Integer> - 200 indicates success
def list_hosts( zone_id)
request(
:expects => 200,

View file

@ -29,6 +29,7 @@ module Fog
# * 'hosts'<~String>
# * 'axfr-ips'<~String>
# * 'restrict-axfr'<~String>
# * 'status'<~Integer> - 200 indicates success
def list_zones
request(
:expects => 200,

View file

@ -3,8 +3,6 @@ module Fog
class Compute
class Real
require 'fog/zerigo/parsers/compute/update_host'
# Update a host record
#
# ==== Parameters
@ -18,6 +16,7 @@ module Fog
# * ttl<~Integer>
# ==== Returns
# * response<~Excon::Response>:
# * 'status'<~Integer> - 200 for success
#
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>},
:expects => 200,
:method => 'PUT',
:parser => Fog::Parsers::Zerigo::Compute::UpdateHost.new,
:path => "/api/1.1/hosts/#{host_id}.xml"
)
end

View file

@ -23,9 +23,7 @@ module Fog
#
# ==== Returns
# * response<~Excon::Response>:
# * header<~Hash>
# * 'status'<~Integer> - 200 for success
#
# * 'status'<~Integer> - 200 for success
def update_zone( zone_id, options = {})
optional_tags= ''