Class: HammerCLIImport::ImportCommand::OrganizationImportCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLIImport::ImportCommand::OrganizationImportCommand
- Defined in:
- lib/hammer_cli_import/organization.rb
Instance Attribute Summary
Attributes included from PersistentMap::Extend
#map_description, #map_target_entity, #maps
Instance Method Summary collapse
- #delete_single_row(data) ⇒ Object
- #import_single_row(data) ⇒ Object
- #mk_org_hash(data) ⇒ Object
-
#upload_manifest_for(label, id) ⇒ Object
:subscriptions :upload => id, :content => File.new(filename, ‘rb’).
Methods inherited from BaseCommand
#_compare_hash, #_create_entity, #api_call, api_call, api_init, #create_entity, csv_columns, #cvs_iterate, #data_dir, #delete, #delete_entity, #delete_entity_by_import_id, #execute, #find_uniq, #found_errors, #get_cache, #get_original_id, #get_translated_id, #import, #initialize, #last_in_cache?, #list_server_entities, #load_cache, #lookup_entity, #lookup_entity_in_array, #lookup_entity_in_cache, #map_entity, #mapped_api_call, #post_delete, #post_import, #print_summary, #process_error, #recognizable_error, #report_summary, #split_multival, #to_singular, #unmap_entity, #update_entity, #wait_for_task, #was_translated
Methods included from PersistentMap::Extend
#persistent_map, #persistent_maps
Methods included from ImportTools::ImportLogging::Extend
Methods included from AsyncTasksReactor::Extend
#add_async_tasks_reactor_options
Methods included from AsyncTasksReactor::Include
#atr_exit, #atr_init, #postpone_till, #wait_for
Methods included from ImportTools::Exceptional::Include
#handle_missing_and_supress, #silently
Methods included from ImportTools::Task::Include
Methods included from ImportTools::ImportLogging::Include
#debug, #error, #fatal, #info, #log, #logtrace, #progress, #setup_logging, #warn
Methods included from PersistentMap::Include
#load_persistent_maps, #map_target_entity, #maps, #prune_persistent_maps, #save_persistent_maps
Constructor Details
This class inherits a constructor from HammerCLIImport::BaseCommand
Instance Method Details
#delete_single_row(data) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hammer_cli_import/organization.rb', line 88 def delete_single_row(data) org_id = data['organization_id'].to_i unless @pm[:organizations][org_id] warn "#{to_singular(:organizations).capitalize} with id #{org_id} wasn't imported. Skipping deletion." return end target_org_id = get_translated_id(:organizations, org_id) if last_in_cache?(:organizations, target_org_id) warn "Won't delete last organization [#{target_org_id}]. Unmapping only." unmap_entity(:organizations, target_org_id) return end if target_org_id == 1 warn "Won't delete organization with id [#{target_org_id}]. Unmapping only." unmap_entity(:organizations, target_org_id) return end delete_entity(:organizations, org_id) end |
#import_single_row(data) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/hammer_cli_import/organization.rb', line 74 def import_single_row(data) if option_into_org_id unless lookup_entity_in_cache(:organizations, {'id' => option_into_org_id}) warn "Organization [#{option_into_org_id}] not found. Skipping." return end map_entity(:organizations, data['organization_id'].to_i, option_into_org_id) return end org = mk_org_hash data new_org = create_entity(:organizations, org, data['organization_id'].to_i) upload_manifest_for(new_org['label'], new_org['id']) unless option_upload_manifests_from.nil? end |
#mk_org_hash(data) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/hammer_cli_import/organization.rb', line 44 def mk_org_hash(data) { :id => data['organization_id'].to_i, :name => data['organization'], :description => "Imported '#{data['organization']}' organization from Red Hat Satellite 5" } end |
#upload_manifest_for(label, id) ⇒ Object
:subscriptions :upload => id, :content => File.new(filename, ‘rb’)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hammer_cli_import/organization.rb', line 53 def upload_manifest_for(label, id) # Remember labels we've already processed in this run @manifests ||= [] return if @manifests.include? label @manifests << label filename = option_upload_manifests_from + '/' + label + '.zip' unless File.exist? filename error "No manifest #{filename} available." return end info "Uploading manifest #{filename} to org-id #{id}" manifest_file = File.new(filename, 'rb') request_headers = {:content_type => 'multipart/form-data', :multipart => true} rc = api_call :subscriptions, :upload, {:organization_id => id, :content => manifest_file}, request_headers wait_for_task(rc['id']) report_summary :uploaded, :manifests end |