1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/dns/zone.rb

67 lines
1.6 KiB
Ruby
Raw Normal View History

2011-08-27 22:06:46 -04:00
require 'fog/core/model'
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
response = service.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,
:service => service
2011-08-28 15:41:48 -04:00
)
end
end
2011-08-27 22:06:46 -04:00
def save
if persisted?
2011-08-27 22:06:46 -04:00
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 = service.create_domains([data])
2011-08-27 22:06:46 -04:00
response = wait_for_job response.body['jobId']
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 = service.modify_domain(identity, { :ttl => ttl, :comment => comment, :email => email})
2011-08-27 22:06:46 -04:00
wait_for_job response.body['jobId']
end
end
end
end
end