Class: Interferon::HostSources::OpticaServices
- Inherits:
-
Object
- Object
- Interferon::HostSources::OpticaServices
- Includes:
- Logging
- Defined in:
- lib/interferon/host_sources/optica_services.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ OpticaServices
constructor
A new instance of OpticaServices.
- #list_hosts ⇒ Object
- #optica_data ⇒ Object
Methods included from Logging
configure_logger_for, #log, #statsd
Constructor Details
#initialize(options) ⇒ OpticaServices
Returns a new instance of OpticaServices.
9 10 11 12 13 14 15 16 |
# File 'lib/interferon/host_sources/optica_services.rb', line 9 def initialize() raise ArgumentError, 'missing host for optica source' \ unless ['host'] @host = ['host'] @port = ['port'] || 80 @envs = ['environments'] || [] end |
Instance Method Details
#list_hosts ⇒ Object
29 30 31 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 |
# File 'lib/interferon/host_sources/optica_services.rb', line 29 def list_hosts services = Hash.new do |h, service| h[service] = { source: 'optica_services', service: service, owners: Set.new, owner_groups: Set.new, consumer_roles: Set.new, consumer_machine_count: 0, provider_machine_count: 0, } end optica_data['nodes'].each do |_ip, host| next unless @envs.empty? || @envs.include?(host['environment']) # make it easier by initializing possibly-missing data to sane defaults host['ownership'] ||= {} host['nerve_services'] ||= [] host['synapse_services'] ||= [] # provider info host['nerve_services'].each do |service| services[service][:provider_machine_count] += 1 services[service][:owners].merge(host['ownership']['people'] || []) services[service][:owner_groups].merge(host['ownership']['groups'] || []) end # consumer info host['synapse_services'].each do |service| services[service][:consumer_roles].add(host['role']) services[service][:consumer_machine_count] += 1 end end # convert all sets to arrays services.each do |k, v| services[k][:owners] = v[:owners].to_a services[k][:owner_groups] = v[:owner_groups].to_a services[k][:consumer_roles] = v[:consumer_roles].to_a end services.values end |
#optica_data ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/interferon/host_sources/optica_services.rb', line 18 def optica_data @optica_data ||= begin con = Net::HTTP.new(@host, @port) con.read_timeout = 60 con.open_timeout = 60 response = con.get('/') JSON.parse(response.body) end end |