hammer_cli_import 0.10.23 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hammer_cli_import/base.rb +37 -5
- data/lib/hammer_cli_import/configfile.rb +31 -16
- data/lib/hammer_cli_import/contenthost.rb +8 -6
- data/lib/hammer_cli_import/importtools.rb +4 -1
- data/lib/hammer_cli_import/persistentmap.rb +1 -1
- data/lib/hammer_cli_import/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c08a194170bc35a88e652f6daefef5f69847dbe0
|
4
|
+
data.tar.gz: b12ebf8a2bac1da4b3d948a41300470b390ece1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c620cd561928849d516dd8483fd59ef98f83460f0f1c5f870a834e46a9ce00d722b2583d5de7e6a2446382fb7614a0dfae1b250c38ef636d1fc17f8e47456d
|
7
|
+
data.tar.gz: 3cdf57fcb72980362f136d6eec0d9aa4d2c9afa0cfeb29c74b517e59139e403bce06957e24c8175983675859cf6dd889a9ff6d2e53ecef5004f14a14ae184092
|
@@ -75,6 +75,22 @@ module HammerCLIImport
|
|
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,13 +443,29 @@ module HammerCLIImport
|
|
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
|
-
|
431
|
-
|
432
|
-
|
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
|
+
unless entity_hash[:host_collection_ids].empty?
|
456
|
+
@api.resource(:host_collections).call(:add_hosts, {
|
457
|
+
'id' => entity_hash[:host_collection_ids][0],
|
458
|
+
'host_ids' => [entity['id']]
|
459
|
+
})
|
460
|
+
end
|
461
|
+
entity['id'] = entity['id'].to_s
|
462
|
+
else
|
463
|
+
entity_hash = {@wrap_out[entity_type] => entity_hash} if @wrap_out[entity_type]
|
464
|
+
debug "entity_hash: #{entity_hash.inspect}"
|
465
|
+
entity = mapped_api_call(entity_type, :create, entity_hash)
|
466
|
+
end
|
433
467
|
debug "created entity: #{entity.inspect}"
|
434
468
|
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
469
|
@pm[entity_type][original_id] = entity['id']
|
438
470
|
get_cache(entity_type)[entity['id']] = entity
|
439
471
|
debug "@pm[#{entity_type}]: #{@pm[entity_type].inspect}"
|
@@ -136,39 +136,52 @@ module HammerCLIImport
|
|
136
136
|
# inside of working-directory
|
137
137
|
def generate_module_template_for(name)
|
138
138
|
module_name = name
|
139
|
+
pwd = Dir.pwd
|
139
140
|
Dir.chdir(option_working_directory)
|
140
141
|
gen_cmd = "puppet module generate #{name}"
|
141
142
|
Open3.popen3(gen_cmd) do |stdin, stdout, _stderr|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
rd
|
147
|
-
|
143
|
+
begin
|
144
|
+
stdout.sync = true
|
145
|
+
ConfigFileImportCommand.interview_questions.each do |q|
|
146
|
+
rd = ''
|
147
|
+
until rd.include? '?'
|
148
|
+
rd = stdout.readline
|
149
|
+
debug "Read #{rd}"
|
150
|
+
end
|
151
|
+
answer = @interview_answers[q].gsub('#{module_name}', module_name)
|
152
|
+
stdin.puts(answer)
|
148
153
|
end
|
149
|
-
|
150
|
-
|
154
|
+
rescue EOFError => e
|
155
|
+
debug 'Done reading'
|
156
|
+
break
|
151
157
|
end
|
152
|
-
rd = ''
|
153
158
|
begin
|
159
|
+
rd = ''
|
154
160
|
rd = stdout.readline while rd
|
155
161
|
rescue EOFError
|
156
162
|
debug 'Done reading'
|
157
163
|
end
|
158
164
|
end
|
165
|
+
Dir.chdir(pwd)
|
159
166
|
|
160
167
|
# Now that we have generated the module, add a 'description' to the
|
161
168
|
# metadata.json file found at option_working_dir/<name>/metadata.json
|
162
169
|
metadata_path = File.join(File.join(option_working_directory, name), 'metadata.json')
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
if File.exist? metadata_path
|
171
|
+
answer = @interview_answers['description'].gsub('#{module_name}', module_name)
|
172
|
+
sed_cmd = "sed -i '\/\"summary\":\/a \\ \\ \"description\": \"#{answer}\",' #{metadata_path}"
|
173
|
+
debug "About to issue #{sed_cmd}"
|
174
|
+
system sed_cmd
|
175
|
+
report_summary :wrote, :puppet_modules
|
176
|
+
else
|
177
|
+
info "Failed puppet module #{name}: metadata.json not created"
|
178
|
+
report_summary :failed, :puppet_modules
|
179
|
+
end
|
168
180
|
end
|
169
181
|
|
170
182
|
def build_puppet_module(module_name)
|
171
183
|
module_dir = File.join(option_working_directory, module_name)
|
184
|
+
return nil unless File.exist? module_dir
|
172
185
|
Dir.chdir(module_dir)
|
173
186
|
gen_cmd = 'puppet module build'
|
174
187
|
Open3.popen3(gen_cmd) do |_stdin, stdout, _stderr|
|
@@ -284,10 +297,11 @@ module HammerCLIImport
|
|
284
297
|
def export_files
|
285
298
|
progress 'Writing converted files'
|
286
299
|
@modules.each do |mname, files|
|
300
|
+
module_dir = File.join(option_working_directory, mname)
|
301
|
+
next unless File.exist? module_dir
|
287
302
|
info "Found module #{mname}"
|
288
303
|
dsl = ''
|
289
304
|
|
290
|
-
module_dir = File.join(option_working_directory, mname)
|
291
305
|
fdir = File.join(module_dir, 'files')
|
292
306
|
Dir.mkdir(fdir)
|
293
307
|
tdir = File.join(module_dir, 'templates')
|
@@ -359,6 +373,7 @@ module HammerCLIImport
|
|
359
373
|
|
360
374
|
# Build the puppet-module for upload
|
361
375
|
module_dir = build_puppet_module(mname)
|
376
|
+
next if module_dir.nil?
|
362
377
|
|
363
378
|
# Build/find the product
|
364
379
|
product_hash = mk_product_hash(data, prod_name)
|
@@ -372,7 +387,7 @@ module HammerCLIImport
|
|
372
387
|
[data['org_id'].to_i, data['channel_id'].to_i])
|
373
388
|
|
374
389
|
# Find the built-module .tar.gz
|
375
|
-
built_module_path = File.join(
|
390
|
+
built_module_path = File.join('pkg',
|
376
391
|
"#{mname}-#{@interview_answers['version']}.tar.gz")
|
377
392
|
info "Uploading #{built_module_path}"
|
378
393
|
|
@@ -25,6 +25,7 @@ module HammerCLIImport
|
|
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,13 +58,14 @@ module HammerCLIImport
|
|
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
|
-
:
|
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 =>
|
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,7 +92,7 @@ module HammerCLIImport
|
|
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
|
-
:
|
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,10 +159,10 @@ module HammerCLIImport
|
|
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[:
|
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(:
|
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)
|
@@ -162,7 +162,10 @@ module ImportTools
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def create_composite_content_view(entity_type, org_id, cv_label, cv_description, cvs)
|
165
|
-
|
165
|
+
if cvs.empty?
|
166
|
+
return list_server_entities(:content_views,
|
167
|
+
{:organization_id => org_id, :name => "Default Organization View"})[0]['id']
|
168
|
+
end
|
166
169
|
if cvs.size == 1
|
167
170
|
return cvs.to_a[0]
|
168
171
|
else
|
@@ -56,7 +56,7 @@ module PersistentMap
|
|
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], :
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammer_cli_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@mkollar"
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hammer_cli
|
@@ -110,8 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.6
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Red Hat Satellite 5 data Importer commands for Hammer
|
117
117
|
test_files: []
|
118
|
+
has_rdoc:
|