1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|dns] record models

This commit is contained in:
Brian Hartsock 2011-08-28 15:41:48 -04:00
parent 754947b98f
commit 7ec6c6cc7b
5 changed files with 157 additions and 20 deletions

View file

@ -0,0 +1,28 @@
module Fog
module DNS
class Rackspace
module Callback
protected
def wait_for_job(job_id, timeout=Fog.timeout, interval=1)
retries = 5
response = nil
Fog.wait_for(timeout, interval) do
response = connection.callback job_id
if response.status != 202
true
elsif retries == 0
raise Fog::Errors::Error.new("Wait on job #{job_id} took too long")
else
retries -= 1
false
end
end
response
end
end
end
end
end

View file

@ -0,0 +1,78 @@
require 'fog/core/model'
require 'fog/dns/models/rackspace/callback'
module Fog
module DNS
class Rackspace
class Record < Fog::Model
include Fog::DNS::Rackspace::Callback
extend Fog::Deprecation
deprecate :ip, :value
deprecate :ip=, :value=
identity :id
attribute :name
attribute :value, :aliases => 'data'
attribute :ttl
attribute :type
attribute :priority
attribute :created
attribute :updated
def destroy
requires :zone, :identity
wait_for_job connection.remove_record(@zone.identity, identity).body['jobId']
true
end
def zone
@zone
end
def save
if identity
update
else
create
end
end
private
def create
requires :name, :type, :value, :zone
options = {
:name => name,
:type => type,
:data => value
}
response = wait_for_job connection.add_records(@zone.identity, [options]).body['jobId']
merge_attributes(response.body['records'].first)
true
end
def update
requires :identity, :zone
options = {}
options[:name] = name if name
options[:type] = type if type
options[:data] = value if value
options[:priority] = priority if priority
wait_for_job connection.modify_record(@zone.identity, identity, options).body['jobId']
true
end
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end

View file

@ -0,0 +1,38 @@
require 'fog/core/collection'
require 'fog/dns/models/rackspace/record'
module Fog
module DNS
class Rackspace
class Records < Fog::Collection
attribute :zone
model Fog::DNS::Rackspace::Record
def all
requires :zone
data = connection.list_records(zone.identity)
load(data.body['records'])
end
def get(record_id)
requires :zone
data = connection.list_record_details(zone.identity, record_id).body
new(data)
#nil or empty string will trigger an argument error
rescue ArgumentError
nil
rescue Fog::Rackspace::Errors::NotFound
nil
end
def new(attributes = {})
requires :zone
super({ :zone => zone }.merge!(attributes))
end
end
end
end
end

View file

@ -1,11 +1,12 @@
require 'fog/core/model'
#require 'fog/dns/models/rackspace/records'
require 'fog/dns/models/rackspace/records'
module Fog
module DNS
class Rackspace
class Zone < Fog::Model
include Fog::DNS::Rackspace::Callback
identity :id
@ -24,6 +25,15 @@ module Fog
true
end
def records
@records ||= begin
Fog::DNS::Rackspace::Records.new(
:zone => self,
:connection => connection
)
end
end
def save
if identity
update
@ -35,23 +45,6 @@ module Fog
private
def wait_for_job(job_id, timeout=Fog.timeout, interval=1)
retries = 5
response = nil
Fog.wait_for(timeout, interval) do
response = connection.callback job_id
if response.status != 202
true
elsif retries == 0
raise Fog::Errors::Error.new("Wait on job #{job_id} took too long")
else
retries -= 1
false
end
end
response
end
def create
requires :domain, :email

View file

@ -10,8 +10,8 @@ module Fog
recognizes :rackspace_auth_token
model_path 'fog/dns/models/rackspace'
#model :record
#collection :records
model :record
collection :records
model :zone
collection :zones