mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2599 from grossjo/rage4_dns_support
Rage4 dns support
This commit is contained in:
commit
ba4215c1c2
34 changed files with 1160 additions and 4 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:
|
||||
|
|
2
lib/fog/rage4.rb
Normal file
2
lib/fog/rage4.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require 'fog/rage4/dns'
|
||||
|
11
lib/fog/rage4/core.rb
Normal file
11
lib/fog/rage4/core.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'fog/core'
|
||||
|
||||
module Fog
|
||||
module Rage4
|
||||
|
||||
extend Fog::Provider
|
||||
|
||||
service(:dns, 'DNS')
|
||||
|
||||
end
|
||||
end
|
74
lib/fog/rage4/dns.rb
Normal file
74
lib/fog/rage4/dns.rb
Normal file
|
@ -0,0 +1,74 @@
|
|||
require 'fog/rage4/core'
|
||||
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 :create_domain
|
||||
request :create_domain_vanity
|
||||
request :create_reverse_domain_4
|
||||
request :get_domain
|
||||
request :get_domain_by_name
|
||||
request :update_domain
|
||||
request :delete_domain
|
||||
request :show_current_usage
|
||||
request :show_global_usage
|
||||
request :list_record_types
|
||||
request :list_geo_regions
|
||||
request :create_record
|
||||
request :update_record
|
||||
request :list_records
|
||||
request :delete_record
|
||||
request :set_record_failover
|
||||
|
||||
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
|
77
lib/fog/rage4/models/dns/record.rb
Normal file
77
lib/fog/rage4/models/dns/record.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
|
||||
class Record < Fog::Model
|
||||
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :value, :aliases => "content"
|
||||
attribute :ttl
|
||||
attribute :zone_id, :aliases => "domain_id"
|
||||
attribute :type, :aliases => "record_type"
|
||||
attribute :priority, :aliases => "priority"
|
||||
attribute :domain_id
|
||||
attribute :geo_region_id
|
||||
attribute :failover_enabled
|
||||
attribute :failover_content
|
||||
attribute :geo_lat
|
||||
attribute :geo_long
|
||||
attribute :geo_lock
|
||||
attribute :is_active
|
||||
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
def domain
|
||||
name
|
||||
end
|
||||
|
||||
def destroy
|
||||
service.delete_record(id)
|
||||
true
|
||||
end
|
||||
|
||||
def zone
|
||||
@zone
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name, :type, :value
|
||||
options = {}
|
||||
options[:priority] = priority if priority
|
||||
options[:ttl] = ttl if ttl
|
||||
options[:geozone] = geo_region_id if geo_region_id
|
||||
options[:geolock] = geo_lock if geo_lock
|
||||
options[:geolat] = geo_lat if geo_lat
|
||||
options[:geolong] = geo_long if geo_long
|
||||
|
||||
# decide whether its a new record or update of an existing
|
||||
if id.nil?
|
||||
data = service.create_record(zone.id, name, value, type, options)
|
||||
else
|
||||
data = service.update_record(id, name, value, type, options)
|
||||
end
|
||||
|
||||
merge_attributes(options)
|
||||
merge_attributes(:name => name, :value => value, :type => type)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def zone=(new_zone)
|
||||
@zone = new_zone
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/rage4/models/dns/records.rb
Normal file
42
lib/fog/rage4/models/dns/records.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(record_id)
|
||||
requires :zone
|
||||
data = service.list_records(zone.id).select {|record| record['id'] == record_id }
|
||||
if !data.empty?
|
||||
new(data.first)
|
||||
else
|
||||
nil
|
||||
end
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :zone
|
||||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
46
lib/fog/rage4/models/dns/zone.rb
Normal file
46
lib/fog/rage4/models/dns/zone.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
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'
|
||||
|
||||
def destroy
|
||||
service.delete_domain(id)
|
||||
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["id"]
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/rage4/models/dns/zones.rb
Normal file
34
lib/fog/rage4/models/dns/zones.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(zone_name)
|
||||
data = service.get_domain_by_name(zone_name).body
|
||||
|
||||
if data["status"] && !data["status"]
|
||||
nil
|
||||
else
|
||||
new(data)
|
||||
end
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/rage4/requests/dns/create_domain.rb
Normal file
33
lib/fog/rage4/requests/dns/create_domain.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Create a domain.
|
||||
# ==== Parameters
|
||||
# * name<~String> - domain name
|
||||
# * email<~String> - email of owner of domain, defaults to email of credentials
|
||||
#
|
||||
# ==== 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
|
34
lib/fog/rage4/requests/dns/create_domain_vanity.rb
Normal file
34
lib/fog/rage4/requests/dns/create_domain_vanity.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
# * nsprefix<~String> - prefix for the domain name, defaults to 'ns'
|
||||
#
|
||||
# ==== 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/createregulardomainext/?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/createrecord/#{domain_id}"
|
||||
path << "?name=#{name}&content=#{content}&type=#{type}"
|
||||
|
||||
path << "&priority=#{options[:priority]}" if options[:priority]
|
||||
|
||||
failover = options[:failover] || 'false'
|
||||
path << "&failover=#{failover}"
|
||||
|
||||
path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]
|
||||
|
||||
ttl = options[:ttl] || 3600
|
||||
path << "&ttl=#{ttl}"
|
||||
|
||||
path << "&geozone=#{options[:geozone]}" if options[:geozone]
|
||||
path << "&geolock=#{options[:geolock]}" if options[:geolock]
|
||||
path << "&geolat=#{options[:geolat]}" if options[:geolat]
|
||||
path << "&geolong=#{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 reverse domain for an ipv4 address .
|
||||
# ==== Parameters
|
||||
# * name<~String> - expects an ipv5 address
|
||||
# * subnet<~Integer> - subnet ie: 9 for /9, range is /8 to /30
|
||||
#
|
||||
# ==== 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
|
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 domain
|
||||
# ==== 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 record
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - numeric record 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
|
30
lib/fog/rage4/requests/dns/get_domain.rb
Normal file
30
lib/fog/rage4/requests/dns/get_domain.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/rage4/requests/dns/get_domain_by_name.rb
Normal file
30
lib/fog/rage4/requests/dns/get_domain_by_name.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Get the details for a specific domain in your account.
|
||||
# ==== Parameters
|
||||
# * name<~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
|
||||
|
||||
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 lsit of all domains for 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
|
27
lib/fog/rage4/requests/dns/list_geo_regions.rb
Normal file
27
lib/fog/rage4/requests/dns/list_geo_regions.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# List all the geo regions available
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'record types'<~Hash>
|
||||
# *'name' <~String> geo record name
|
||||
# *'value' <~Integer> Integer value of the type
|
||||
|
||||
def list_geo_regions
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/rapi/listgeoregions'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/rage4/requests/dns/list_record_types.rb
Normal file
26
lib/fog/rage4/requests/dns/list_record_types.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# List all the record types available
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * 'record types'<~Hash>
|
||||
# *'name' <~String> record type name
|
||||
# *'value' <~Integer> Integer value of the type
|
||||
def list_record_types
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => '/rapi/listrecordtypes'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/rage4/requests/dns/list_records.rb
Normal file
31
lib/fog/rage4/requests/dns/list_records.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
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>
|
||||
# * updated_at<~String>
|
||||
# * domain_id<~Integer>
|
||||
# * id<~Integer>
|
||||
# * content<~String>
|
||||
# * record_type<~String>
|
||||
# * priority<~Integer>
|
||||
def list_records(id)
|
||||
request( :expects => 200,
|
||||
:method => "GET",
|
||||
:path => "/rapi/getrecords/#{id}" )
|
||||
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
|
25
lib/fog/rage4/requests/dns/show_current_usage.rb
Normal file
25
lib/fog/rage4/requests/dns/show_current_usage.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Shows current usage for a single domain
|
||||
# ==== Parameters
|
||||
# * id<~Integer> - domain name numeric ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>
|
||||
def show_current_usage(id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/showcurrentusage/#{id}" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/rage4/requests/dns/show_global_usage.rb
Normal file
25
lib/fog/rage4/requests/dns/show_global_usage.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rage4
|
||||
class Real
|
||||
|
||||
# Shows global usage for all domains
|
||||
# ==== Parameters
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>
|
||||
|
||||
def show_global_usage
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/rapi/showcurrentglobalusage/" )
|
||||
|
||||
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
|
||||
# * id<~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(id, options = {})
|
||||
email = options[:email] || @rage4_email
|
||||
|
||||
path = "/rapi/updatedomain/#{id}?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
|
||||
|
||||
# Updates an existing 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]
|
||||
|
||||
failover = options[:failover] || 'false'
|
||||
path << "&failover=#{failover}"
|
||||
|
||||
path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]
|
||||
|
||||
ttl = options[:ttl] || 3600
|
||||
path << "&ttl=#{ttl}"
|
||||
|
||||
path << "&geozone=#{options[:geozone]}" if options[:geozone]
|
||||
path << "&geolock=#{options[:geolock]}" if options[:geolock]
|
||||
path << "&geolat=#{options[:geolat]}" if options[:geolat]
|
||||
path << "&geolong=#{options[:geolong]}" if options[:geolong]
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -35,6 +35,9 @@ def dns_providers
|
|||
:zone_attributes => {
|
||||
:email => 'fog@example.com'
|
||||
}
|
||||
},
|
||||
:rage4 => {
|
||||
:mocked => false
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
for provider, config in dns_providers
|
||||
|
||||
# FIXME: delay/timing breaks things :(
|
||||
next if [:dnsmadeeasy].include?(provider)
|
||||
next if [:dnsmadeeasy, :rage4].include?(provider)
|
||||
|
||||
domain_name = uniq_id + '.com'
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
for provider, config in dns_providers
|
||||
|
||||
# FIXME: delay/timing breaks things :(
|
||||
next if [:dnsmadeeasy].include?(provider)
|
||||
next if [:dnsmadeeasy, :rage4].include?(provider)
|
||||
|
||||
domain_name = uniq_id + '.com'
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
for provider, config in dns_providers
|
||||
|
||||
# FIXME: delay/timing breaks things :(
|
||||
next if [:dnsmadeeasy].include?(provider)
|
||||
next if [:dnsmadeeasy, :rage4].include?(provider)
|
||||
|
||||
domain_name = uniq_id + '.com'
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
for provider, config in dns_providers
|
||||
|
||||
# FIXME: delay/timing breaks things :(
|
||||
next if [:dnsmadeeasy].include?(provider)
|
||||
next if [:dnsmadeeasy, :rage4].include?(provider)
|
||||
|
||||
domain_name = uniq_id + '.com'
|
||||
|
||||
|
|
241
tests/rage4/requests/dns/dns_tests.rb
Normal file
241
tests/rage4/requests/dns/dns_tests.rb
Normal file
|
@ -0,0 +1,241 @@
|
|||
Shindo.tests('Fog::DNS[:rage4] | DNS requests', ['rage4', 'dns']) do
|
||||
|
||||
@domain = ''
|
||||
@domain_id = nil
|
||||
@record_id = nil
|
||||
@domain_count = 0
|
||||
|
||||
@created_domain_list = []
|
||||
|
||||
tests("success") do
|
||||
|
||||
test("get current domain count") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].list_domains()
|
||||
if response.status == 200
|
||||
@domain_count = response.body.size
|
||||
end
|
||||
|
||||
if response.status == 200
|
||||
response.body = []
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
|
||||
test("create domain") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
domain = generate_unique_domain
|
||||
response = Fog::DNS[:rage4].create_domain(domain)
|
||||
if response.status == 200
|
||||
@domain_id = response.body['id']
|
||||
@domain = domain
|
||||
end
|
||||
|
||||
if response.status == 200 && response.body['id'] != 0
|
||||
@created_domain_list << response.body['id']
|
||||
end
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status'] && !@domain_id.nil?
|
||||
end
|
||||
|
||||
test("create_domain_vanity") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
domain = generate_unique_domain
|
||||
response = Fog::DNS[:rage4].create_domain_vanity(domain, 'foo.com')
|
||||
|
||||
if response.status == 200 && response.body['id'] != 0
|
||||
@created_domain_list << response.body['id']
|
||||
end
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status']
|
||||
end
|
||||
|
||||
test("create_reverse_domain_4") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].create_reverse_domain_4('192.168.1.1', 29)
|
||||
|
||||
if response.status == 200 && response.body['id'] != 0
|
||||
@created_domain_list << response.body['id']
|
||||
end
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status']
|
||||
end
|
||||
|
||||
test("get_domain") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].get_domain(@domain_id)
|
||||
|
||||
returns(200) {response.status}
|
||||
returns(@domain_id) {response.body['id']}
|
||||
returns(@domain) {response.body['name']}
|
||||
returns(Fog.credentials[:rage4_email]) {response.body['owner_email']}
|
||||
returns(0) {response.body['type']}
|
||||
returns(0) {response.body['subnet_mask']}
|
||||
end
|
||||
|
||||
test("get_domain_by_name") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].get_domain_by_name(@domain)
|
||||
|
||||
returns(200) {response.status}
|
||||
returns(@domain_id) {response.body['id']}
|
||||
returns(@domain) {response.body['name']}
|
||||
returns(Fog.credentials[:rage4_email]) {response.body['owner_email']}
|
||||
returns(0) {response.body['type']}
|
||||
returns(0) {response.body['subnet_mask']}
|
||||
end
|
||||
|
||||
test("update_domain") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].update_domain(@domain_id, {:email => 'test@test.com'})
|
||||
|
||||
returns(200) { response.status }
|
||||
returns(true) {response.body['status']}
|
||||
returns(@domain_id) {response.body['id']}
|
||||
returns("") {response.body['error'] }
|
||||
|
||||
end
|
||||
|
||||
|
||||
test("show_current_usage") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].show_current_usage(@domain_id)
|
||||
returns(200) { response.status }
|
||||
returns([]) { response.body }
|
||||
end
|
||||
|
||||
test("show_global_usage") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].show_global_usage()
|
||||
returns(200) { response.status }
|
||||
returns([]) { response.body }
|
||||
end
|
||||
|
||||
test("list_record_types") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].list_record_types()
|
||||
response.body.each do |record_type|
|
||||
returns(true) { !record_type['name'].nil? }
|
||||
returns(true) { !record_type['value'].nil? }
|
||||
end
|
||||
|
||||
returns(200) { response.status }
|
||||
returns(Array) { response.body.class }
|
||||
end
|
||||
|
||||
test("list_geo_regions") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].list_geo_regions()
|
||||
response.body.each do |record_type|
|
||||
returns(true) { !record_type['name'].nil? }
|
||||
returns(true) { !record_type['value'].nil? }
|
||||
end
|
||||
|
||||
returns(200) { response.status }
|
||||
returns(Array) { response.body.class }
|
||||
end
|
||||
|
||||
test("create_record") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
name = "www." + @domain
|
||||
type = 2 #"A"
|
||||
data = "1.2.3.4"
|
||||
response = Fog::DNS[:rage4].create_record(@domain_id, name , data, type)
|
||||
|
||||
if response.status == 200
|
||||
@record_id = response.body['id']
|
||||
end
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status'] && !@record_id.nil?
|
||||
end
|
||||
|
||||
test("update_record") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
name = "www." + @domain
|
||||
type = 2 #"A"
|
||||
data = "4.3.2.1"
|
||||
response = Fog::DNS[:rage4].update_record(@record_id, name, data, type)
|
||||
|
||||
returns(@record_id) { response.body['id'] }
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status']
|
||||
end
|
||||
|
||||
test("list_records") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].list_records(@domain_id)
|
||||
# returns nameserver records as well, will only verify
|
||||
# the record we have tracked
|
||||
|
||||
response.body.each do |record|
|
||||
if record['id'] == @record_id
|
||||
returns(@record_id) { record['id'] }
|
||||
returns("www." + @domain) { record['name'] }
|
||||
returns("A") { record['type'] }
|
||||
returns(3600) { record['ttl'] }
|
||||
returns(nil) { record['priority'] }
|
||||
returns(@domain_id) { record['domain_id'] }
|
||||
returns(0) { record['geo_region_id'] }
|
||||
returns(false) { record['failover_enabled'] }
|
||||
returns(nil) { record['failover_content'] }
|
||||
returns(true) { record['is_active'] }
|
||||
returns(false) { record['geo_lock'] }
|
||||
end
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
test("delete_record") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = Fog::DNS[:rage4].delete_record(@record_id)
|
||||
returns(@record_id) { response.body['id'] }
|
||||
|
||||
response.status == 200 && response.body['error'] == "" &&
|
||||
response.body['status']
|
||||
end
|
||||
|
||||
test("delete_domain") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
response = nil
|
||||
@created_domain_list.each do |domain_id|
|
||||
response = Fog::DNS[:rage4].delete_domain(domain_id)
|
||||
|
||||
|
||||
returns(true) {response.body['status']}
|
||||
returns(domain_id) {response.body['id']}
|
||||
returns("") {response.body['error'] }
|
||||
end
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests( 'failure') do
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue