class HammerCLICsv::CsvCommand::ImportCommand

Constants

RESOURCES
SUPPORTED_RESOURCES

Public Class Methods

supported?() click to toggle source
# File lib/hammer_cli_csv/import.rb, line 11
def self.supported?
  true
end

Public Instance Methods

execute() click to toggle source
# File lib/hammer_cli_csv/import.rb, line 39
def execute
  @api = api_connection

  resources_specified = RESOURCES.collect do |resource|
    resource if self.send("option_#{resource}") || ARGV.include?('--' + resource.gsub('_', '-'))
  end
  resources_specified.compact!
  RESOURCES.each do |resource|
    if resources_specified.include?(resource) || (resources_specified == [] && option_dir)
      hammer_resource(resource)
    end
  end

  HammerCLI::EX_OK
end
hammer(context = nil) click to toggle source
# File lib/hammer_cli_csv/import.rb, line 55
def hammer(context = nil)
  context ||= {
    :interactive => false,
    :username => @username,
    :password => @password
  }

  HammerCLI::MainCommand.new('', context)
end
hammer_resource(resource) click to toggle source
# File lib/hammer_cli_csv/import.rb, line 65
def hammer_resource(resource)
  return if !self.send("option_#{resource}") && !option_dir
  options_file = option_dir ? "#{option_dir}/#{resource.gsub('_', '-')}.csv" :  self.send("option_#{resource}")
  unless options_file_exists? options_file
    if option_dir
      return unless SUPPORTED_RESOURCES.include?(resource)
      puts _("Skipping %{resource} because '%{options_file}' does not exist") %
        {:resource => resource, :options_file => options_file} if option_verbose?
      return
    end
    raise "File for #{resource} '#{options_file}' does not exist"
  end
  puts _("Importing %{resource} from '%{options_file}'") %
    {:resource => resource, :options_file => options_file} if option_verbose?

  args = %W( csv #{resource.gsub('_', '-')} --file #{options_file} )
  args << '-v' if option_verbose?
  args += %W( --organization #{option_organization} ) if option_organization
  args += %W( --prefix #{option_prefix} ) if option_prefix
  args += %W( --threads #{option_threads} ) if option_threads
  hammer.run(args)
end

Private Instance Methods

get_option(name) click to toggle source
# File lib/hammer_cli_csv/import.rb, line 98
def get_option(name)
  HammerCLI::Settings.settings[:_params][name] ||
    HammerCLI::Settings.get(:csv, name) ||
    HammerCLI::Settings.get(:katello, name) ||
    HammerCLI::Settings.get(:foreman, name)
end
options_file_exists?(options_file) click to toggle source
# File lib/hammer_cli_csv/import.rb, line 90
def options_file_exists?(options_file)
  f = open(options_file)
  f.close
  true
rescue
  false
end