<commit_before>require 'stackbuilder/support/namespace'
require 'stackbuilder/support/mcollective'

class Support::MCollectiveHpilo
  include Support::MCollective

  def update_ilo_firmware(host_fqdn, fabric)
    do_hpilo_call(fabric, "update_rib_firmware", :host_fqdn => to_ilo_host_fqdn(host_fqdn), :version => "latest")
  end

  def set_one_time_network_boot(host_fqdn, fabric)
    do_hpilo_call(fabric, "set_one_time_boot", :host_fqdn => to_ilo_host_fqdn(host_fqdn), :device => "network")
  end

  def power_off_host(host_fqdn, fabric)
    do_hpilo_call(fabric, "power_off", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    sleep 2 while get_host_power_status(host_fqdn, fabric) == 'ON'
  end

  def power_on_host(host_fqdn, fabric)
    do_hpilo_call(fabric, "power_on", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    sleep 2 while get_host_power_status(host_fqdn, fabric) == 'OFF'
  end

  def get_host_power_status(host_fqdn, fabric)
    result = do_hpilo_call(fabric, "power_status", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    result[:power]
  end

  def get_mac_address(host_fqdn, fabric)
    result = do_hpilo_call(fabric, "get_host_data", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    result[:mac_address]
  end

  private

  def to_ilo_host_fqdn(host_fqdn)
    host_fqdn.sub("mgmt", "ilo")
  end

  def do_hpilo_call(fabric, action, args_hash)
    rsps = mco_client("hpilo", :timeout => 10, :fabric => fabric) { |mco| mco.send(action, args_hash) }

    fail "no response to mco hpilo call for fabric #{fabric}" unless rsps.size == 1
    fail "failed during mco hpilo call for fabric #{fabric}: #{rsps[0][:statusmsg]}" unless rsps[0][:statuscode] == 0

    logger(Logger::INFO) { "Successfully carried out mco hpilo #{action} operation on #{rsps[0][:sender]}" }
    rsps[0][:data]
  end
end<commit_msg>tomd: mac address is in the :output sub thingy<commit_after>require 'stackbuilder/support/namespace'
require 'stackbuilder/support/mcollective'

class Support::MCollectiveHpilo
  include Support::MCollective

  def update_ilo_firmware(host_fqdn, fabric)
    do_hpilo_call(fabric, "update_rib_firmware", :host_fqdn => to_ilo_host_fqdn(host_fqdn), :version => "latest")
  end

  def set_one_time_network_boot(host_fqdn, fabric)
    do_hpilo_call(fabric, "set_one_time_boot", :host_fqdn => to_ilo_host_fqdn(host_fqdn), :device => "network")
  end

  def power_off_host(host_fqdn, fabric)
    do_hpilo_call(fabric, "power_off", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    sleep 2 while get_host_power_status(host_fqdn, fabric) == 'ON'
  end

  def power_on_host(host_fqdn, fabric)
    do_hpilo_call(fabric, "power_on", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    sleep 2 while get_host_power_status(host_fqdn, fabric) == 'OFF'
  end

  def get_host_power_status(host_fqdn, fabric)
    result = do_hpilo_call(fabric, "power_status", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    result[:power]
  end

  def get_mac_address(host_fqdn, fabric)
    result = do_hpilo_call(fabric, "get_host_data", :host_fqdn => to_ilo_host_fqdn(host_fqdn))
    result[:output][:mac_address]
  end

  private

  def to_ilo_host_fqdn(host_fqdn)
    host_fqdn.sub("mgmt", "ilo")
  end

  def do_hpilo_call(fabric, action, args_hash)
    rsps = mco_client("hpilo", :timeout => 10, :fabric => fabric) { |mco| mco.send(action, args_hash) }

    fail "no response to mco hpilo call for fabric #{fabric}" unless rsps.size == 1
    fail "failed during mco hpilo call for fabric #{fabric}: #{rsps[0][:statusmsg]}" unless rsps[0][:statuscode] == 0

    logger(Logger::INFO) { "Successfully carried out mco hpilo #{action} operation on #{rsps[0][:sender]}" }
    rsps[0][:data]
  end
end
{'fraction_non_alphanumeric': 0.12173202614379085, 'fraction_numerical': 0.0054466230936819175, 'mean_word_length': 5.618018018018018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '404910', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1439, 'n_words': 275}