Class: HammerCLICsv::CsvCommand::ImportCommand
- Inherits:
-
HammerCLI::Apipie::Command
- Object
- HammerCLI::Apipie::Command
- HammerCLICsv::CsvCommand::ImportCommand
- Defined in:
- lib/hammer_cli_csv/import.rb
Constant Summary collapse
- RESOURCES =
%w( organizations locations puppet_environments operating_systems domains architectures partition_tables lifecycle_environments host_collections provisioning_templates subscriptions products content_views content_view_filters activation_keys hosts content_hosts reports roles users )
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hammer_cli_csv/import.rb', line 33 def execute @api = ApipieBindings::API.new({:uri => get_option(:host), :username => get_option(:username), :password => get_option(:password), :api_version => 2}) # Swing the hammers RESOURCES.each do |resource| hammer_resource(resource) end HammerCLI::EX_OK end |
#hammer(context = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/hammer_cli_csv/import.rb', line 45 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
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hammer_cli_csv/import.rb', line 55 def hammer_resource(resource) return if !self.send("option_#{resource}") && !option_dir = self.send("option_#{resource}") || "#{option_dir}/#{resource.sub('_', '-')}.csv" if !File.exists? 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 |