lib/arborist/node/service.rb in arborist-0.2.0.pre20170519125456 vs lib/arborist/node/service.rb in arborist-0.2.0

- old
+ new

@@ -52,10 +52,23 @@ ###### public ###### + ## + # Get/set the port the service binds to + dsl_accessor :port + + ## + # Get/set the application protocol the service uses + dsl_accessor :app_protocol + + ## + # Get/set the network protocol the service uses + dsl_accessor :protocol + + ### Set service +attributes+. def modify( attributes ) attributes = stringify_keys( attributes ) super @@ -64,31 +77,10 @@ self.app_protocol( attributes['app_protocol'] ) self.protocol( attributes['protocol'] ) end - ### Get/set the port the service is bound to. - def port( new_port=nil ) - return @port unless new_port - @port = new_port - end - - - ### Get/set the (layer 7) protocol used by the service - def app_protocol( new_proto=nil ) - return @app_protocol unless new_proto - @app_protocol = new_proto - end - - - ### Get/set the transport layer protocol the service uses - def protocol( new_proto=nil ) - return @protocol unless new_proto - @protocol = new_proto - end - - ### Set an IP address of the service. This must be one of the addresses of its ### containing host. def address( new_address ) self.log.debug "Adding address %p to %p" % [ new_address, self ] normalized_addresses = normalize_address( new_address ) @@ -107,22 +99,32 @@ def addresses return @addresses || @host.addresses end + ### Delegate the service's hostname to it's parent host. + def hostname + return @host.hostname + end + + ### Returns +true+ if the node matches the specified +key+ and +val+ criteria. def match_criteria?( key, val ) self.log.debug "Matching %p: %p against %p" % [ key, val, self ] + array_val = Array( val ) return case key when 'port' - val = default_port_for( val, @protocol ) unless val.is_a?( Fixnum ) - self.port == val.to_i + vals = array_val.collect do |port| + port = default_port_for( port, @protocol ) unless port.is_a?( Integer ) + port.to_i + end + vals.include?( self.port ) when 'address' search_addr = IPAddr.new( val ) self.addresses.any? {|a| search_addr.include?(a) } - when 'protocol' then self.protocol == val.downcase - when 'app', 'app_protocol' then self.app_protocol == val + when 'protocol' then array_val.include?( self.protocol ) + when 'app', 'app_protocol' then array_val.include?( self.app_protocol ) else super end end @@ -130,10 +132,11 @@ ### Return a Hash of the operational values that are included with the node's ### monitor state. def operational_values return super.merge( addresses: self.addresses.map( &:to_s ), + hostname: self.hostname, port: self.port, protocol: self.protocol, app_protocol: self.app_protocol, ) end @@ -159,10 +162,10 @@ # # Serialization # ### Return a Hash of the host node's state. - def to_h + def to_h( * ) return super.merge( addresses: self.addresses.map(&:to_s), protocol: self.protocol, app_protocol: self.app_protocol, port: self.port