hammer_cli_katello 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/hammer_cli_katello.rb +1 -0
- data/lib/hammer_cli_katello/activation_key.rb +7 -1
- data/lib/hammer_cli_katello/apipie_helper.rb +8 -0
- data/lib/hammer_cli_katello/content_view_purge.rb +10 -22
- data/lib/hammer_cli_katello/content_view_version.rb +56 -76
- data/lib/hammer_cli_katello/cv_import_export_helper.rb +83 -0
- data/lib/hammer_cli_katello/host_errata.rb +10 -0
- data/lib/hammer_cli_katello/lifecycle_environment.rb +2 -0
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/test/data/3.10/foreman_api.json +1 -0
- data/test/data/3.9/foreman_api.json +1 -1
- data/test/functional/apipie_helper_test.rb +5 -0
- data/test/functional/content_view/purge_test.rb +50 -25
- data/test/functional/content_view/version/export_test.rb +54 -2
- data/test/functional/content_view/version/import_test.rb +111 -0
- data/test/functional/host/errata/recalculate_test.rb +42 -0
- data/test/test_helper.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5a0c1942a467a8de0c6ed9e0ea81e682488d7885bfe49f2921e9a2a6fd7e99f
|
4
|
+
data.tar.gz: c92458aa1299e5c707323fd9ad96422149400f676002fdd6497e2f171799caef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0044948e47d6ada111b0cabb37a925d754b1b4b2e1b38519804886a1c6ebd593a847b429916c2c780efb86d95f4a653399738142b27117c8ce40d4abc20ea33d'
|
7
|
+
data.tar.gz: 3c363f5ddeba819dfc7b4fc3d531583b5c8c5f12d151147e3bd2addc65cd4fbf31b065c4bb6971a824c362092d1cbd79ee1588e1c717b2f5461d0b86f5708558
|
data/lib/hammer_cli_katello.rb
CHANGED
@@ -29,6 +29,7 @@ module HammerCLIKatello
|
|
29
29
|
require 'hammer_cli_katello/id_name_options_validator'
|
30
30
|
require 'hammer_cli_katello/local_helper'
|
31
31
|
require 'hammer_cli_katello/apipie_helper'
|
32
|
+
require 'hammer_cli_katello/cv_import_export_helper'
|
32
33
|
|
33
34
|
# commands
|
34
35
|
HammerCLI::MainCommand.lazy_subcommand("activation-key", _("Manipulate activation keys"),
|
@@ -146,7 +146,7 @@ module HammerCLIKatello
|
|
146
146
|
field :id, _("ID")
|
147
147
|
field :product_name, _("Name")
|
148
148
|
field :format_consumed, _("Attached")
|
149
|
-
field :
|
149
|
+
field :quantity_attached, _("Quantity")
|
150
150
|
field :start_date, _("Start Date"), Fields::Date
|
151
151
|
field :end_date, _("End Date"), Fields::Date
|
152
152
|
field :support_level, _("Support")
|
@@ -154,6 +154,12 @@ module HammerCLIKatello
|
|
154
154
|
field :account_number, _("Account")
|
155
155
|
end
|
156
156
|
|
157
|
+
def extend_data(data)
|
158
|
+
data["format_consumed"] = _("#{data['consumed']} out of "\
|
159
|
+
"#{data['quantity'] == -1 ? 'Unlimited' : data['quantity']}")
|
160
|
+
data
|
161
|
+
end
|
162
|
+
|
157
163
|
option '--id', "ACTIVATION_KEY_ID", _("ID of the activation key"),
|
158
164
|
attribute_name: :option_activation_key_id
|
159
165
|
option '--name', "ACTIVATION_KEY_NAME", _("Activation key name to search by"),
|
@@ -8,6 +8,14 @@ module HammerCLIKatello
|
|
8
8
|
call(:index, resource, options)['results']
|
9
9
|
end
|
10
10
|
|
11
|
+
def update(resource, options = {})
|
12
|
+
call(:update, resource, options)['results']
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy(resource, options = {})
|
16
|
+
call(:destroy, resource, options)
|
17
|
+
end
|
18
|
+
|
11
19
|
def call(action, resource, options = {})
|
12
20
|
HammerCLIForeman.foreman_resource(resource).call(action, options)
|
13
21
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module HammerCLIKatello
|
2
2
|
class ContentViewPurgeCommand < HammerCLIKatello::Command
|
3
3
|
include HammerCLIForemanTasks::Async
|
4
|
+
include HammerCLIKatello::ApipieHelper
|
4
5
|
include OrganizationOptions
|
5
6
|
|
6
7
|
command_name "purge"
|
@@ -24,14 +25,6 @@ module HammerCLIKatello
|
|
24
25
|
|
25
26
|
build_options
|
26
27
|
|
27
|
-
def resource_content_views
|
28
|
-
HammerCLIForeman.foreman_resource(:content_views)
|
29
|
-
end
|
30
|
-
|
31
|
-
def resource_content_view_versions
|
32
|
-
HammerCLIForeman.foreman_resource(:content_view_versions)
|
33
|
-
end
|
34
|
-
|
35
28
|
class ContentViewIdParamSource
|
36
29
|
def initialize(command)
|
37
30
|
@command = command
|
@@ -74,31 +67,26 @@ module HammerCLIKatello
|
|
74
67
|
|
75
68
|
private def purge_version(v)
|
76
69
|
if option_async?
|
77
|
-
task =
|
70
|
+
task = destroy(:content_view_versions, 'id' => v["id"])
|
78
71
|
print_message _("Version '%{version}' of content view '%{view}' scheduled "\
|
79
72
|
"for deletion in task '%{task_id}'.") %
|
80
|
-
{version: v["version"], view: content_view["name"], task_id: task['id']}
|
73
|
+
{version: v["version"], view: v["content_view"]["name"], task_id: task['id']}
|
81
74
|
else
|
82
|
-
task_progress(
|
75
|
+
task_progress(call(:destroy, :content_view_versions, 'id' => v["id"]))
|
83
76
|
print_message _("Version '%{version}' of content view '%{view}' deleted.") %
|
84
|
-
{version: v["version"], view: content_view["name"]}
|
77
|
+
{version: v["version"], view: v["content_view"]["name"]}
|
85
78
|
end
|
86
79
|
end
|
87
80
|
|
88
|
-
private def content_view
|
89
|
-
@content_view ||= resource_content_views.call(:show, 'id' => options['option_id'])
|
90
|
-
end
|
91
|
-
|
92
81
|
private def old_unused_versions
|
93
82
|
return @old_unused_versions if @old_unused_versions
|
94
83
|
|
95
|
-
all_versions =
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
# Keep only versions which are not used
|
84
|
+
all_versions = index(:content_view_versions, :content_view_id => options['option_id'])
|
85
|
+
all_versions.sort_by! { |v| [v['major'], v['minor']] }
|
100
86
|
@old_unused_versions = all_versions.select do |v|
|
101
|
-
v["
|
87
|
+
v["environments"].empty? &&
|
88
|
+
v["composite_content_views"].empty? &&
|
89
|
+
v["composite_content_view_versions"].empty?
|
102
90
|
end
|
103
91
|
end
|
104
92
|
end
|
@@ -265,6 +265,7 @@ module HammerCLIKatello
|
|
265
265
|
class ExportCommand < HammerCLIForeman::Command
|
266
266
|
include HammerCLIKatello::LocalHelper
|
267
267
|
include HammerCLIKatello::ApipieHelper
|
268
|
+
include HammerCLIKatello::CVImportExportHelper
|
268
269
|
|
269
270
|
PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
|
270
271
|
|
@@ -287,18 +288,29 @@ module HammerCLIKatello
|
|
287
288
|
|
288
289
|
def execute
|
289
290
|
cvv = show(:content_view_versions, 'id' => options['option_id'])
|
290
|
-
|
291
|
-
show(:repositories, 'id' => repo['id'], :full_result => true)
|
292
|
-
end
|
291
|
+
cv = show(:content_views, 'id' => cvv['content_view_id'])
|
293
292
|
|
294
|
-
|
293
|
+
composite = cv["composite"]
|
294
|
+
export_json_options = { :cvv => cvv }
|
295
295
|
|
296
|
-
|
297
|
-
|
298
|
-
|
296
|
+
if composite
|
297
|
+
components = cv['components']
|
298
|
+
export_json_options[:component_cvvs] = components.collect do |component|
|
299
|
+
component['name']
|
300
|
+
end
|
301
|
+
export_json_options[:repositories] = []
|
302
|
+
else
|
303
|
+
repositories = fetch_cvv_repositories(cvv)
|
304
|
+
check_repo_download_policy(repositories)
|
305
|
+
|
306
|
+
repositories.each do |repo|
|
307
|
+
repo['packages'] = index(:packages, 'repository_id' => repo['id'], :full_result => true)
|
308
|
+
repo['errata'] = index(:errata, 'repository_id' => repo['id'], :full_result => true)
|
309
|
+
end
|
310
|
+
export_json_options[:repositories] = repositories
|
299
311
|
end
|
300
312
|
|
301
|
-
json = export_json(
|
313
|
+
json = export_json(export_json_options)
|
302
314
|
create_tar(cvv, repositories, json)
|
303
315
|
return HammerCLI::EX_OK
|
304
316
|
end
|
@@ -311,15 +323,17 @@ module HammerCLIKatello
|
|
311
323
|
|
312
324
|
Dir.mkdir("#{options['option_export_dir']}/#{export_prefix}")
|
313
325
|
|
314
|
-
|
315
|
-
|
316
|
-
|
326
|
+
if repositories
|
327
|
+
Dir.chdir(PUBLISHED_REPOS_DIR) do
|
328
|
+
repo_tar = "#{options['option_export_dir']}/#{export_prefix}/#{export_repos_tar}"
|
329
|
+
repo_dirs = []
|
317
330
|
|
318
|
-
|
319
|
-
|
320
|
-
|
331
|
+
repositories.each do |repo|
|
332
|
+
repo_dirs.push(repo['relative_path'])
|
333
|
+
end
|
321
334
|
|
322
|
-
|
335
|
+
`tar cvfh #{repo_tar} #{repo_dirs.join(" ")}`
|
336
|
+
end
|
323
337
|
end
|
324
338
|
|
325
339
|
Dir.chdir("#{options['option_export_dir']}/#{export_prefix}") do
|
@@ -348,35 +362,13 @@ module HammerCLIKatello
|
|
348
362
|
MSG
|
349
363
|
raise _(msg)
|
350
364
|
end
|
351
|
-
|
352
|
-
def export_json(content_view_version, repositories)
|
353
|
-
json = {
|
354
|
-
"name" => content_view_version['content_view']['name'],
|
355
|
-
"major" => content_view_version['major'],
|
356
|
-
"minor" => content_view_version['minor']
|
357
|
-
}
|
358
|
-
|
359
|
-
json["repositories"] = repositories.collect do |repo|
|
360
|
-
{
|
361
|
-
"id" => repo['id'],
|
362
|
-
"label" => repo['label'],
|
363
|
-
"content_type" => repo['content_type'],
|
364
|
-
"backend_identifier" => repo['backend_identifier'],
|
365
|
-
"relative_path" => repo['relative_path'],
|
366
|
-
"on_disk_path" => "#{PUBLISHED_REPOS_DIR}/#{repo['relative_path']}",
|
367
|
-
"rpm_filenames" => repo['packages'].collect { |package| package['filename'] },
|
368
|
-
"errata_ids" => repo['errata'].collect { |errata| errata['errata_id'] }
|
369
|
-
}
|
370
|
-
end
|
371
|
-
|
372
|
-
json
|
373
|
-
end
|
374
365
|
end
|
375
366
|
|
376
367
|
class ImportCommand < HammerCLIForeman::Command
|
377
368
|
include HammerCLIForemanTasks::Async
|
378
369
|
include HammerCLIKatello::LocalHelper
|
379
370
|
include HammerCLIKatello::ApipieHelper
|
371
|
+
include HammerCLIKatello::CVImportExportHelper
|
380
372
|
|
381
373
|
attr_accessor :export_tar_dir, :export_tar_file, :export_tar_prefix
|
382
374
|
|
@@ -389,8 +381,7 @@ module HammerCLIKatello
|
|
389
381
|
|
390
382
|
option "--organization-id", "ORGANIZATION_ID", _("Organization numeric identifier")
|
391
383
|
option(
|
392
|
-
'--export-tar',
|
393
|
-
'EXPORT_TAR',
|
384
|
+
'--export-tar', 'EXPORT_TAR',
|
394
385
|
_("Location of export tar on disk")
|
395
386
|
)
|
396
387
|
|
@@ -406,47 +397,35 @@ module HammerCLIKatello
|
|
406
397
|
raise _("Export tar #{options['option_export_tar']} does not exist.")
|
407
398
|
end
|
408
399
|
|
409
|
-
|
410
|
-
|
411
|
-
self.export_tar_dir = File.dirname(options['option_export_tar'])
|
412
|
-
untar_export
|
413
|
-
|
414
|
-
export_json = read_json
|
400
|
+
import_tar_params = obtain_export_params(options['option_export_tar'])
|
401
|
+
untar_export(import_tar_params)
|
415
402
|
|
403
|
+
export_json = read_json(import_tar_params)
|
416
404
|
cv = content_view(export_json['name'], options['option_organization_id'])
|
417
|
-
sync_repositories(export_json['repositories'], options['option_organization_id'])
|
418
|
-
|
419
|
-
publish(
|
420
|
-
cv['id'],
|
421
|
-
export_json['major'],
|
422
|
-
export_json['minor'],
|
423
|
-
repos_units(export_json['repositories'])
|
424
|
-
)
|
425
|
-
return HammerCLI::EX_OK
|
426
|
-
end
|
427
|
-
|
428
|
-
def untar_export
|
429
|
-
Dir.chdir(@export_tar_dir) do
|
430
|
-
`tar -xf #{@export_tar_file}`
|
431
|
-
end
|
432
405
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
else
|
437
|
-
raise _("Export repos tar file is missing.")
|
406
|
+
if export_json['composite_components']
|
407
|
+
composite_version_ids = export_json['composite_components'].map do |component|
|
408
|
+
find_local_component_id(component)
|
438
409
|
end
|
410
|
+
|
411
|
+
update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids)
|
412
|
+
publish(cv['id'], export_json['major'], export_json['minor'])
|
413
|
+
else
|
414
|
+
sync_repositories(export_json['repositories'], options['option_organization_id'],
|
415
|
+
import_tar_params)
|
416
|
+
|
417
|
+
publish(
|
418
|
+
cv['id'], export_json['major'],
|
419
|
+
export_json['minor'], repos_units(export_json['repositories'])
|
420
|
+
)
|
439
421
|
end
|
422
|
+
return HammerCLI::EX_OK
|
440
423
|
end
|
441
424
|
|
442
|
-
def
|
443
|
-
|
444
|
-
|
445
|
-
json_file = File.read(json_file)
|
446
|
-
JSON.parse(json_file)
|
447
|
-
end
|
425
|
+
def sync_repositories(repositories, organization_id, options)
|
426
|
+
export_tar_dir = options[:dirname]
|
427
|
+
export_tar_prefix = options[:prefix]
|
448
428
|
|
449
|
-
def sync_repositories(repositories, organization_id)
|
450
429
|
repositories.each do |repo|
|
451
430
|
library_repos = index(
|
452
431
|
:repositories,
|
@@ -467,7 +446,7 @@ module HammerCLIKatello
|
|
467
446
|
|
468
447
|
synchronize(
|
469
448
|
library_repo['id'],
|
470
|
-
"file://#{
|
449
|
+
"file://#{export_tar_dir}/#{export_tar_prefix}/#{repo['relative_path']}"
|
471
450
|
)
|
472
451
|
end
|
473
452
|
end
|
@@ -489,8 +468,9 @@ module HammerCLIKatello
|
|
489
468
|
task_progress(call(:sync, :repositories, 'id' => id, 'source_url' => source_url))
|
490
469
|
end
|
491
470
|
|
492
|
-
def publish(id, major, minor, repos_units)
|
493
|
-
params = {'id' => id, 'major' => major, 'minor' => minor
|
471
|
+
def publish(id, major, minor, repos_units = nil)
|
472
|
+
params = {'id' => id, 'major' => major, 'minor' => minor }
|
473
|
+
params['repos_units'] = repos_units if repos_units
|
494
474
|
task_progress(call(:publish, :content_views, params))
|
495
475
|
end
|
496
476
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module HammerCLIKatello
|
2
|
+
module CVImportExportHelper
|
3
|
+
PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
|
4
|
+
|
5
|
+
def fetch_cvv_repositories(cvv)
|
6
|
+
cvv['repositories'].collect do |repo|
|
7
|
+
show(:repositories, 'id' => repo['id'], :full_result => true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_local_component_id(component_from_export)
|
12
|
+
*name, version = component_from_export.split(' ')
|
13
|
+
name = name.join(' ')
|
14
|
+
existing_component_cv = content_view(name, options['option_organization_id'])
|
15
|
+
found_composite_version = existing_component_cv['versions'].select do |v|
|
16
|
+
v['version'] == version
|
17
|
+
end
|
18
|
+
if found_composite_version.empty?
|
19
|
+
raise _("Unable to find CV version %{cvv} on system. Please ensure it " \
|
20
|
+
"is already imported." % {'cvv' => component_from_export})
|
21
|
+
end
|
22
|
+
found_composite_version.first['id']
|
23
|
+
end
|
24
|
+
|
25
|
+
def untar_export(options)
|
26
|
+
export_tar_file = options[:filename]
|
27
|
+
export_tar_dir = options[:dirname]
|
28
|
+
export_tar_prefix = options[:prefix]
|
29
|
+
|
30
|
+
Dir.chdir(export_tar_dir) do
|
31
|
+
`tar -xf #{export_tar_file}`
|
32
|
+
end
|
33
|
+
|
34
|
+
Dir.chdir("#{export_tar_dir}/#{export_tar_prefix}") do
|
35
|
+
if File.exist?(export_tar_file.gsub('.tar', '-repos.tar'))
|
36
|
+
`tar -xf #{export_tar_file.gsub('.tar', '-repos.tar')}`
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def obtain_export_params(option_export_tar)
|
42
|
+
export_tar_file = File.basename(option_export_tar)
|
43
|
+
{:filename => export_tar_file,
|
44
|
+
:dirname => File.dirname(option_export_tar),
|
45
|
+
:prefix => export_tar_file.gsub('.tar', '')}
|
46
|
+
end
|
47
|
+
|
48
|
+
def read_json(options)
|
49
|
+
export_tar_file = options[:filename]
|
50
|
+
export_tar_dir = options[:dirname]
|
51
|
+
export_tar_prefix = options[:prefix]
|
52
|
+
|
53
|
+
json_file = export_tar_file.gsub('tar', 'json')
|
54
|
+
json_file = "#{export_tar_dir}/#{export_tar_prefix}/#{json_file}"
|
55
|
+
json_file = File.read(json_file)
|
56
|
+
JSON.parse(json_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def export_json(export_json_options)
|
60
|
+
content_view_version = export_json_options[:cvv]
|
61
|
+
repositories = export_json_options[:repositories]
|
62
|
+
json = {
|
63
|
+
"name" => content_view_version['content_view']['name'],
|
64
|
+
"major" => content_view_version['major'],
|
65
|
+
"minor" => content_view_version['minor']
|
66
|
+
}
|
67
|
+
json["composite_components"] = export_json_options[:component_cvvs]
|
68
|
+
json["repositories"] = repositories.collect do |repo|
|
69
|
+
{
|
70
|
+
"id" => repo['id'],
|
71
|
+
"label" => repo['label'],
|
72
|
+
"content_type" => repo['content_type'],
|
73
|
+
"backend_identifier" => repo['backend_identifier'],
|
74
|
+
"relative_path" => repo['relative_path'],
|
75
|
+
"on_disk_path" => "#{PUBLISHED_REPOS_DIR}/#{repo['relative_path']}",
|
76
|
+
"rpm_filenames" => repo['packages'].collect { |package| package['filename'] },
|
77
|
+
"errata_ids" => repo['errata'].collect { |errata| errata['errata_id'] }
|
78
|
+
}
|
79
|
+
end
|
80
|
+
json
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -49,6 +49,16 @@ module HammerCLIKatello
|
|
49
49
|
build_options
|
50
50
|
end
|
51
51
|
|
52
|
+
class RecalculateCommand < HammerCLIKatello::SingleResourceCommand
|
53
|
+
include HammerCLIForemanTasks::Async
|
54
|
+
resource :host_errata, :applicability
|
55
|
+
command_name "recalculate"
|
56
|
+
success_message _("Errata recalculated with task %{id}.")
|
57
|
+
failure_message _("Could not recalculate errata")
|
58
|
+
|
59
|
+
build_options
|
60
|
+
end
|
61
|
+
|
52
62
|
autoload_subcommands
|
53
63
|
end
|
54
64
|
end
|