Class: Fleet::Discovery

Inherits:
Object
  • Object
show all
Defined in:
lib/fleet/discovery.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discovery_url = Fleetctl.options.discovery_url) ⇒ Discovery

Returns a new instance of Discovery.



11
12
13
# File 'lib/fleet/discovery.rb', line 11

def initialize(discovery_url = Fleetctl.options.discovery_url)
  @discovery_url = discovery_url
end

Instance Attribute Details

#discovery_urlObject

Returns the value of attribute discovery_url.



9
10
11
# File 'lib/fleet/discovery.rb', line 9

def discovery_url
  @discovery_url
end

Class Method Details

.hostsObject



4
5
6
# File 'lib/fleet/discovery.rb', line 4

def hosts
  new(discovery_url).hosts
end

Instance Method Details

#dataObject



15
16
17
# File 'lib/fleet/discovery.rb', line 15

def data
  @data ||= JSON.parse(Net::HTTP.get(URI.parse(@discovery_url)))
end

#hostsObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/fleet/discovery.rb', line 19

def hosts
  begin
    data['node']['nodes'].map{|node| node['value'].split(':')[0..1].join(':').split('//').last}
  rescue => e
    Fleetctl.logger.error 'ERROR in Fleet::Discovery#hosts, returning empty set'
    Fleetctl.logger.error e.message
    Fleetctl.logger.error e.backtrace.join("\n")
    []
  end
end