Class: Fog::HP::DNS::Mock
- Inherits:
-
Object
- Object
- Fog::HP::DNS::Mock
- Defined in:
- lib/fog/hp/dns.rb,
lib/fog/hp/requests/dns/get_domain.rb,
lib/fog/hp/requests/dns/get_record.rb,
lib/fog/hp/requests/dns/list_domains.rb,
lib/fog/hp/requests/dns/create_domain.rb,
lib/fog/hp/requests/dns/create_record.rb,
lib/fog/hp/requests/dns/delete_domain.rb,
lib/fog/hp/requests/dns/delete_record.rb,
lib/fog/hp/requests/dns/update_domain.rb,
lib/fog/hp/requests/dns/update_record.rb,
lib/fog/hp/requests/dns/list_records_in_a_domain.rb,
lib/fog/hp/requests/dns/get_servers_hosting_domain.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_domain(name, email, options = {}) ⇒ Object
- #create_record(domain_id, name, type, data, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_domain(domain_id) ⇒ Object
- #delete_record(domain_id, record_id) ⇒ Object
- #dummy_servers ⇒ Object
- #get_domain(domain_id) ⇒ Object
- #get_record(domain_id, record_id) ⇒ Object
- #get_servers_hosting_domain(domain_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_domains ⇒ Object
- #list_records_in_a_domain(domain_id) ⇒ Object
- #records_for_domain(domain_id) ⇒ Object
- #reset_data ⇒ Object
- #update_domain(domain_id, options = {}) ⇒ Object
- #update_record(domain_id, record_id, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
46 47 48 |
# File 'lib/fog/hp/dns.rb', line 46 def initialize(={}) @hp_access_key = [:hp_access_key] end |
Class Method Details
.data ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/fog/hp/dns.rb', line 33 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => {}, :records => {} } end end |
.reset ⇒ Object
42 43 44 |
# File 'lib/fog/hp/dns.rb', line 42 def self.reset @data = nil end |
Instance Method Details
#create_domain(name, email, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/hp/requests/dns/create_domain.rb', line 45 def create_domain(name, email, ={}) response = Excon::Response.new response.status = 200 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'name' => name || 'domain1.com.', 'email' => email || '[email protected]', 'description' => [:description] || 'desc domain1.com.', 'ttl' => [:ttl] || 3600, 'serial' => Fog::Mock.random_numbers(10).to_i, 'created_at' => '2012-01-01T13:32:20Z' } self.data[:domains][data['id']] = data response.body = data response end |
#create_record(domain_id, name, type, data, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fog/hp/requests/dns/create_record.rb', line 50 def create_record(domain_id, name, type, data, ={}) response = Excon::Response.new if list_domains.body['domains'].find {|_| _['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' => ['ttl'] || 3600, 'description' => ['description'] || 'desc for www.example.com.', '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 |
#data ⇒ Object
50 51 52 |
# File 'lib/fog/hp/dns.rb', line 50 def data self.class.data[@hp_access_key] end |
#delete_domain(domain_id) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/dns/delete_domain.rb', line 20 def delete_domain(domain_id) response = Excon::Response.new if list_domains.body['domains'].find { |_| _['id'] == domain_id } response.status = 202 response else raise Fog::HP::DNS::NotFound end end |
#delete_record(domain_id, record_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/hp/requests/dns/delete_record.rb', line 21 def delete_record(domain_id, record_id) response = Excon::Response.new if list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id } response.status = 200 response else raise Fog::HP::DNS::NotFound end response end |
#dummy_servers ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/hp/requests/dns/get_servers_hosting_domain.rb', line 41 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 |
#get_domain(domain_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/hp/requests/dns/get_domain.rb', line 28 def get_domain(domain_id) response = Excon::Response.new if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id } response.status = 200 response.body = domain response else raise Fog::HP::DNS::NotFound end end |
#get_record(domain_id, record_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fog/hp/requests/dns/get_record.rb', line 33 def get_record(domain_id, record_id) response = Excon::Response.new if record = list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id } response.status = 200 response.body = record response else raise Fog::HP::DNS::NotFound end end |
#get_servers_hosting_domain(domain_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/hp/requests/dns/get_servers_hosting_domain.rb', line 30 def get_servers_hosting_domain(domain_id) response = Excon::Response.new if list_domains.body['domains'].find { |_| _['id'] == domain_id } response.status = 200 response.body = { 'servers' => dummy_servers } response else raise Fog::HP::DNS::NotFound end end |
#list_domains ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/fog/hp/requests/dns/list_domains.rb', line 26 def list_domains response = Excon::Response.new domains = self.data[:domains].values response.status = 200 response.body = { 'domains' => domains } response end |
#list_records_in_a_domain(domain_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fog/hp/requests/dns/list_records_in_a_domain.rb', line 33 def list_records_in_a_domain(domain_id) response = Excon::Response.new if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id } response.status = 200 response.body = { 'records' => records_for_domain(domain_id) } else raise Fog::HP::DNS::NotFound end response end |
#records_for_domain(domain_id) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/fog/hp/requests/dns/list_records_in_a_domain.rb', line 44 def records_for_domain(domain_id) rdata = data[:records].select { |_,v| v['domain_id'] == domain_id} records = [] rdata.each { |_,v| records << v } records end |
#reset_data ⇒ Object
54 55 56 |
# File 'lib/fog/hp/dns.rb', line 54 def reset_data self.class.data.delete(@hp_access_key) end |
#update_domain(domain_id, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/hp/requests/dns/update_domain.rb', line 42 def update_domain(domain_id, ={}) response = Excon::Response.new if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id } domain['name'] = [:name] if [:name] domain['description'] = [:description] if [:description] domain['ttl'] = [:ttl] if [:ttl] domain['email'] = [:email] if [:email] response.status = 200 response.body = domain response else raise Fog::HP::DNS::NotFound end end |
#update_record(domain_id, record_id, options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/hp/requests/dns/update_record.rb', line 48 def update_record(domain_id, record_id, ) response = Excon::Response.new if record = list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id } record['name'] = [:name] if [:name] record['type'] = [:type] if [:type] record['data'] = [:data] if [:data] record['priority'] = [:priority] if [:priority] response.status = 200 response.body = record response else raise Fog::HP::DNS::NotFound end end |