Revision 00542595
Added by Thomas McKay about 6 years ago
lib/hammer_cli_import/base.rb | ||
---|---|---|
75 | 75 |
@summary = {} |
76 | 76 |
# Initialize AsyncTaskReactor |
77 | 77 |
atr_init |
78 |
|
|
79 |
server = (HammerCLI::Settings.settings[:_params] && |
|
80 |
HammerCLI::Settings.settings[:_params][:host]) || |
|
81 |
HammerCLI::Settings.get(:foreman, :host) |
|
82 |
username = (HammerCLI::Settings.settings[:_params] && |
|
83 |
HammerCLI::Settings.settings[:_params][:username]) || |
|
84 |
HammerCLI::Settings.get(:foreman, :username) |
|
85 |
password = (HammerCLI::Settings.settings[:_params] && |
|
86 |
HammerCLI::Settings.settings[:_params][:password]) || |
|
87 |
HammerCLI::Settings.get(:foreman, :password) |
|
88 |
@api = ApipieBindings::API.new({ |
|
89 |
:uri => server, |
|
90 |
:username => username, |
|
91 |
:password => password, |
|
92 |
:api_version => 2 |
|
93 |
}) |
|
78 | 94 |
end |
79 | 95 |
|
80 | 96 |
# What spacewalk-report do we expect to use for a given subcommand |
... | ... | |
427 | 443 |
return get_cache(entity_type)[@pm[entity_type][original_id]] |
428 | 444 |
else |
429 | 445 |
info 'Creating new ' + type + ': ' + entity_hash.values_at(:name, :label, :login).compact[0] |
430 |
entity_hash = {@wrap_out[entity_type] => entity_hash} if @wrap_out[entity_type] |
|
431 |
debug "entity_hash: #{entity_hash.inspect}" |
|
432 |
entity = mapped_api_call(entity_type, :create, entity_hash) |
|
446 |
if entity_type == :systems |
|
447 |
entity = @api.resource(:host_subscriptions).call(:create, entity_hash) |
|
448 |
params = { |
|
449 |
'id' => entity['id'], |
|
450 |
'host' => { |
|
451 |
'comment' => entity_hash[:description] |
|
452 |
} |
|
453 |
} |
|
454 |
@api.resource(:hosts).call(:update, params) |
|
455 |
@api.resource(:host_collections).call(:add_hosts, { |
|
456 |
'id' => entity_hash[:host_collection_ids][0], |
|
457 |
'host_ids' => [entity['id']] |
|
458 |
}) |
|
459 |
entity['id'] = entity['id'].to_s |
|
460 |
else |
|
461 |
entity_hash = {@wrap_out[entity_type] => entity_hash} if @wrap_out[entity_type] |
|
462 |
debug "entity_hash: #{entity_hash.inspect}" |
|
463 |
entity = mapped_api_call(entity_type, :create, entity_hash) |
|
464 |
end |
|
433 | 465 |
debug "created entity: #{entity.inspect}" |
434 | 466 |
entity = entity[@wrap_in[entity_type]] if @wrap_in[entity_type] |
435 |
# workaround for Bug |
|
436 |
entity['id'] = entity['uuid'] if entity_type == :systems |
|
437 | 467 |
@pm[entity_type][original_id] = entity['id'] |
438 | 468 |
get_cache(entity_type)[entity['id']] = entity |
439 | 469 |
debug "@pm[#{entity_type}]: #{@pm[entity_type].inspect}" |
lib/hammer_cli_import/contenthost.rb | ||
---|---|---|
25 | 25 |
class ImportCommand |
26 | 26 |
class ContentHostImportCommand < BaseCommand |
27 | 27 |
include ImportTools::ContentView::Include |
28 |
include ImportTools::LifecycleEnvironment::Include |
|
28 | 29 |
|
29 | 30 |
command_name 'content-host' |
30 | 31 |
reportname = 'system-profiles' |
... | ... | |
57 | 58 |
hcollections = split_multival(data['system_group_id']).collect do |sg_id| |
58 | 59 |
get_translated_id(:host_collections, sg_id) |
59 | 60 |
end |
61 |
org_id = get_translated_id(:organizations, data['organization_id'].to_i) |
|
60 | 62 |
{ |
61 | 63 |
:name => data['profile_name'], |
62 |
:description => "#{data['description']}\nsat5_system_id: #{data['server_id']}",
|
|
64 |
:comment => "#{data['description']}\nsat5_system_id: #{data['server_id']}",
|
|
63 | 65 |
:facts => {'release' => data['release'], 'architecture' => data['architecture']}, |
64 |
:type => 'system', |
|
65 | 66 |
# :guest_ids => [], |
66 |
:organization_id => get_translated_id(:organizations, data['organization_id'].to_i), |
|
67 |
:organization_id => org_id, |
|
68 |
:lifecycle_environment_id => get_env(org_id)['id'], |
|
67 | 69 |
:content_view_id => cv_id, |
68 | 70 |
:host_collection_ids => hcollections |
69 | 71 |
} |
... | ... | |
90 | 92 |
# store processed system profiles to a set according to the organization |
91 | 93 |
@map << { |
92 | 94 |
:org_id => data['organization_id'].to_i, |
93 |
:system_id => data['server_id'].to_i,
|
|
95 |
:host_id => data['server_id'].to_i,
|
|
94 | 96 |
:uuid => c_host['uuid']} |
95 | 97 |
# associate virtual guests in post_import to make sure, all the guests |
96 | 98 |
# are already imported (and known to sat6) |
... | ... | |
157 | 159 |
info "#{to_singular(:systems).capitalize} with id #{profile_id} wasn't imported. Skipping deletion." |
158 | 160 |
return |
159 | 161 |
end |
160 |
profile = get_cache(:systems)[@pm[:systems][profile_id]]
|
|
162 |
profile = get_cache(:systems)[@pm[:hosts][profile_id]]
|
|
161 | 163 |
cv = get_cache(:content_views)[profile['content_view_id']] |
162 | 164 |
@composite_cvs << cv['id'] if cv['composite'] |
163 |
delete_entity_by_import_id(:systems, get_translated_id(:systems, profile_id), 'uuid')
|
|
165 |
delete_entity_by_import_id(:systems, get_translated_id(:hosts, profile_id), 'uuid')
|
|
164 | 166 |
end |
165 | 167 |
|
166 | 168 |
def post_delete(_file) |
lib/hammer_cli_import/persistentmap.rb | ||
---|---|---|
56 | 56 |
:content_views |
57 | 57 |
@definitions[:redhat_repositories] = [{'org_id' => Fixnum}, {'channel_id' => Fixnum}], ['sat6' => Fixnum], |
58 | 58 |
:repositories |
59 |
@definitions[:systems] = ['sat5' => Fixnum], ['sat6' => String], :systems
|
|
59 |
@definitions[:systems] = ['sat5' => Fixnum], ['sat6' => String], :hosts
|
|
60 | 60 |
@definitions[:template_snippets] = ['id' => Fixnum], ['sat6' => Fixnum], :config_templates |
61 | 61 |
|
62 | 62 |
@definitions.freeze |
Also available in: Unified diff
fixes #14615 - update api calls for hosts