Class: Consul::Async::ServiceInstance
- Inherits:
-
Hash
- Object
- Hash
- Consul::Async::ServiceInstance
- Defined in:
- lib/consul/async/consul_template.rb
Overview
The ServiceInstance has shortcuts (such as service_address method), but is basically a Hash.
Instance Method Summary collapse
-
#current_weight ⇒ Object
Return the weights applied on instance according to current status.
-
#initialize(obj) ⇒ ServiceInstance
constructor
A new instance of ServiceInstance.
-
#node_meta ⇒ Object
Return ['Node']['Meta'].
-
#service_address ⇒ Object
Return ['Service']['Address'] if defined, the address of node otherwise.
-
#service_meta ⇒ Object
Return a defined hash of string valued Service.Meta.
-
#service_or_node_meta_value(key) ⇒ Object
If given key exists in Service.Meta returns it, otherwise the same key from return Node.Meta, otherwise return nil.
-
#status ⇒ Object
Return the global state of a Service, will return passing|warning|critical.
-
#weights ⇒ Object
Return Consul weights even if Consul version < 1.2.3 with same semantics.
Constructor Details
#initialize(obj) ⇒ ServiceInstance
Returns a new instance of ServiceInstance.
502 503 504 505 |
# File 'lib/consul/async/consul_template.rb', line 502 def initialize(obj) super merge!(obj) end |
Instance Method Details
#current_weight ⇒ Object
Return the weights applied on instance according to current status
553 554 555 556 |
# File 'lib/consul/async/consul_template.rb', line 553 def current_weight current_status = status weights[current_status.capitalize] || 0 end |
#node_meta ⇒ Object
Return ['Node']['Meta']
508 509 510 |
# File 'lib/consul/async/consul_template.rb', line 508 def self['Node']['Meta'] || {} end |
#service_address ⇒ Object
Return ['Service']['Address'] if defined, the address of node otherwise
513 514 515 516 517 |
# File 'lib/consul/async/consul_template.rb', line 513 def service_address val = self['Service']['Address'] val = self['Node']['Address'] unless !val.nil? && val != '' val end |
#service_meta ⇒ Object
Return a defined hash of string valued Service.Meta
520 521 522 |
# File 'lib/consul/async/consul_template.rb', line 520 def self['Service']['Meta'] || {} end |
#service_or_node_meta_value(key) ⇒ Object
If given key exists in Service.Meta returns it, otherwise the same key from return Node.Meta, otherwise return nil
526 527 528 |
# File 'lib/consul/async/consul_template.rb', line 526 def (key) [key] || [key] end |
#status ⇒ Object
Return the global state of a Service, will return passing|warning|critical
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/consul/async/consul_template.rb', line 531 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 |
#weights ⇒ Object
Return Consul weights even if Consul version < 1.2.3 with same semantics
548 549 550 |
# File 'lib/consul/async/consul_template.rb', line 548 def weights self['Service']['Weights'] || { 'Passing' => 1, 'Warning' => 1 } end |