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’].
-
#service_address ⇒ Object
Return [‘Service’] 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 |
# File 'lib/consul/async/consul_template.rb', line 502 def initialize(obj) merge!(obj) end |
Instance Method Details
#current_weight ⇒ Object
Return the weights applied on instance according to current status
552 553 554 555 |
# File 'lib/consul/async/consul_template.rb', line 552 def current_weight current_status = status weights[current_status.capitalize] || 0 end |
#node_meta ⇒ Object
Return [‘Node’]
507 508 509 |
# File 'lib/consul/async/consul_template.rb', line 507 def self['Node']['Meta'] || {} end |
#service_address ⇒ Object
Return [‘Service’] if defined, the address of node otherwise
512 513 514 515 516 |
# File 'lib/consul/async/consul_template.rb', line 512 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
519 520 521 |
# File 'lib/consul/async/consul_template.rb', line 519 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
525 526 527 |
# File 'lib/consul/async/consul_template.rb', line 525 def (key) [key] || [key] end |
#status ⇒ Object
Return the global state of a Service, will return passing|warning|critical
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/consul/async/consul_template.rb', line 530 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
547 548 549 |
# File 'lib/consul/async/consul_template.rb', line 547 def weights self['Service']['Weights'] || { 'Passing' => 1, 'Warning' => 1 } end |