Class: Imperium::Service
Overview
Service is a container for data being received from and sent to the agent services APIs.
Instance Attribute Summary collapse
-
#address ⇒ String
The network address to find the service at for DNS requests, defaults to the running agent’s IP if left blank.
-
#checks ⇒ Array<ServiceCheck>
Specifies a list of checks to use for monitoring the service’s health.
- #create_index ⇒ Integer readonly
-
#enable_tag_override ⇒ Boolean
Specifies to disable the anti-entropy feature for this service’s tags.
-
#id ⇒ String
The service’s id, when creating a new service this will be automatically assigned if not supplied, must be unique.
- #modify_index ⇒ Integer readonly
-
#name ⇒ String
The service’s name in the consul UI, required for creation, not required to be unique.
-
#port ⇒ Integer
The port the service is bound to for network services.
-
#tags ⇒ Arary<String>
List of tags to be used for the service, can be used after creation for filtering in the API.
Instance Method Summary collapse
- #add_check(val) ⇒ Object (also: #check=)
-
#initialize(*args) ⇒ Service
constructor
A new instance of Service.
-
#registration_data ⇒ Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
Generate a hash containing the data necessary for registering this service.
Methods inherited from APIObject
#==, #attribute_map, #ruby_attribute_names, #to_h
Constructor Details
#initialize(*args) ⇒ Service
46 47 48 49 50 51 |
# File 'lib/imperium/service.rb', line 46 def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end |
Instance Attribute Details
#address ⇒ String
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#checks ⇒ Array<ServiceCheck>
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#create_index ⇒ Integer (readonly)
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#enable_tag_override ⇒ Boolean
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#id ⇒ String
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#modify_index ⇒ Integer (readonly)
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#name ⇒ String
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#port ⇒ Integer
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
#tags ⇒ Arary<String>
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 80 81 82 83 84 85 86 |
# File 'lib/imperium/service.rb', line 32 class Service < APIObject self.attribute_map = { 'ID' => :id, 'Name' => :name, 'Tags' => :tags, 'Address' => :address, 'Port' => :port, 'Check' => :check, 'Checks' => :checks, 'EnableTagOverride' => :enable_tag_override, 'CreateIndex' => :create_index, 'ModifyIndex' => :modify_index } def initialize(*args) # So we can << onto these w/o having to nil check everywhere first ||= [] @checks ||= [] super end def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end alias check= add_check def checks=(val) @checks = (val || []).map { |obj| maybe_convert_service_check(obj) } end def (val) = (val.nil? ? [] : val) end # Generate a hash containing the data necessary for registering this service. # # If both Check and Checks are present in the object they're coalesced into # a single Checks key. # # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>] def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end private def maybe_convert_service_check(attrs_or_check) attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check end end |
Instance Method Details
#add_check(val) ⇒ Object Also known as: check=
53 54 55 |
# File 'lib/imperium/service.rb', line 53 def add_check(val) @checks << maybe_convert_service_check(val) unless val.nil? end |
#registration_data ⇒ Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
Generate a hash containing the data necessary for registering this service.
If both Check and Checks are present in the object they’re coalesced into a single Checks key.
73 74 75 76 77 78 79 |
# File 'lib/imperium/service.rb', line 73 def registration_data to_h.tap do |h| h.delete('CreateIndex') h.delete('ModifyIndex') h.delete('Checks') if checks.empty? end end |