Module: Proxy::Discovery

Extended by:
Log, Util
Defined in:
lib/smart_proxy_discovery/version.rb,
lib/smart_proxy_discovery/discovery.rb,
lib/smart_proxy_discovery/discovery_api.rb,
lib/smart_proxy_discovery/discovery_main.rb

Defined Under Namespace

Modules: ApiHelpers Classes: Dispatcher, InboundApi, NotFound, OutboundApi, Plugin

Constant Summary collapse

VERSION =
'1.0.5'
CREATE_DISCOVERED_HOST_PATH =
'/api/v2/discovered_hosts/facts'

Class Method Summary collapse

Class Method Details

.create_discovered_host(request) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 12

def create_discovered_host(request)
  foreman_request = Proxy::HttpRequest::ForemanRequest.new()
  req = foreman_request.request_factory.create_post(CREATE_DISCOVERED_HOST_PATH, request.body.read)
  response = foreman_request.send_request(req)
  unless response.is_a? Net::HTTPSuccess
    msg = JSON.parse(response.body)['message'] rescue "N/A"
    raise "Discovery failed, code #{response.code}, reason: #{msg}"
  end
end

.inventory_facter(ip) ⇒ Object



22
23
24
25
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 22

def inventory_facter(ip)
  client = get_rest_client(generate_url(ip))
  client["/inventory/facter"].get()
end

.kexec(ip, body) ⇒ Object



44
45
46
47
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 44

def kexec(ip, body)
  client = get_rest_client(generate_url(ip))
  client["/power/kexec"].put(body)
end

.reboot(ip) ⇒ Object



39
40
41
42
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 39

def reboot(ip)
  client = get_rest_client(generate_url(ip))
  client["/power/reboot"].put({})
end

.reboot_legacy(ip) ⇒ Object



32
33
34
35
36
37
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 32

def reboot_legacy(ip)
  url         = "http://#{ip}:8443"
  reboot_path = "/bmc/#{ip}/chassis/power/cycle"
  client      = get_rest_client(url)
  client[reboot_path].put({})
end

.refresh_facts_legacy(ip) ⇒ Object



27
28
29
30
# File 'lib/smart_proxy_discovery/discovery_main.rb', line 27

def refresh_facts_legacy(ip)
  client = get_rest_client(generate_url(ip))
  client['/facts'].get
end