mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|dns] Add the HP DNS provider along with the tests.
This commit is contained in:
parent
2b4dcf0d86
commit
749685be8a
28 changed files with 446 additions and 279 deletions
|
@ -60,7 +60,7 @@ module Fog
|
|||
service(:block_storage_v2, 'hp/block_storage_v2', 'BlockStorageV2')
|
||||
service(:cdn, 'hp/cdn', 'CDN')
|
||||
service(:compute, 'hp/compute', 'Compute')
|
||||
service(:dns, 'hp/lb', 'DNS')
|
||||
service(:dns, 'hp/dns', 'DNS')
|
||||
service(:lb, 'hp/lb', 'LB')
|
||||
service(:network, 'hp/network', 'Network')
|
||||
service(:storage, 'hp/storage', 'Storage')
|
||||
|
|
|
@ -12,13 +12,11 @@ module Fog
|
|||
|
||||
secrets :hp_secret_key
|
||||
|
||||
# model_path 'fog/hp/models/dns'
|
||||
# model :domain
|
||||
# collection :domains
|
||||
# model :record
|
||||
# collection :records
|
||||
# model :server
|
||||
|
||||
model_path 'fog/hp/models/dns'
|
||||
model :domain
|
||||
collection :domains
|
||||
model :record
|
||||
collection :records
|
||||
|
||||
request_path 'fog/hp/requests/dns'
|
||||
request :create_domain
|
||||
|
@ -38,7 +36,8 @@ module Fog
|
|||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
|
||||
:domains => {},
|
||||
:records => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -135,7 +134,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::HP::BlockStorage::NotFound.slurp(error)
|
||||
Fog::HP::DNS::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
|
|
|
@ -150,7 +150,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::HP::BlockStorage::NotFound.slurp(error)
|
||||
Fog::HP::LB::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
|
|
0
lib/fog/hp/models/dns/domain.rb
Normal file
0
lib/fog/hp/models/dns/domain.rb
Normal file
36
lib/fog/hp/models/dns/domains.rb
Normal file
36
lib/fog/hp/models/dns/domains.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/hp/models/dns/domains'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class DNS
|
||||
|
||||
class Domains < Fog::Collection
|
||||
|
||||
attribute :filters
|
||||
|
||||
model Fog::HP::DNS::Domains
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
def all(filters = filters)
|
||||
self.filters = filters
|
||||
non_aliased_filters = Fog::HP.convert_aliased_attributes_to_original(self.model, filters)
|
||||
load(service.list_domains(non_aliased_filters).body['domains'])
|
||||
end
|
||||
|
||||
def get(domain_id)
|
||||
if domain = service.get_domain(domain_id).body['domain']
|
||||
new(domain)
|
||||
end
|
||||
rescue Fog::HP::DNS::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
0
lib/fog/hp/models/dns/record.rb
Normal file
0
lib/fog/hp/models/dns/record.rb
Normal file
0
lib/fog/hp/models/dns/records.rb
Normal file
0
lib/fog/hp/models/dns/records.rb
Normal file
|
@ -2,10 +2,35 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
|
||||
# Create a new DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'name'<~String> - Name of domain
|
||||
# * 'email'<~String> - email for the domain
|
||||
# * options<~Hash>:
|
||||
# * 'ttl'<~String> - TTL for the domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
class Real
|
||||
def create_domain(name, options)
|
||||
data = options.dup
|
||||
data[:name] = name
|
||||
def create_domain(name, email, options={})
|
||||
data = {
|
||||
:name => name,
|
||||
:email => email
|
||||
}
|
||||
|
||||
l_options = [:ttl]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
|
@ -16,18 +41,19 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
def create_domain(name, options)
|
||||
def create_domain(name, email, options={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
data = {
|
||||
:id => SecureRandom.uuid,
|
||||
:name => "domain1.com.",
|
||||
:ttl => 3600,
|
||||
:serial => 1351800588,
|
||||
:email => "nsadmin@example.org",
|
||||
:created_at=>"2012-11-01T20:09:48.094457"
|
||||
data = {
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'name' => name || 'domain1.com.',
|
||||
'ttl' => options[:ttl] || 3600,
|
||||
'email' => email || 'nsadmin@example.org',
|
||||
'serial' => 1351800588,
|
||||
'created_at' => '2012-01-01T13:32:20Z'
|
||||
}
|
||||
self.data[:domains][data['id']] = data
|
||||
response.body = data
|
||||
response
|
||||
end
|
||||
|
|
|
@ -2,12 +2,32 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
def create_record(domain_id, name, type, data, priority)
|
||||
|
||||
# Create a new DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'name'<~String> - Name of record
|
||||
# * 'type'<~String> - Type of the record i.e. 'A'
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~String> - Priority
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~String> - Priority for the record
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
# * 'updated_at'<~String> - updated date time stamp
|
||||
def create_record(domain_id, name, type, data, priority=nil)
|
||||
data = {
|
||||
:name=> name,
|
||||
:type=> type,
|
||||
:data=> data
|
||||
:name => name,
|
||||
:type => type,
|
||||
:data => data
|
||||
}
|
||||
data[:priority] = priority.to_i unless priority.nil?
|
||||
|
||||
|
@ -22,21 +42,27 @@ module Fog
|
|||
end
|
||||
class Mock
|
||||
def create_record(domain_id, name, type, data, priority)
|
||||
priority = priority.to_i unless priority.nil?
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
data = {
|
||||
:id=> "2e32e609-3a4f-45ba-bdef-e50eacd345ad",
|
||||
:name=> "www.example.com.",
|
||||
:type=> "A",
|
||||
:created_at=> "2012-11-02T19:56:26.366792",
|
||||
:updated_at=> null,
|
||||
:domain_id=> "89acac79-38e7-497d-807c-a011e1310438",
|
||||
:ttl=> 3600,
|
||||
:data=> "15.185.172.152"
|
||||
}
|
||||
response.body = data
|
||||
response
|
||||
response
|
||||
if list_domains.body['domains'].detect {|_| _['id'] == domain_id}
|
||||
response.status = 200
|
||||
data = {
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'domain_id' => domain_id,
|
||||
'name' => name || 'www.example.com.',
|
||||
'type' => type || 'A',
|
||||
'data' => data || '15.185.172.152',
|
||||
'ttl' => 3600,
|
||||
'priority' => priority || nil,
|
||||
'created_at' => '2012-11-02T19:56:26.366792',
|
||||
'updated_at' => '2012-11-02T19:56:26.366792'
|
||||
}
|
||||
self.data[:records][data['id']] = data
|
||||
response.body = data
|
||||
response
|
||||
else
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
# Delete a Domain
|
||||
# Delete a DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~Integer> - Id of domain to delete
|
||||
# * domain_id<~String> - UUId of domain to delete
|
||||
#
|
||||
def delete_domain(domain_id)
|
||||
request(
|
||||
|
@ -22,17 +22,12 @@ module Fog
|
|||
class Mock
|
||||
def delete_domain(domain_id)
|
||||
response = Excon::Response.new
|
||||
if image = find_domain(domain_id)
|
||||
if list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
response.status = 202
|
||||
response
|
||||
else
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def find_domain(domain_id)
|
||||
list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,39 +2,33 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
# Delete a Record
|
||||
# Delete a DNS Record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~Integer> - Id of domain for record
|
||||
# * record_id<~Integer> - Id of record to delete
|
||||
#
|
||||
def delete_record(domain_id, record_id)
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'DELETE',
|
||||
:path => "domains/#{domain_id}/records/#{record_id}"
|
||||
)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_record(domain_id, record_id)
|
||||
response = Excon::Response.new
|
||||
if image = find_record(domain_id, record_id)
|
||||
if list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
response.status = 200
|
||||
response
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def find_record(domain_id, record_id)
|
||||
list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,36 +2,40 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
|
||||
# Get details for existing domain
|
||||
# Get details for existing DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * instance_id<~Integer> - Id of the domain to get
|
||||
# * domain_id<~String> - UUId of the domain to get
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# *TBD
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
class Real
|
||||
def get_domain(instance_id)
|
||||
response = request(
|
||||
def get_domain(domain_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "domains/#{instance_id}"
|
||||
:path => "domains/#{domain_id}"
|
||||
)
|
||||
response
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
|
||||
def get_domain(instance_id)
|
||||
def get_domain(domain_id)
|
||||
response = Excon::Response.new
|
||||
if domain = find_domain(instance_id)
|
||||
if domain = list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
response.status = 200
|
||||
response.body = {'domain' => domain}
|
||||
response.body = domain
|
||||
response
|
||||
else
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,31 +2,43 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Get details of an existing DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~String> - UUId of domain for record
|
||||
# * record_id<~String> - UUId of record to get
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUId of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~Integer> - Priority for the record
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
# * 'updated_at'<~String> - updated date time stamp
|
||||
def get_record(domain_id, record_id)
|
||||
response = request(
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "domains/#{domain_id}/records/#{record_id}"
|
||||
)
|
||||
response
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def get_record(domain_id, record_id)
|
||||
if record = find_record(domain_id, record_id)
|
||||
response = Excon::Response.new
|
||||
if record = list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
response.status = 200
|
||||
response.body = record
|
||||
response.body = record
|
||||
response
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
def find_record(domain_id, record_id)
|
||||
list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,19 +2,26 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
# Get servers for existing domain
|
||||
# Get authoritative nameservers for existing DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * instance_id<~Integer> - Id of the domain with servers
|
||||
# * domain_id<~String> - UUId of the domain to get nameservers for
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# *TBD
|
||||
def get_servers_hosting_domain(instance_id)
|
||||
# * body<~Hash>:
|
||||
# * 'nameservers'<~Array>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
def get_servers_hosting_domain(domain_id)
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "domains/#{instance_id}/servers"
|
||||
:path => "domains/#{domain_id}/servers"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -22,18 +29,33 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def get_servers_hosting_domain(instance_id)
|
||||
if domain = find_domain(instance_id)
|
||||
def get_servers_hosting_domain(domain_id)
|
||||
response = Excon::Response.new
|
||||
if list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
response.status = 200
|
||||
response.body = {'domain' => domain}
|
||||
response.body = { 'servers' => dummy_servers }
|
||||
response
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def dummy_servers
|
||||
[
|
||||
{
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'name' => 'ns1.provider.com.',
|
||||
'created_at' => '2012-01-01T13:32:20Z',
|
||||
'updated_at' => '2012-01-01T13:32:20Z'
|
||||
},
|
||||
{
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'name' => 'ns2.provider.com.',
|
||||
'created_at' => '2012-01-01T13:32:20Z',
|
||||
'updated_at' => '2012-01-01T13:32:20Z'
|
||||
},
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,20 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
# List all flavors (IDs and names only)
|
||||
|
||||
# List all DNS domains
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'domains'<~Array>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
def list_domains
|
||||
request(
|
||||
:expects => [200],
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'domains'
|
||||
)
|
||||
|
@ -17,13 +26,9 @@ module Fog
|
|||
class Mock
|
||||
def list_domains
|
||||
response = Excon::Response.new
|
||||
domains = self.data[:domains].values
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"domains" => [
|
||||
{"name" => "domain1.com.", "created_at" => "2012-11-01T20:11:08.000000", "email" => "nsadmin@example.org", "ttl" => 3600, "serial" => 1351800668, "id" => "09494b72-b65b-4297-9efb-187f65a0553e"},
|
||||
{"name" => "domain2.com.", "created_at" => "2012-11-01T20:09:48.000000", "email" => "nsadmin@example.org", "ttl" => 3600, "serial" => 1351800588, "id" => "89acac79-38e7-497d-807c-a011e1310438"}
|
||||
]
|
||||
}
|
||||
response.body = { 'domains' => domains }
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,24 @@ module Fog
|
|||
module HP
|
||||
class DNS
|
||||
class Real
|
||||
# List DNS records for a given domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'records'<~Array>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~Integer> - Priority for the record
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
# * 'updated_at'<~String> - updated date time stamp
|
||||
def list_records_in_a_domain(domain_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "domains/#{domain_id}/records"
|
||||
)
|
||||
|
@ -14,62 +29,21 @@ module Fog
|
|||
class Mock
|
||||
def list_records_in_a_domain(domain_id)
|
||||
response = Excon::Response.new
|
||||
if records = find_domain(domain_id)
|
||||
if domain = list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
response.status = 200
|
||||
response.body = records_for_domain(domain_id)
|
||||
response.body = { 'records' => records_for_domain(domain_id) }
|
||||
else
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def find_domain(domain_id)
|
||||
list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
end
|
||||
|
||||
def records_for_domain(domain_id)
|
||||
|
||||
data = {
|
||||
"records" => [
|
||||
{
|
||||
"id" => "2e32e609-3a4f-45ba-bdef-e50eacd345ad",
|
||||
"name" => "www.example.com.",
|
||||
"type" => "A",
|
||||
"ttl" => 3600,
|
||||
"created_at" => "2012-11-02T19:56:26.000000",
|
||||
"updated_at" => "2012-11-04T13:22:36.000000",
|
||||
"data" => "15.185.172.153",
|
||||
"domain_id" => "89acac79-38e7-497d-807c-a011e1310438",
|
||||
"tenant_id" => nil,
|
||||
"priority" => nil,
|
||||
"version" => 1,
|
||||
},
|
||||
{
|
||||
"id" => "8e9ecf3e-fb92-4a3a-a8ae-7596f167bea3",
|
||||
"name" => "host1.example.com.",
|
||||
"type" => "A",
|
||||
"ttl" => 3600,
|
||||
"created_at" => "2012-11-04T13:57:50.000000",
|
||||
"updated_at" => nil,
|
||||
"data" => "15.185.172.154",
|
||||
"domain_id" => "89acac79-38e7-497d-807c-a011e1310438",
|
||||
"tenant_id" => nil,
|
||||
"priority" => nil,
|
||||
"version" => 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
if domain_id == list_domains.body["domains"].first["id"]
|
||||
data
|
||||
else
|
||||
{
|
||||
"records" => []
|
||||
}
|
||||
end
|
||||
|
||||
rdata = data[:records].select { |_,v| v['domain_id'] == domain_id}
|
||||
records = []
|
||||
rdata.each { |_,v| records << v }
|
||||
records
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,9 +3,32 @@ module Fog
|
|||
class DNS
|
||||
|
||||
class Real
|
||||
def update_domain(domain_id, options)
|
||||
# Update an existing DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~String> - UUId of domain to delete
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of domain
|
||||
# * 'ttl'<~String> - TTL for the domain
|
||||
# * 'email'<~String> - email for the domain
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
def update_domain(domain_id, options={})
|
||||
l_options = [:name, :ttl, :email]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(options),
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "domains/#{domain_id}"
|
||||
|
@ -14,12 +37,14 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
def update_domain(domain_id, options)
|
||||
def update_domain(domain_id, options={})
|
||||
response = Excon::Response.new
|
||||
if domain = list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
if options['name']
|
||||
domain['name'] = options['name']
|
||||
end
|
||||
|
||||
domain['name'] = options[:name] if options[:name]
|
||||
domain['ttl'] = options[:ttl] if options[:ttl]
|
||||
domain['email'] = options[:email] if options[:email]
|
||||
|
||||
response.status = 200
|
||||
response.body = domain
|
||||
response
|
||||
|
|
|
@ -3,9 +3,37 @@ module Fog
|
|||
class DNS
|
||||
|
||||
class Real
|
||||
def update_record(domain_id, record_id, options)
|
||||
# Update an existing DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~String> - UUId of domain to delete
|
||||
# * record_id<~String> - UUId of record to get
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of record
|
||||
# * 'type'<~String> - Type of the record i.e. 'A'
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~Integer> - Priority
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~Integer> - Priority for the record
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
# * 'updated_at'<~String> - updated date time stamp
|
||||
def update_record(domain_id, record_id, options={})
|
||||
l_options = [:name, :type, :data, :priority]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(options),
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "domains/#{domain_id}/records/#{record_id}"
|
||||
|
@ -16,22 +44,21 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def update_record(domain_id, record_id, options)
|
||||
if record = find_record(domain_id, record_id)
|
||||
if options['name']
|
||||
domain['name'] = options['name']
|
||||
end
|
||||
response = Excon::Response.new
|
||||
if record = list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
record['name'] = options[:name] if options[:name]
|
||||
record['type'] = options[:type] if options[:type]
|
||||
record['data'] = options[:data] if options[:data]
|
||||
record['priority'] = options[:priority] if options[:priority]
|
||||
|
||||
response.status = 200
|
||||
response.body = record
|
||||
response
|
||||
else
|
||||
raise Fog::HP::DNS::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def find_record(domain_id, record_id)
|
||||
list_records_in_a_domain(domain_id).body['records'].detect { |_| _['id'] == record_id }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ Shindo.tests('Fog::CDN::HP', ['hp', 'cdn']) do
|
|||
credentials = {
|
||||
:auth_token => 'auth_token',
|
||||
:endpoint_url => 'http://127.0.0.1/cdnpath/',
|
||||
:cdn_endpoint_url => "http://127.0.0.1/cdnpath/",
|
||||
:cdn_endpoint_url => 'http://127.0.0.1/cdnpath/',
|
||||
:service_catalog => {
|
||||
:"CDN" => {
|
||||
:zone => 'http://127.0.0.1/cdnpath/'}},
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
Shindo.tests("HP::DNS | create domain tests", ['hp', 'dns', 'domain']) do
|
||||
|
||||
@create_format = {
|
||||
id: String,
|
||||
name: String,
|
||||
ttl: Integer,
|
||||
serial: Integer,
|
||||
email: String,
|
||||
created_at: String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests("#create_domain").formats(@create_format) do
|
||||
HP[:dns].create_domain("name","joe@blow.com").body
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
Shindo.tests("HP::DNS | delete domain tests", ['hp', 'dns', 'domain']) do
|
||||
@domain_id = "09494b72-b65b-4297-9efb-187f65a0553e"
|
||||
@domain_bad = "09494b72-111-222-333"
|
||||
tests('success') do
|
||||
tests("#delete_domain(#{@domain_id})").succeeds do
|
||||
HP[:dns].delete_domain(@domain_id)
|
||||
end
|
||||
end
|
||||
tests('failure') do
|
||||
tests("#delete_domain(#{@domain_bad})").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].delete_domain(@domain_bad)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
71
tests/hp/requests/dns/domain_tests.rb
Normal file
71
tests/hp/requests/dns/domain_tests.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
Shindo.tests("HP::DNS | domain requests", ['hp', 'dns', 'domain']) do
|
||||
@domain_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'ttl' => Integer,
|
||||
'serial' => Integer,
|
||||
'email' => String,
|
||||
'created_at' => String
|
||||
}
|
||||
|
||||
@server_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'created_at' => String,
|
||||
'updated_at' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@domain_name = 'www.fogtest.com.'
|
||||
@email = 'test@fogtest.com'
|
||||
|
||||
tests("#create_domain(#{@domain_name}, #{@email})").formats(@domain_format) do
|
||||
data = HP[:dns].create_domain(@domain_name, @email).body
|
||||
@domain_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
tests('#list_domains').formats({'domains' => [@domain_format]}) do
|
||||
HP[:dns].list_domains.body
|
||||
end
|
||||
|
||||
tests("#get_domain(#{@domain_id})").formats(@domain_format) do
|
||||
HP[:dns].get_domain(@domain_id).body
|
||||
end
|
||||
|
||||
tests("#get_servers_hosting_domain(#{@domain_id})").formats('servers' => [@server_format]) do
|
||||
HP[:dns].get_servers_hosting_domain(@domain_id).body
|
||||
end
|
||||
|
||||
tests("#update_domain(#{@domain_id}, {:email => 'updated@fogtest.com'})").formats(@domain_format) do
|
||||
HP[:dns].update_domain(@domain_id, {:email => 'updated@fogtest.com'}).body
|
||||
end
|
||||
|
||||
tests("#delete_domain(#{@domain_id})").succeeds do
|
||||
HP[:dns].delete_domain(@domain_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get_domain('invalid_domain')").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].get_domain('invalid_domain')
|
||||
end
|
||||
|
||||
tests("#get_servers_hosting_domain('invalid_domain')").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].get_servers_hosting_domain('invalid_domain')
|
||||
end
|
||||
|
||||
tests("#update_domain('invalid_domain', {:email => 'updated@fogtest.com'})").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].update_domain('invalid_domain', {:email => 'updated@fogtest.com'})
|
||||
end
|
||||
|
||||
tests("#delete_domain('invalid_domain')").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].delete_domain('invalid_domain')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
Shindo.tests("HP::DNS | get domain tests", ['hp', 'dns', 'domain']) do
|
||||
@domain_id = "09494b72-b65b-4297-9efb-187f65a0553e"
|
||||
@domain_bad = "09494b72-111-222-333"
|
||||
|
||||
@domain_format = {
|
||||
"id" => String,
|
||||
"name" => String,
|
||||
"ttl" => Integer,
|
||||
"serial" => Integer,
|
||||
"email" => String,
|
||||
"created_at" => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests("#get_domain(#{ @domain_id})").formats(@domain_format) do
|
||||
HP[:dns].get_domain(@domain_id).body['domain']
|
||||
end
|
||||
end
|
||||
tests('failure') do
|
||||
tests("#get_domain(#{ @domain_bad})").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].get_domain(@domain_body)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
Shindo.tests("HP::DNS | get servers hosting domain tests", ['hp', 'dns', 'domain']) do
|
||||
tests('success') do
|
||||
|
||||
end
|
||||
tests('failure') do
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
Shindo.tests("HP::DNS | list domains tests", ['hp', 'dns', 'domain']) do
|
||||
@domain_format = {
|
||||
"id" => String,
|
||||
"name" => String,
|
||||
"ttl" => Integer,
|
||||
"serial" => Integer,
|
||||
"email" => String,
|
||||
"created_at" => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_domains').formats({'domains' => [@domain_format]}) do
|
||||
HP[:dns].list_domains.body
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
Shindo.tests("HP::DNS | list records tests", ['hp', 'dns', 'records']) do
|
||||
@domain_id = "09494b72-b65b-4297-9efb-187f65a0553e"
|
||||
@domain2 = "89acac79-38e7-497d-807c-a011e1310438"
|
||||
@domain_bad = "09494b72-111-222-333"
|
||||
tests('success') do
|
||||
tests("#list_records_in_a_domain(#{@domain_id})").succeeds do
|
||||
HP[:dns].list_records_in_a_domain(@domain_id)
|
||||
end
|
||||
tests("#list_records_in_a_domain(#{@domain2})").returns(true) do
|
||||
HP[:dns].list_records_in_a_domain(@domain2).body["records"].count == 0
|
||||
end
|
||||
|
||||
end
|
||||
tests('failure') do
|
||||
tests("#list_records_in_a_domain(#{@domain_bad})").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].list_records_in_a_domain(@domain_bad)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
64
tests/hp/requests/dns/records_tests.rb
Normal file
64
tests/hp/requests/dns/records_tests.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
Shindo.tests("HP::DNS | record requests", ['hp', 'dns', 'record']) do
|
||||
@record_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'type' => String,
|
||||
'domain_id' => String,
|
||||
'ttl' => Integer,
|
||||
'data' => String,
|
||||
'priority' => Integer,
|
||||
'created_at' => String,
|
||||
'updated_at' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@domain_name = 'www.fogtest.com.'
|
||||
@email = 'test@fogtest.com'
|
||||
@domain_id = HP[:dns].create_domain(@domain_name, @email).body['id']
|
||||
@record_name = 'www.fogtest.com.'
|
||||
@record_data = '15.185.172.152'
|
||||
|
||||
tests("#create_record(#{@domain_id}, #{@record_name}, 'A', #{@record_data}, 1)").formats(@record_format) do
|
||||
data = HP[:dns].create_record(@domain_id, @record_name, 'A', @record_data, 1).body
|
||||
@record_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
tests("#list_records_in_a_domain(#{@domain_id})").formats({'records' => [@record_format]}) do
|
||||
HP[:dns].list_records_in_a_domain(@domain_id).body
|
||||
end
|
||||
|
||||
tests("#get_record(#{@domain_id}, #{@record_id})").formats(@record_format) do
|
||||
HP[:dns].get_record(@domain_id, @record_id).body
|
||||
end
|
||||
|
||||
tests("#update_record(#{@domain_id}, #{@record_id}, {:email => 'updated@fogtest.com'})").formats(@record_format) do
|
||||
HP[:dns].update_record(@domain_id, @record_id, {:email => 'updated@fogtest.com'}).body
|
||||
end
|
||||
|
||||
tests("#delete_record(#{@domain_id}, #{@record_id})").succeeds do
|
||||
HP[:dns].delete_record(@domain_id, @record_id)
|
||||
end
|
||||
|
||||
HP[:dns].delete_domain(@domain_id)
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get_record(#{@domain_id}, 'invalid_record')").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].get_record(@domain_id, 'invalid_record')
|
||||
end
|
||||
|
||||
tests("#update_record(#{@domain_id}, 'invalid_record', {:email => 'updated@fogtest.com'})").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].update_record(@domain_id, 'invalid_record', {:email => 'updated@fogtest.com'})
|
||||
end
|
||||
|
||||
tests("#delete_record(#{@domain_id}, 'invalid_record')").raises(Fog::HP::DNS::NotFound) do
|
||||
HP[:dns].delete_record(@domain_id, 'invalid_record')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
Shindo.tests("HP::DNS | list records tests", ['hp', 'dns', 'domains']) do
|
||||
tests('success') do
|
||||
|
||||
end
|
||||
tests('failure') do
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue