class Consul::Async::ServiceInstance
The ServiceInstance
has shortcuts (such as service_address
method), but is basically a Hash.
Public Class Methods
new(obj)
click to toggle source
# File lib/consul/async/consul_template.rb, line 501 def initialize(obj) merge!(obj) end
Public Instance Methods
current_weight()
click to toggle source
Return the weights applied on instance according to current status
# File lib/consul/async/consul_template.rb, line 551 def current_weight current_status = status weights[current_status.capitalize] || 0 end
node_meta()
click to toggle source
Return ['Node’]
# File lib/consul/async/consul_template.rb, line 506 def node_meta self['Node']['Meta'] || {} end
service_address()
click to toggle source
Return ['Service’] if defined, the address of node otherwise
# File lib/consul/async/consul_template.rb, line 511 def service_address val = self['Service']['Address'] val = self['Node']['Address'] unless !val.nil? && val != '' val end
service_meta()
click to toggle source
Return a defined hash of string valued Service.Meta
# File lib/consul/async/consul_template.rb, line 518 def service_meta self['Service']['Meta'] || {} end
service_or_node_meta_value(key)
click to toggle source
If given key exists in Service.Meta returns it, otherwise the same key from return Node.Meta, otherwise return nil
# File lib/consul/async/consul_template.rb, line 524 def service_or_node_meta_value(key) service_meta[key] || node_meta[key] end
status()
click to toggle source
Return the global state of a Service, will return passing|warning|critical
# File lib/consul/async/consul_template.rb, line 529 def status ret = 'passing' checks = self['Checks'] return ret unless checks checks.each do |chk| st = chk['Status'] if st == 'critical' ret = st elsif st == 'warning' && ret == 'passing' ret = st end end ret end