Class: Dyn::Traffic::GSLB
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #[](host_list_key) ⇒ Object
- #add_host(value) ⇒ Object
- #contact_nick(value = nil) ⇒ Object
- #delete ⇒ Object
- #find(fqdn, query_hash) ⇒ Object
- #fqdn(value = nil) ⇒ Object
- #get(fqdn = nil, region_code = 'global') ⇒ Object
- #host_list(value = nil) ⇒ Object
-
#initialize(dyn, zone, options) ⇒ GSLB
constructor
A new instance of GSLB.
- #min_healthy(value = nil) ⇒ Object
- #monitor(value = nil) ⇒ Object
- #region_code(value = nil) ⇒ Object
- #resource_path ⇒ Object
- #save(replace = false) ⇒ Object
- #serve_count(value = nil) ⇒ Object
- #to_json ⇒ Object
- #ttl(value = nil) ⇒ Object
Methods inherited from Base
#discard_change_set, #freeze, #get_change_set, #publish, #thaw
Constructor Details
#initialize(dyn, zone, options) ⇒ GSLB
Returns a new instance of GSLB.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dyn/traffic/gslb.rb', line 26 def initialize(dyn, zone, ) @dyn = dyn @zone = zone @resource_path = "GSLB/#{@zone}" @fqdn = [:fqdn] @ttl = [:ttl] || 30 @host_list = [:host_list] || {} @contact_nick = [:contact_nick] || 'owner' @region_code = [:region_code] || 'global' @monitor = [:monitor] || {} @serve_count = [:serve_count] || 1 @min_healthy = [:min_healthy] || 1 end |
Instance Method Details
#[](host_list_key) ⇒ Object
42 43 44 |
# File 'lib/dyn/traffic/gslb.rb', line 42 def [](host_list_key) @host_list[host_list_key] end |
#add_host(value) ⇒ Object
87 88 89 90 91 |
# File 'lib/dyn/traffic/gslb.rb', line 87 def add_host(value) # :address => 'x.x.x.x', :label => 'friendly-name', :weight => 10, :serve_mode => 'obey' @host_list[value[:address]] = value self end |
#contact_nick(value = nil) ⇒ Object
50 51 52 |
# File 'lib/dyn/traffic/gslb.rb', line 50 def contact_nick(value=nil) value ? (@contact_nick = value; self) : @contact_nick end |
#delete ⇒ Object
150 151 152 |
# File 'lib/dyn/traffic/gslb.rb', line 150 def delete @dyn.delete("#{@resource_path}/#{fqdn}") end |
#find(fqdn, query_hash) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/dyn/traffic/gslb.rb', line 131 def find(fqdn, query_hash) results = [] get(fqdn).each do |rr| query_hash.each do |key, value| results << rr if rr[key.to_s] == value end end results end |
#fqdn(value = nil) ⇒ Object
46 47 48 |
# File 'lib/dyn/traffic/gslb.rb', line 46 def fqdn(value=nil) value ? (@fqdn = value; self) : @fqdn end |
#get(fqdn = nil, region_code = 'global') ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/dyn/traffic/gslb.rb', line 97 def get(fqdn=nil, region_code='global') if fqdn results = @dyn.get("#{@resource_path}/#{fqdn}") region = {} results["region"].each {|r| region = r if r["region_code"] == region_code} raise Dyn::Exceptions::RequestFailed, "Cannot find #{region_code} GSLB pool for #{fqdn}" if region.empty? # Default monitor timeout is 0, but specifying timeout 0 on a put or post results in an exception results["monitor"].delete("timeout") if results["monitor"]["timeout"] == 0 host_list = {} region["pool"].each do |h| host_list[h["address"]] = { :address => h["address"], :label => h["label"], :weight => h["weight"], :serve_mode => h["serve_mode"] } end Dyn::Traffic::GSLB.new(@dyn, results["zone"], { :fqdn => results["fqdn"], :ttl => results["ttl"], :host_list => host_list, :contact_nick => results["contact_nickname"], :region_code => region["region_code"], :monitor => results["monitor"], :serve_count => region["serve_count"], :min_healthy => region["min_healthy"] }) else @dyn.get(resource_path) end end |
#host_list(value = nil) ⇒ Object
71 72 73 |
# File 'lib/dyn/traffic/gslb.rb', line 71 def host_list(value=nil) value ? (@host_list = value; self) : @host_list end |
#min_healthy(value = nil) ⇒ Object
58 59 60 |
# File 'lib/dyn/traffic/gslb.rb', line 58 def min_healthy(value=nil) value ? (@min_healthy = value; self) : @min_healthy end |
#monitor(value = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dyn/traffic/gslb.rb', line 75 def monitor(value=nil) # :protocol => 'HTTP', :interval => 1, :retries => 2, :timeout => 10, :port => 8000, # :path => '/healthcheck', :host => 'example.com', :header => 'X-User-Agent: DynECT Health\n', :expected => 'passed' if value @monitor = {} value.each do |k,v| @monitor[k] = v end end @monitor end |
#region_code(value = nil) ⇒ Object
66 67 68 69 |
# File 'lib/dyn/traffic/gslb.rb', line 66 def region_code(value=nil) # US West, US Central, US East, EU West, EU Central, EU East, Asia, global value ? (@region_code = value; self) : @region_code end |
#resource_path ⇒ Object
93 94 95 |
# File 'lib/dyn/traffic/gslb.rb', line 93 def resource_path "GSLB/#{@zone}" end |
#save(replace = false) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/dyn/traffic/gslb.rb', line 141 def save(replace=false) if replace == true || replace == :replace @dyn.put("#{@resource_path}/#{@fqdn}", self) else @dyn.post("#{@resource_path}/#{@fqdn}", self) end self end |
#serve_count(value = nil) ⇒ Object
62 63 64 |
# File 'lib/dyn/traffic/gslb.rb', line 62 def serve_count(value=nil) value ? (@serve_count = value; self) : @serve_count end |
#to_json ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/dyn/traffic/gslb.rb', line 154 def to_json { "ttl" => @ttl, "monitor" => @monitor, "region" => { "region_code" => @region_code, "serve_count" => @serve_count, "min_healthy" => @min_healthy, "pool" => @host_list.values }, "contact_nickname" => @contact_nick }.to_json end |
#ttl(value = nil) ⇒ Object
54 55 56 |
# File 'lib/dyn/traffic/gslb.rb', line 54 def ttl(value=nil) value ? (@ttl = value; self) : @ttl end |