Class: Fog::DNS::Dynect::Mock
- Inherits:
-
Object
- Object
- Fog::DNS::Dynect::Mock
- Defined in:
- lib/fog/dynect/dns.rb,
lib/fog/dynect/requests/dns/get_zone.rb,
lib/fog/dynect/requests/dns/put_zone.rb,
lib/fog/dynect/requests/dns/post_zone.rb,
lib/fog/dynect/requests/dns/get_record.rb,
lib/fog/dynect/requests/dns/put_record.rb,
lib/fog/dynect/requests/dns/delete_zone.rb,
lib/fog/dynect/requests/dns/post_record.rb,
lib/fog/dynect/requests/dns/post_session.rb,
lib/fog/dynect/requests/dns/delete_record.rb,
lib/fog/dynect/requests/dns/get_node_list.rb,
lib/fog/dynect/requests/dns/get_all_records.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auth_token ⇒ Object
- #data ⇒ Object
- #delete_record(type, zone, fqdn, record_id) ⇒ Object
- #delete_zone(zone) ⇒ Object
- #get_all_records(zone, options = {}) ⇒ Object
- #get_node_list(zone, options = {}) ⇒ Object
- #get_record(type, zone, fqdn, options = {}) ⇒ Object
- #get_zone(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #post_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
- #post_session ⇒ Object
- #post_zone(rname, ttl, zone, options = {}) ⇒ Object
- #put_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
- #put_zone(zone, options = {}) ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
32 33 34 35 36 |
# File 'lib/fog/dynect/dns.rb', line 32 def initialize(={}) @dynect_customer = [:dynect_customer] @dynect_username = [:dynect_username] @dynect_password = [:dynect_password] end |
Class Method Details
.data ⇒ Object
38 39 40 41 42 |
# File 'lib/fog/dynect/dns.rb', line 38 def self.data @data ||= { :zones => {} } end |
.reset ⇒ Object
44 45 46 |
# File 'lib/fog/dynect/dns.rb', line 44 def self.reset @data = nil end |
Instance Method Details
#auth_token ⇒ Object
48 49 50 |
# File 'lib/fog/dynect/dns.rb', line 48 def auth_token @auth_token ||= Fog::Dynect::Mock.token end |
#data ⇒ Object
52 53 54 |
# File 'lib/fog/dynect/dns.rb', line 52 def data self.class.data end |
#delete_record(type, zone, fqdn, record_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/dynect/requests/dns/delete_record.rb', line 24 def delete_record(type, zone, fqdn, record_id) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] raise Fog::DNS::Dynect::NotFound unless zone[:records][type].find { |record| record[:fqdn] == fqdn && record[:record_id] == record_id.to_i } zone[:records_to_delete] << { :type => type, :fqdn => fqdn, :record_id => record_id.to_i } response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => {}, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "delete: Record will be deleted on zone publish", "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } response end |
#delete_zone(zone) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/dynect/requests/dns/delete_zone.rb', line 20 def delete_zone(zone) self.data[:zones].delete(zone) response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => {}, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "ERR_CD" => '', "INFO" => '', "LVL" => '', "SOURCE" => '' }] } response end |
#get_all_records(zone, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/dynect/requests/dns/get_all_records.rb', line 24 def get_all_records(zone, = {}) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] response = Excon::Response.new response.status = 200 data = [zone[:zone]] if fqdn = [:fqdn] data = data | zone[:records].map { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact else data = data | zone[:records].map { |type, records| records.map { |record| record[:fqdn] } }.flatten end response.body = { "status" => "success", "data" => data, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "get_tree: Here is your zone tree", "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } response end |
#get_node_list(zone, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/dynect/requests/dns/get_node_list.rb', line 24 def get_node_list(zone, = {}) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] response = Excon::Response.new response.status = 200 data = [zone[:zone]] if fqdn = [:fqdn] data = data | zone[:records].map { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact else data = data | zone[:records].map { |type, records| records.map { |record| record[:fqdn] } }.flatten end response.body = { "status" => "success", "data" => data, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "get_tree: Here is your zone tree", "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } response end |
#get_record(type, zone, fqdn, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/dynect/requests/dns/get_record.rb', line 25 def get_record(type, zone, fqdn, = {}) raise ArgumentError unless [ 'AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT' ].include? type raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] response = Excon::Response.new response.status = 200 if record_id = ['record_id'] raise Fog::DNS::Dynect::NotFound unless record = zone[:records][type].find { |record| record[:record_id] == record_id.to_i } response.body = { "status" => "success", "data" => { "zone" => record[:zone][:zone], "ttl" => record[:ttl], "fqdn" => record[:fqdn], "record_type" => type, "rdata" => record[:rdata], "record_id" => record[:record_id] }, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "get: Found the record", "SOURCE" => "API-B", "ERR_CD" => nil, "LVL" => "INFO" }] } else records = if type == "ANY" zone[:records].values.flatten.select { |record| record[:fqdn] == fqdn } else zone[:records][type].select { |record| record[:fqdn] == fqdn } end response.body = { "status" => "success", "data" => records.map { |record| "/REST/#{record[:type]}Record/#{record[:zone][:zone]}/#{record[:fqdn]}/#{record[:record_id]}" }, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "detail: Found #{records.size} record", "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } end response end |
#get_zone(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fog/dynect/requests/dns/get_zone.rb', line 22 def get_zone( = {}) if ['zone'] raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][['zone']] data = { "zone_type" => zone[:zone_type], "serial_style" => zone[:serial_style], "serial" => zone[:serial], "zone" => zone[:zone] } info = "get: Your zone, #{zone[:zone]}" else data = self.data[:zones].map { |zone, data| "/REST/Zone/#{zone}/" } info = "get: Your #{data.size} zones" end response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => data, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => info, "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } response end |
#post_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fog/dynect/requests/dns/post_record.rb', line 26 def post_record(type, zone, fqdn, rdata, = {}) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] records = zone[:records] record_id = zone[:next_record_id] zone[:next_record_id] += 1 record = { :type => type, :zone => zone, :fqdn => fqdn, :rdata => rdata, :ttl => [:ttl] || zone[:ttl], :record_id => record_id } records[type] << record response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => { "zone" => record[:zone][:zone], "ttl" => record[:ttl], "fqdn" => record[:fqdn], "record_type" => record[:type], "rdata" => record[:rdata], "record_id" => record[:record_id] }, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO"=>"add: Record added", "SOURCE"=>"BLL", "ERR_CD"=>nil, "LVL"=>"INFO" }] } response end |
#post_session ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/dynect/requests/dns/post_session.rb', line 21 def post_session response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => { "token" => auth_token, "version" => Fog::Dynect::Mock.version }, "job_id" => Fog::Dynect::Mock.job_id, "msgs"=>[{ "INFO"=>"login: Login successful", "SOURCE"=>"BLL", "ERR_CD"=>nil, "LVL"=>"INFO" }] } response end |
#post_zone(rname, ttl, zone, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/dynect/requests/dns/post_zone.rb', line 31 def post_zone(rname, ttl, zone, = {}) new_zone = self.data[:zones][zone] = { :next_record_id => 0, :records => Hash.new do |records_hash, type| records_hash[type] = [] end, :records_to_delete => [], :rname => rname, :serial_style => [:serial_style] || "increment", :serial => 0, :ttl => ttl, :zone => zone, :zone_type => "Primary" } response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => { "zone_type" => new_zone[:zone_type], "serial_style" => new_zone[:serial_style], "serial" => new_zone[:serial], "zone" => zone }, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => "create: New zone #{zone} created. Publish it to put it on our server.", "SOURCE" => "BLL", "ERR_CD" => nil, "LVL" => "INFO" }] } response end |
#put_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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/dynect/requests/dns/put_record.rb', line 31 def put_record(type, zone, fqdn, rdata, = {}) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] records = zone[:records] record_id = zone[:next_record_id] zone[:next_record_id] += 1 record = { :type => type, :zone => zone, :fqdn => fqdn, :rdata => rdata, :ttl => [:ttl] || zone[:ttl], :record_id => record_id } records[type] << record response = Excon::Response.new response.status = 200 response.body = { "status" => "success", "data" => { "zone" => record[:zone][:zone], "ttl" => record[:ttl], "fqdn" => record[:fqdn], "record_type" => record[:type], "rdata" => record[:rdata], "record_id" => record[:record_id] }, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO"=>"add: Record added", "SOURCE"=>"BLL", "ERR_CD"=>nil, "LVL"=>"INFO" }] } response end |
#put_zone(zone, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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/dynect/requests/dns/put_zone.rb', line 26 def put_zone(zone, = {}) raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] raise ArgumentError unless .size == 1 response = Excon::Response.new response.status = 200 data = {} if ['freeze'] zone['frozen'] = true info = "freeze: Your zone is now frozen" elsif ['publish'] zone[:changes] = {} zone[:records_to_delete].each do |record| zone[:records][record[:type]].delete_if { |r| r[:fqdn] == record[:fqdn] && r[:record_id] == record[:record_id] } end zone[:records_to_delete] = [] data = { "zone_type" => zone[:zone_type], "serial_style" => zone[:serial_style], "serial" => zone[:serial] += 1, "zone" => zone[:zone] } info = "publish: #{zone[:zone]} published" elsif ['thaw'] zone[:frozen] = false info = "thaw: Your zone is now thawed, you may edit normally" else raise ArgumentError end response.body = { "status" => "success", "data" => data, "job_id" => Fog::Dynect::Mock.job_id, "msgs" => [{ "INFO" => info, "SOURCE"=>"BLL", "ERR_CD"=>nil, "LVL"=>"INFO" }] } response end |
#reset_data ⇒ Object
56 57 58 |
# File 'lib/fog/dynect/dns.rb', line 56 def reset_data self.class.reset end |