Class: Interferon::HostSources::Optica

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/interferon/host_sources/optica.rb

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #log, #statsd

Constructor Details

#initialize(options) ⇒ Optica

Returns a new instance of Optica.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/interferon/host_sources/optica.rb', line 8

def initialize(options)
  raise ArgumentError, "missing host for optica source" \
    unless options['host']

  @host = options['host']
  @port = options['port'] || 80
end

Instance Method Details

#list_hostsObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/interferon/host_sources/optica.rb', line 16

def list_hosts
  return optica_data['nodes'].map{|ip, host| {
      :source => 'optica',
      :hostname => host['hostname'],
      :role => host['role'],
      :environment => host['environment'],

      :owners => host['ownership'] && host['ownership']['people'] || [],
      :owner_groups => host['ownership'] && host['ownership']['groups'] || [],
    }}
end

#optica_dataObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/interferon/host_sources/optica.rb', line 28

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