Skip to content

Commit

Permalink
[slicehost|dns] give dns its own namespace/service
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Dec 21, 2010
1 parent 8d7733c commit 8b3081a
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 141 deletions.
1 change: 1 addition & 0 deletions lib/fog/slicehost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Slicehost

service_path 'fog/slicehost'
service :compute
service :dns

def self.new(attributes = {})
location = caller.first
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/slicehost/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def class_for(key)
case key
when :compute, :slices
Fog::Slicehost::Compute
when :dns
Fog::Slicehost::DNS
else
raise ArgumentError, "Unrecognized service: #{key}"
end
Expand Down
8 changes: 0 additions & 8 deletions lib/fog/slicehost/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class Compute < Fog::Service
request :get_slice
request :get_slices
request :reboot_slice
request :create_zone
request :delete_zone
request :get_zones
request :get_zone
request :create_record
request :delete_record
request :get_records
request :get_record

class Mock

Expand Down
84 changes: 84 additions & 0 deletions lib/fog/slicehost/dns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
module Fog
module Slicehost
class DNS < Fog::Service

requires :slicehost_password
recognizes :host, :port, :scheme, :persistent

model_path 'fog/slicehost/models/dns'

request_path 'fog/slicehost/requests/dns'
request :create_record
request :create_zone
request :delete_record
request :delete_zone
request :get_record
request :get_records
request :get_zone
request :get_zones

class Mock

def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end

def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end

def initialize(options={})
@slicehost_password = options[:slicehost_password]
@data = self.class.data[@slicehost_password]
end

end

class Real

def initialize(options={})
@slicehost_password = options[:slicehost_password]
@host = options[:host] || "api.slicehost.com"
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end

def reload
@connection.reset
end

def request(params)
params[:headers] ||= {}
params[:headers].merge!({
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).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.merge!({:host => @host}))
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Slicehost::DNS::NotFound.slurp(error)
else
error
end
end

response
end

end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class CreateRecord < Fog::Parsers::Base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class CreateZone < Fog::Parsers::Base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class GetRecord < Fog::Parsers::Base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class GetRecords < Fog::Parsers::Base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class GetZone < Fog::Parsers::Base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fog
module Parsers
module Slicehost
module Compute
module DNS

class GetZones < Fog::Parsers::Base

Expand Down
75 changes: 0 additions & 75 deletions lib/fog/slicehost/requests/compute/dns_manager.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/fog/slicehost/requests/compute/mock.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

require 'fog/slicehost/parsers/compute/create_record'
require 'fog/slicehost/parsers/dns/create_record'

# Create a new record in a DNS zone - or update an existing one
# ==== Parameters
Expand Down Expand Up @@ -42,7 +42,7 @@ def create_record( record_type, zone_id, name, data, options = {})
: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,
:parser => Fog::Parsers::Slicehost::DNS::CreateRecord.new,
:path => 'records.xml'
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

require 'fog/slicehost/parsers/compute/create_zone'
require 'fog/slicehost/parsers/dns/create_zone'

# Create a new zone for Slicehost's DNS servers to serve/host
# ==== Parameters
Expand Down Expand Up @@ -35,7 +35,7 @@ def create_zone(origin, options = {})
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone><origin>#{origin}</origin>#{optional_tags}</zone>},
:expects => 201,
:method => 'POST',
:parser => Fog::Parsers::Slicehost::Compute::CreateZone.new,
:parser => Fog::Parsers::Slicehost::DNS::CreateZone.new,
:path => 'zones.xml'
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

# Delete a record from the specified DNS zone
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

# Delete a zone from Slicehost's DNS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

require 'fog/slicehost/parsers/compute/get_record'
require 'fog/slicehost/parsers/dns/get_record'

# Get an individual DNS record from the specified zone
#
Expand All @@ -21,7 +21,7 @@ def get_record( record_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Slicehost::Compute::GetRecords.new,
:parser => Fog::Parsers::Slicehost::DNS::GetRecords.new,
:path => "records/#{record_id}.xml"
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

require 'fog/slicehost/parsers/compute/get_records'
require 'fog/slicehost/parsers/dns/get_records'

# Get all the DNS records across all the DNS zones for this account
#
Expand All @@ -22,7 +22,7 @@ def get_records
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Slicehost::Compute::GetRecords.new,
:parser => Fog::Parsers::Slicehost::DNS::GetRecords.new,
:path => "records.xml"
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Fog
module Slicehost
class Compute
class DNS
class Real

require 'fog/slicehost/parsers/compute/get_zone'
require 'fog/slicehost/parsers/dns/get_zone'

# Get details of a DNS zone
#
Expand All @@ -21,7 +21,7 @@ def get_zone(zone_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Slicehost::Compute::GetZone.new,
:parser => Fog::Parsers::Slicehost::DNS::GetZone.new,
:path => "/zones/#{zone_id}.xml"
)
end
Expand Down
Loading

0 comments on commit 8b3081a

Please sign in to comment.