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
27
28
# File 'lib/interferon/host_sources/optica.rb', line 16

def list_hosts
  optica_data['nodes'].map do |_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
end

#optica_dataObject



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

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