mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
all request types support by the rage4 api without mocks or tests
This commit is contained in:
parent
d5740ab24d
commit
341ccf56f3
30 changed files with 1070 additions and 0 deletions
|
@ -30,6 +30,7 @@ require 'fog/local'
|
|||
require 'fog/bare_metal_cloud'
|
||||
require 'fog/ninefold'
|
||||
require 'fog/rackspace'
|
||||
require 'fog/rage4'
|
||||
require 'fog/riakcs'
|
||||
require 'fog/openstack'
|
||||
require 'fog/ovirt'
|
||||
|
|
|
@ -81,6 +81,7 @@ require 'fog/bin/local'
|
|||
require 'fog/bin/bare_metal_cloud'
|
||||
require 'fog/bin/ninefold'
|
||||
require 'fog/bin/rackspace'
|
||||
require 'fog/bin/rage4'
|
||||
require 'fog/bin/riakcs'
|
||||
require 'fog/bin/openstack'
|
||||
require 'fog/bin/ovirt'
|
||||
|
|
31
lib/fog/bin/rage4.rb
Normal file
31
lib/fog/bin/rage4.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
class Rage4 < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :dns
|
||||
Fog::DNS::Rage4
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :dns
|
||||
Fog::Logger.warning("Rage4[:dns] is not recommended, use DNS[:rage4] for portability")
|
||||
Fog::DNS.new(:provider => 'Rage4')
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key.inspect}"
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
def services
|
||||
Fog::Rage4.services
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -74,6 +74,8 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
|
|||
:rackspace_username:
|
||||
:rackspace_servicenet:
|
||||
:rackspace_cdn_ssl:
|
||||
:rage4_email:
|
||||
:rage4_password:
|
||||
:riakcs_access_key_id:
|
||||
:riakcs_secret_access_key:
|
||||
:stormondemand_username:
|
||||
|
|
110
lib/fog/rage4/dns.rb
Normal file
110
lib/fog/rage4/dns.rb
Normal file
|
@ -0,0 +1,110 @@
|
|||
require 'fog/rage4'
|
||||
require 'fog/dns'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4 < Fog::Service
|
||||
|
||||
requires :rage4_email, :rage4_api_key
|
||||
recognizes :rage4_url, :host, :path, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/rage4/models/dns'
|
||||
model :record
|
||||
collection :records
|
||||
model :zone
|
||||
collection :zones
|
||||
|
||||
request_path 'fog/rage4/requests/dns'
|
||||
request :list_domains
|
||||
request :get_domain
|
||||
request :get_domain_by_name
|
||||
request :create_domain
|
||||
request :create_domain_vanity
|
||||
request :create_reverse_domain_4
|
||||
request :create_reverse_domain_6
|
||||
request :update_domain
|
||||
request :delete_domain
|
||||
request :import_domain
|
||||
request :sync_domain
|
||||
|
||||
request :export_zone_file
|
||||
request :show_current_usage
|
||||
request :show_global_usage
|
||||
request :list_record_types
|
||||
request :list_geo_regions
|
||||
request :list_records
|
||||
|
||||
request :create_record
|
||||
request :update_record
|
||||
request :delete_record
|
||||
request :set_record_failover
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:domains => [],
|
||||
:records => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@rage4_email = options[:rage4_email]
|
||||
@rage4_password = options[:rage4_api_key]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@rage4_email]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@rage4_email)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
@rage4_email = options[:rage4_email]
|
||||
@rage4_password = options[:rage4_api_key]
|
||||
@connection_options = options[:connection_options] || {}
|
||||
if options[:rage4_url]
|
||||
uri = URI.parse(options[:rage4_url])
|
||||
options[:host] = uri.host
|
||||
options[:port] = uri.port
|
||||
options[:scheme] = uri.scheme
|
||||
end
|
||||
@host = options[:host] || "secure.rage4.com"
|
||||
@persistent = options[:persistent] || false
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:headers] ||= {}
|
||||
key = "#{@rage4_email}:#{@rage4_password}"
|
||||
params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",'')})
|
||||
|
||||
response = @connection.request(params)
|
||||
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
66
lib/fog/rage4/models/dns/record.rb
Normal file
66
lib/fog/rage4/models/dns/record.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
|
||||
class Record < Fog::Model
|
||||
extend Fog::Deprecation
|
||||
deprecate :ip, :value
|
||||
deprecate :ip=, :value=
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :value, :aliases => "content"
|
||||
attribute :ttl
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
attribute :zone_id, :aliases => "domain_id"
|
||||
attribute :type, :aliases => "record_type"
|
||||
attribute :priority, :aliases => "prio"
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
service.delete_record(zone.id, identity)
|
||||
true
|
||||
end
|
||||
|
||||
def zone
|
||||
@zone
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name, :type, :value
|
||||
options = {}
|
||||
options[:prio] = priority if priority
|
||||
options[:ttl] = ttl if ttl
|
||||
|
||||
# decide whether its a new record or update of an existing
|
||||
if id.nil?
|
||||
data = service.create_record(zone.id, name, type, value, options)
|
||||
else
|
||||
options[:name] = name if name
|
||||
options[:content] = value if value
|
||||
options[:type] = type if type
|
||||
data = service.update_record(zone.id, id, options)
|
||||
end
|
||||
|
||||
merge_attributes(data.body["record"])
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def zone=(new_zone)
|
||||
@zone = new_zone
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/rage4/models/dns/records.rb
Normal file
38
lib/fog/rage4/models/dns/records.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rage4/models/dns/record'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
|
||||
class Records < Fog::Collection
|
||||
|
||||
attribute :zone
|
||||
|
||||
model Fog::DNS::Rage4::Record
|
||||
|
||||
def all
|
||||
requires :zone
|
||||
clear
|
||||
data = service.list_records(zone.id).body.map {|record| record['record']}
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(record_id)
|
||||
requires :zone
|
||||
data = service.get_record(zone.id, record_id).body["record"]
|
||||
new(data)
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :zone
|
||||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
48
lib/fog/rage4/models/dns/zone.rb
Normal file
48
lib/fog/rage4/models/dns/zone.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/rage4/models/dns/records'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
|
||||
class Zone < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :domain, :aliases => 'name'
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
|
||||
def destroy
|
||||
service.delete_domain(identity)
|
||||
true
|
||||
end
|
||||
|
||||
def records
|
||||
@records ||= begin
|
||||
Fog::DNS::Rage4::Records.new(
|
||||
:zone => self,
|
||||
:service => service
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def nameservers
|
||||
[
|
||||
"ns1.r4ns.com",
|
||||
"ns2.r4ns.com",
|
||||
]
|
||||
end
|
||||
|
||||
def save
|
||||
requires :domain
|
||||
data = service.create_domain(domain).body["domain"]
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/rage4/models/dns/zones.rb
Normal file
29
lib/fog/rage4/models/dns/zones.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rage4/models/dns/zone'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
|
||||
class Zones < Fog::Collection
|
||||
|
||||
model Fog::DNS::Rage4::Zone
|
||||
|
||||
def all
|
||||
clear
|
||||
data = service.list_domains.body.map {|zone| zone['domain']}
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(zone_id)
|
||||
data = service.get_domain(zone_id).body['domain']
|
||||
new(data)
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/rage4/requests/dns/create_domain.rb
Normal file
30
lib/fog/rage4/requests/dns/create_domain.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a domain.
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def create_domain(name, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/createregulardomain/?name=#{name}&email=#{email}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/rage4/requests/dns/create_domain_vanity.rb
Normal file
33
lib/fog/rage4/requests/dns/create_domain_vanity.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a domain with a vanity name server.
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
# * nsname<~String> - vanity ns domain name
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def create_domain_vanity(name, nsname, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
nsprefix = options[:nsprefix] || 'ns'
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/createregulardomain/?name=#{name}&email=#{email}" +
|
||||
"&nsname=#{nsname}&nsprefix=#{nsprefix}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
65
lib/fog/rage4/requests/dns/create_record.rb
Normal file
65
lib/fog/rage4/requests/dns/create_record.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a record
|
||||
# ==== Parameters
|
||||
# * domain id <~Integer> The id of the domain you wish to create a record for
|
||||
# * name <~String> Name of record, include domain name
|
||||
# * content <~String> IP address or Domain name
|
||||
# * type <~Integer> The type of record to create see list_record_types
|
||||
# * priority <~Integer> - Record prioirity (nullable)
|
||||
# * failover <~Boolean> Enable/disable failover default false
|
||||
# * failovercontent <~String> Failover value, only valid for A/AAAA records
|
||||
# * ttl <~Integer> - Time to live
|
||||
# * geozone <~Long> Geo region id, see list_geo_regions
|
||||
# * geolock <~Boolean> Lock geo coordinates, default false
|
||||
# * geolat <~Double> Geo latitude, (nullable)
|
||||
# * geolong <~Double> Geo longitude, (nullable)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
|
||||
|
||||
# https://secure.rage4.com/rapi/createrecord/
|
||||
|
||||
|
||||
def create_record(domain_id, name, content, type, options = {})
|
||||
|
||||
|
||||
path = "/rapi/createregulardomain/#{domain_id}?"
|
||||
path << "?name=#{name}&content=#{content}&type=#{type}"
|
||||
|
||||
path << "&priority=#{options[:priority]}" if options[:priority]
|
||||
|
||||
failovercontent = options[:failover] || false
|
||||
path << "&failover=#{options[:failover]}"
|
||||
|
||||
path << "&failovercontent=#{failovercontent}" if options[:failovercontent]
|
||||
|
||||
ttl = options[:ttl] || 3600
|
||||
path << "&ttl=#{ttl}"
|
||||
|
||||
path << "&geozone=#{options[:geozone]}" if options[:geozone]
|
||||
path << "&geozone=#{options[:geolock]}" if options[:geolock]
|
||||
path << "&geozone=#{options[:geolat]}" if options[:geolat]
|
||||
path << "&geozone=#{options[:geolong]}" if options[:geolong]
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/rage4/requests/dns/create_reverse_domain_4.rb
Normal file
32
lib/fog/rage4/requests/dns/create_reverse_domain_4.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a domain.
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
# * subnet<~Integer> - subnet integer
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def create_reverse_domain_4(name, subnet, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/createreversedomain4/?name=#{name}&email=#{email}" +
|
||||
"&subnet=#{subnet}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/rage4/requests/dns/create_reverse_domain_6.rb
Normal file
32
lib/fog/rage4/requests/dns/create_reverse_domain_6.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a domain.
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
# * subnet<~Integer> - subnet integer
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def create_reverse_domain_6(name, subnet, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/createreversedomain4/?name=#{name}&email=#{email}" +
|
||||
"&subnet=#{subnet}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/rage4/requests/dns/delete_domain.rb
Normal file
28
lib/fog/rage4/requests/dns/delete_domain.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Delete a specific omain
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def delete_domain(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/deletedomain/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/rage4/requests/dns/delete_record.rb
Normal file
28
lib/fog/rage4/requests/dns/delete_record.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Delete a specific omrecordain
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def delete_record(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/deleterecord/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/rage4/requests/dns/export_zone_file.rb
Normal file
28
lib/fog/rage4/requests/dns/export_zone_file.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Delete a specific omain
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def export_zone_file(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/exportzonefile/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/rage4/requests/dns/get_domain.rb
Normal file
44
lib/fog/rage4/requests/dns/get_domain.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Get the details for a specific domain in your account. .
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~Integer>
|
||||
# * 'name'<~String>
|
||||
# * 'owner_email'<~String>
|
||||
# * 'type'<~Integer>
|
||||
# * 'subnet_mask'<~Integer>
|
||||
def get_domain(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/getdomain/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_domain(id)
|
||||
domain = self.data[:domains].detect do |domain|
|
||||
domain["domain"]["id"] == id
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = domain
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/rage4/requests/dns/get_domain_by_name.rb
Normal file
44
lib/fog/rage4/requests/dns/get_domain_by_name.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Get the details for a specific domain in your account.
|
||||
# ==== Parameters
|
||||
# * id<~String> - name of domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~Integer>
|
||||
# * 'name'<~String>
|
||||
# * 'owner_email'<~String>
|
||||
# * 'type'<~Integer>
|
||||
# * 'subnet_mask'<~Integer>
|
||||
def get_domain_by_name(name)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/getdomainbyname/?name=#{name}")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def get_domain_by_name(name)
|
||||
domain = self.data[:domains].detect do |domain|
|
||||
domain["domain"]["name"] == id
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = domain
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/rage4/requests/dns/import_domain.rb
Normal file
29
lib/fog/rage4/requests/dns/import_domain.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Import a domain. You need to allow AXFR transfers.
|
||||
# Only regular domains are supported.
|
||||
# ==== Parameters
|
||||
# * name<~String> - name of the domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def import_domain(name)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/importdomain/#{name}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/rage4/requests/dns/list_domains.rb
Normal file
41
lib/fog/rage4/requests/dns/list_domains.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Get the details for all domains in your account.
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'domains'<~Hash>
|
||||
# * 'id'<~Integer>
|
||||
# * 'name'<~String>
|
||||
# * 'owner_email'<~String>
|
||||
# * 'type'<~Integer>
|
||||
# * 'subnet_mask'<~Integer>
|
||||
def list_domains
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/rapi/getdomains'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_domains
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = self.data[:domains]
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/rage4/requests/dns/list_geo_regions.rb
Normal file
25
lib/fog/rage4/requests/dns/list_geo_regions.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# List all the record types available
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'domains'<~Hash>
|
||||
|
||||
def list_geo_regions
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/rapi/listgeoregions'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/rage4/requests/dns/list_record_types.rb
Normal file
25
lib/fog/rage4/requests/dns/list_record_types.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# List all the record types available
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'domains'<~Hash>
|
||||
|
||||
def list_record_types
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/rapi/listrecordtypes'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/rage4/requests/dns/list_records.rb
Normal file
44
lib/fog/rage4/requests/dns/list_records.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Get the list of records for the specific domain.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * id<~Integer>
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * records<Array~>
|
||||
# * name<~String>
|
||||
# * ttl<~Integer>
|
||||
# * created_at<~String>
|
||||
# * special_type<~String>
|
||||
# * updated_at<~String>
|
||||
# * domain_id<~Integer>
|
||||
# * id<~Integer>
|
||||
# * content<~String>
|
||||
# * record_type<~String>
|
||||
# * prio<~Integer>
|
||||
def list_records(id)
|
||||
request( :expects => 200,
|
||||
:method => "GET",
|
||||
:path => "/rapi/getrecords/#{id}" )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_records(domain)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = self.data[:records][domain] || []
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/rage4/requests/dns/set_record_failover.rb
Normal file
29
lib/fog/rage4/requests/dns/set_record_failover.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Set a failover to on or off
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def set_record_failover(id, active, failover)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/setrecordfailover/#{id}&active=#{active}&failover=#{failover}"
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/rage4/requests/dns/show_current_usage.rb
Normal file
28
lib/fog/rage4/requests/dns/show_current_usage.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Delete a specific omain
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def show_current_usage(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/showcurrentusage/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/rage4/requests/dns/show_global_usage.rb
Normal file
23
lib/fog/rage4/requests/dns/show_global_usage.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Delete a specific omain
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
def show_global_usage
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/showcurrentglobalusage/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/rage4/requests/dns/sync_domain.rb
Normal file
29
lib/fog/rage4/requests/dns/sync_domain.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Sync to external server ("Shadow Master")
|
||||
# You need to allow AXFR transfers
|
||||
# Only regular domains are supported
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
# * ip<~String> - Ip address of remote server
|
||||
# ==== Returns
|
||||
#
|
||||
#
|
||||
|
||||
def sync_domain(name, ip)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/syncdomain/?name=#{name}&server=#{ip}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
43
lib/fog/rage4/requests/dns/update_domain.rb
Normal file
43
lib/fog/rage4/requests/dns/update_domain.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Update an existing domain
|
||||
# ==== Parameters
|
||||
# * domain<~Integer> - domain integer value
|
||||
# * email <~String> - email of domain owner
|
||||
# * nsprefix<~String> - vanity ns prefix (nullable)
|
||||
# * nsname<~String> - vanity ns domain name (nullable)
|
||||
# * enablevanity<~String> - activate/deactivate
|
||||
# * failover<~Boolean> - failover enable
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
def update_domain(name, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
|
||||
path = "/rapi/updatedomain/?name=#{name}&email=#{email}"
|
||||
|
||||
path << "&nsname=#{options[:nsname]}" if options[:nsname]
|
||||
path << "&nsprefix=#{options[:nsprefix]}" if options[:nsprefix]
|
||||
path << "&enablevanity=#{options[:enablevanity]}" if options[:enablevanity]
|
||||
path << "&failover=#{options[:failover]}" if options[:failover]
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/rage4/requests/dns/update_record.rb
Normal file
64
lib/fog/rage4/requests/dns/update_record.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a record
|
||||
# ==== Parameters
|
||||
# * record_id <~Integer> The id of the record you wish to update
|
||||
# * name <~String> Name of record, include domain name
|
||||
# * content <~String> IP address or Domain name
|
||||
# * type <~Integer> The type of record to create see list_record_types
|
||||
# * priority <~Integer> - Record prioirity (nullable)
|
||||
# * failover <~Boolean> Enable/disable failover default false
|
||||
# * failovercontent <~String> Failover value, only valid for A/AAAA records
|
||||
# * ttl <~Integer> - Time to live
|
||||
# * geozone <~Long> Geo region id, see list_geo_regions
|
||||
# * geolock <~Boolean> Lock geo coordinates, default false
|
||||
# * geolat <~Double> Geo latitude, (nullable)
|
||||
# * geolong <~Double> Geo longitude, (nullable)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'status'<~Boolean>
|
||||
# * 'id'<~Integer>
|
||||
# * 'error'<~String>
|
||||
|
||||
|
||||
# https://secure.rage4.com/rapi/createrecord/
|
||||
|
||||
|
||||
def update_record(record_id, name, content, type, options = {})
|
||||
|
||||
path = "/rapi/updaterecord/#{record_id}?"
|
||||
path << "?name=#{name}&content=#{content}&type=#{type}"
|
||||
|
||||
path << "&priority=#{options[:priority]}" if options[:priority]
|
||||
|
||||
failovercontent = options[:failover] || false
|
||||
path << "&failover=#{options[:failover]}"
|
||||
|
||||
path << "&failovercontent=#{failovercontent}" if options[:failovercontent]
|
||||
|
||||
ttl = options[:ttl] || 3600
|
||||
path << "&ttl=#{ttl}"
|
||||
|
||||
path << "&geozone=#{options[:geozone]}" if options[:geozone]
|
||||
path << "&geozone=#{options[:geolock]}" if options[:geolock]
|
||||
path << "&geozone=#{options[:geolat]}" if options[:geolat]
|
||||
path << "&geozone=#{options[:geolong]}" if options[:geolong]
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue