Class: HammerCLICsv::CsvCommand::ImportCommand

Inherits:
HammerCLI::Apipie::Command
  • Object
show all
Defined in:
lib/hammer_cli_csv/import.rb

Constant Summary collapse

RESOURCES =
%w( organizations locations roles users puppet_environments operating_systems
domains architectures partition_tables lifecycle_environments host_collections
subscriptions activation_keys hosts content_hosts reports )

Instance Method Summary collapse

Instance Method Details

#executeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hammer_cli_csv/import.rb', line 41

def execute
  @api = ApipieBindings::API.new({
                                   :uri => option_server || HammerCLI::Settings.get(:csv, :host),
                                   :username => option_username || HammerCLI::Settings.get(:csv, :username),
                                   :password => option_password || HammerCLI::Settings.get(:csv, :password),
                                   :api_version => 2
                                 })

  # Swing the hammers
  RESOURCES.each do |resource|
    hammer_resource(resource)
  end

  HammerCLI::EX_OK
end

#hammer(context = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/hammer_cli_csv/import.rb', line 57

def hammer(context = nil)
  context ||= {
    :interactive => false,
    :username => 'admin', # TODO: this needs to come from config/settings
    :password => 'changeme' # TODO: this needs to come from config/settings
  }

  HammerCLI::MainCommand.new('', context)
end

#hammer_resource(resource) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hammer_cli_csv/import.rb', line 67

def hammer_resource(resource)
  return if !self.send("option_#{resource}") && !option_dir
  options_file = self.send("option_#{resource}") || "#{option_dir}/#{resource.sub('_', '-')}.csv"
  if !File.exists? options_file
    return if option_dir
    raise "File for #{resource} '#{options_file}' does not exist"
  end

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