2011-08-27 22:06:46 -04:00
|
|
|
require 'fog/core/model'
|
2011-08-29 11:37:01 -04:00
|
|
|
require 'fog/rackspace/models/dns/records'
|
2011-08-27 22:06:46 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module DNS
|
|
|
|
class Rackspace
|
|
|
|
|
|
|
|
class Zone < Fog::Model
|
2011-08-28 15:41:48 -04:00
|
|
|
include Fog::DNS::Rackspace::Callback
|
2011-08-27 22:06:46 -04:00
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :email, :aliases => 'emailAddress'
|
|
|
|
attribute :domain, :aliases => 'name'
|
|
|
|
attribute :created
|
|
|
|
attribute :updated
|
|
|
|
attribute :account_id, :aliases => 'accountId'
|
|
|
|
attribute :ttl
|
|
|
|
attribute :nameservers
|
|
|
|
attribute :comment
|
|
|
|
|
|
|
|
def destroy
|
2011-08-28 10:53:43 -04:00
|
|
|
response = connection.remove_domain(identity)
|
2011-08-27 22:06:46 -04:00
|
|
|
wait_for_job response.body['jobId'], Fog.timeout
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2011-08-28 15:41:48 -04:00
|
|
|
def records
|
|
|
|
@records ||= begin
|
|
|
|
Fog::DNS::Rackspace::Records.new(
|
|
|
|
:zone => self,
|
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-27 22:06:46 -04:00
|
|
|
def save
|
|
|
|
if identity
|
|
|
|
update
|
|
|
|
else
|
|
|
|
create
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create
|
2011-08-28 10:53:43 -04:00
|
|
|
requires :domain, :email
|
2011-08-27 22:06:46 -04:00
|
|
|
|
|
|
|
data = { :name => domain, :email => email }
|
|
|
|
response = connection.create_domains([data])
|
|
|
|
|
|
|
|
response = wait_for_job response.body['jobId']
|
2011-11-10 20:53:00 -05:00
|
|
|
merge_attributes(response.body['response']['domains'].select {|domain| domain['name'] == self.domain}.first)
|
2011-08-27 22:06:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
requires :ttl, :email
|
|
|
|
|
|
|
|
response = connection.modify_domain(identity, { :ttl => ttl, :comment => comment, :email => email})
|
|
|
|
wait_for_job response.body['jobId']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|