module Proxy::Discovery

Constants

CREATE_DISCOVERED_HOST_PATH
VERSION

Public Class Methods

create_discovered_host(request) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Class Methods

generate_url(ip) click to toggle source
# File lib/smart_proxy_discovery/discovery_main.rb, line 51
def generate_url(ip)
  scheme = Proxy::Discovery::Plugin.settings.node_scheme
  port = Proxy::Discovery::Plugin.settings.node_port
  "#{scheme}://#{ip}:#{port}"
end
get_rest_client(url) click to toggle source
# File lib/smart_proxy_discovery/discovery_main.rb, line 57
def get_rest_client(url)
  RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE)
end