module HammerCLIForeman::Interface::InterfaceUpdate

Public Class Methods

included(base) click to toggle source
# File lib/hammer_cli_foreman/interface.rb, line 76
def self.included(base)
  base.option "--primary", :flag, _("Should this interface be used for constructing the FQDN of the host? Each managed hosts needs to have one primary interface.")
  base.option "--provision", :flag, _("Should this interface be used for TFTP of PXELinux (or SSH for image-based hosts)? Each managed hosts needs to have one provision interface.")
end

Public Instance Methods

get_interfaces(host_id) click to toggle source
# File lib/hammer_cli_foreman/interface.rb, line 81
def get_interfaces(host_id)
  HammerCLIForeman.foreman_resource!(:interfaces).call(:index, {'host_id' => host_id}, request_headers, request_options)
end
mandatory_interfaces(host_id, nic_id) click to toggle source
# File lib/hammer_cli_foreman/interface.rb, line 85
def mandatory_interfaces(host_id, nic_id)
  mandatory_options = []
  get_interfaces(host_id)['results'].each do |nic|
    if (nic['primary'] || nic['provision']) && nic['id'] != nic_id
      mandatory_options << {
        'id' => nic['id'],
        'primary' => nic['primary'],
        'provision' => nic['provision']
      }
    end
  end
  mandatory_options
end
reset_flag(interfaces_params, flag) click to toggle source
# File lib/hammer_cli_foreman/interface.rb, line 99
def reset_flag(interfaces_params, flag)
  interfaces_params.each do |nic|
    nic[flag] = false if nic[flag]
  end
end
send_request() click to toggle source
# File lib/hammer_cli_foreman/interface.rb, line 105
def send_request
  nic_params = request_params
  interface = nic_params['interface']

  interface['id'] = nic_params['id'].to_i if nic_params['id']
  interface['compute_attributes'] = option_compute_attributes

  host_params = {}
  host_params['id'] = nic_params['host_id']
  host_params['host'] = {}
  host_params['host']['interfaces_attributes'] = mandatory_interfaces(nic_params['host_id'], interface['id'])

  reset_flag(host_params['host']['interfaces_attributes'], 'primary') if option_primary?
  reset_flag(host_params['host']['interfaces_attributes'], 'provision') if option_provision?

  host_params['host']['interfaces_attributes'] += [interface]

  HammerCLIForeman.foreman_resource!(:hosts).call(:update, host_params, request_headers, request_options)
end