class Interferon::HostSources::Optica

Public Class Methods

new(options) click to toggle source
# 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

Public Instance Methods

list_hosts() click to toggle source
# 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_data() click to toggle source
# 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