hammer_cli_katello 1.0.1 → 1.2.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +5 -1
  3. data/lib/hammer_cli_katello/content_import.rb +16 -1
  4. data/lib/hammer_cli_katello/content_view_version.rb +0 -273
  5. data/lib/hammer_cli_katello/docker.rb +13 -0
  6. data/lib/hammer_cli_katello/docker_manifest.rb +53 -0
  7. data/lib/hammer_cli_katello/docker_tag.rb +40 -0
  8. data/lib/hammer_cli_katello/host_collection.rb +6 -0
  9. data/lib/hammer_cli_katello/host_collection_erratum.rb +10 -0
  10. data/lib/hammer_cli_katello/host_collection_package.rb +30 -0
  11. data/lib/hammer_cli_katello/host_collection_package_group.rb +30 -0
  12. data/lib/hammer_cli_katello/host_errata.rb +9 -1
  13. data/lib/hammer_cli_katello/host_package.rb +32 -0
  14. data/lib/hammer_cli_katello/host_package_group.rb +16 -0
  15. data/lib/hammer_cli_katello/id_resolver.rb +3 -1
  16. data/lib/hammer_cli_katello/organization.rb +10 -0
  17. data/lib/hammer_cli_katello/ping.rb +13 -5
  18. data/lib/hammer_cli_katello/repository.rb +21 -27
  19. data/lib/hammer_cli_katello/simple_content_access.rb +2 -0
  20. data/lib/hammer_cli_katello/version.rb +1 -1
  21. data/locale/hammer-cli-katello.pot +0 -25
  22. data/test/data/4.0/foreman_api.json +1 -1
  23. data/test/data/4.1/foreman_api.json +1 -0
  24. data/test/functional/activation_key/subscriptions_test.rb +5 -2
  25. data/test/functional/content_export/complete/version_test.rb +35 -0
  26. data/test/functional/content_import/list_test.rb +65 -0
  27. data/test/functional/content_import/version_test.rb +6 -6
  28. data/test/functional/host_collection/create_test.rb +11 -0
  29. data/test/functional/organization/info_test.rb +22 -0
  30. data/test/functional/ping_test.rb +52 -13
  31. data/test/test_helper.rb +1 -1
  32. metadata +15 -45
  33. data/lib/hammer_cli_katello/cv_import_export_helper.rb +0 -187
  34. data/test/functional/content_view/version/cv_import_export_helper_test.rb +0 -20
  35. data/test/functional/content_view/version/default_export_test.rb +0 -40
  36. data/test/functional/content_view/version/export_test.rb +0 -148
  37. data/test/functional/content_view/version/import_test.rb +0 -346
  38. data/test/functional/repository/export_test.rb +0 -121
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 186183bd2337627828ad27578924b491161632034de3f51b2896a02312b68519
4
- data.tar.gz: 903b7f9c68fdfcd7538739a1f98aa896e18924806f69d37576a85f935315f7e1
3
+ metadata.gz: 2ec840ea7e9516ce7268b7d2ddce6bebce2a4b4a71ac4963c475fc472a6e5dab
4
+ data.tar.gz: 2388188ed12e64cc36d20192ccd1d70c2e53547efef35a5f40b02d1a190fcb77
5
5
  SHA512:
6
- metadata.gz: ae67f54e90820899048b453b5c6592d0e7ac36ee562d798c74c82365c82de577c158640259eeb222cfb9e5f8ab5e880fd1ce36dcba56eed3f67dadaf2430eef7
7
- data.tar.gz: aae484692b57eb9405e01b2b2f6e01b8254e7903b53fdbe919e829366e0f28ab46e5184e61111fa637655d029cd000197639a1e5919cc5bc59c041ad93108eb0
6
+ metadata.gz: 190ede71c0bb873d5ded32b884de84137da2a367d987f055505fcfde3995a3419fd1e5c919630569b18266bba2efd5c5a496b471803de659f63dd547299c67e1
7
+ data.tar.gz: 3f96f683fb9a0ab6f0f92c6451aa528dd6929c6a16172dd1a4dfbfc63c7dcb6f1d7b2b0f49dc1fff72f039a08aaa5374d31d122a7222e053d985c78755f44e97
@@ -30,7 +30,6 @@ module HammerCLIKatello
30
30
  require 'hammer_cli_katello/id_name_options_validator'
31
31
  require 'hammer_cli_katello/local_helper'
32
32
  require 'hammer_cli_katello/apipie_helper'
33
- require 'hammer_cli_katello/cv_import_export_helper'
34
33
  require 'hammer_cli_katello/content_export_helper'
35
34
 
36
35
  # commands
@@ -156,6 +155,11 @@ module HammerCLIKatello
156
155
  'hammer_cli_katello/simple_content_access'
157
156
  )
158
157
 
158
+ HammerCLI::MainCommand.lazy_subcommand("docker", _("Manipulate docker content"),
159
+ 'HammerCLIKatello::DockerCommand',
160
+ 'hammer_cli_katello/docker'
161
+ )
162
+
159
163
  # subcommands to hammer_cli_foreman commands
160
164
  require 'hammer_cli_katello/host'
161
165
  require 'hammer_cli_katello/hostgroup'
@@ -13,7 +13,7 @@ module HammerCLIKatello
13
13
  :required => false
14
14
 
15
15
  base.build_options do |o|
16
- o.expand(:all).including(:content_views, :organizations).except(:metadata)
16
+ o.expand(:all).including(:organizations).except(:metadata)
17
17
  end
18
18
 
19
19
  base.validate_options do
@@ -58,6 +58,21 @@ module HammerCLIKatello
58
58
  include ContentImportCommon
59
59
  end
60
60
 
61
+ class ListCommand < HammerCLIKatello::ListCommand
62
+ desc "View content view import histories"
63
+ output do
64
+ field :id, _('ID')
65
+ field :path, _('Path')
66
+ field :type, _('Type')
67
+ field :content_view_version, _('Content View Version')
68
+ field :content_view_version_id, _('Content View Version ID')
69
+ field :created_at, _('Created at')
70
+ field :updated_at, _('Updated at'), Fields::Field, :hide_blank => true
71
+ end
72
+
73
+ build_options
74
+ end
75
+
61
76
  autoload_subcommands
62
77
  end
63
78
  end
@@ -271,279 +271,6 @@ module HammerCLIKatello
271
271
  end
272
272
  end
273
273
 
274
- class ExportDefaultCommand < HammerCLIForeman::Command
275
- include HammerCLIKatello::LocalHelper
276
- include HammerCLIKatello::ApipieHelper
277
- include HammerCLIKatello::CVImportExportHelper
278
-
279
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
280
-
281
- desc _('Export the library default content view')
282
-
283
- command_name "export-default"
284
-
285
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
286
-
287
- validate_options do
288
- option(:option_export_dir).required
289
- end
290
-
291
- build_options
292
-
293
- def execute
294
- validate_pulp3_not_enabled(fail_msg_export)
295
- export_dir = options['option_export_dir']
296
-
297
- Dir.mkdir(export_dir) unless Dir.exist?(export_dir)
298
- result = Kernel.system("rsync -aL #{PUBLISHED_REPOS_DIR} #{export_dir}")
299
- if result == true
300
- output.print_message _("Default content view export is available at #{export_dir}")
301
- HammerCLI::EX_OK
302
- else
303
- output.print_error _("Could not export the default content view at #{export_dir}")
304
- HammerCLI::EX_CANTCREAT
305
- end
306
- end
307
- end
308
-
309
- class LegacyExportCommand < HammerCLIKatello::SingleResourceCommand
310
- include HammerCLIForemanTasks::Async
311
- include LifecycleEnvironmentNameMapping
312
- include HammerCLIKatello::CVImportExportHelper
313
- desc _('Export a content view (legacy method)')
314
-
315
- action :export
316
- command_name "export-legacy"
317
-
318
- success_message _("Content view is being exported in task %{id}.")
319
- failure_message _("Could not export the content view")
320
- build_options do |o|
321
- o.expand(:all).including(:environments, :content_views, :organizations)
322
- end
323
-
324
- extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
325
-
326
- def request_params
327
- validate_pulp3_not_enabled(fail_msg_export)
328
- super
329
- end
330
- end
331
-
332
- class ExportCommand < HammerCLIForeman::Command
333
- include HammerCLIKatello::LocalHelper
334
- include HammerCLIKatello::ApipieHelper
335
- include HammerCLIKatello::CVImportExportHelper
336
-
337
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
338
-
339
- desc _('Export a content view version')
340
-
341
- command_name "export"
342
-
343
- success_message _("Content view export is available in %{directory}.")
344
- failure_message _("Could not export the content view")
345
-
346
- option "--id", "ID", _("Content View Version numeric identifier")
347
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
348
-
349
- validate_options do
350
- option(:option_export_dir).required
351
- option(:option_id).required
352
- end
353
-
354
- build_options
355
-
356
- def execute
357
- cvv = show(:content_view_versions, 'id' => options['option_id'])
358
- cv = show(:content_views, 'id' => cvv['content_view_id'])
359
-
360
- validate_pulp3_not_enabled(fail_msg_export)
361
-
362
- composite = cv["composite"]
363
-
364
- export_json_options = { :cvv => cvv }
365
-
366
- if composite
367
- components = cv['components']
368
- export_json_options[:component_cvvs] = components.collect do |component|
369
- component['name']
370
- end
371
- export_json_options[:repositories] = []
372
- else
373
- repositories = fetch_exportable_cvv_repositories(cvv)
374
- collect_packages(repositories)
375
-
376
- export_json_options[:repositories] = repositories
377
- end
378
-
379
- json = export_json(export_json_options)
380
- if repositories&.any? || cv['composite']
381
- create_tar(cv, cvv, repositories, json)
382
- else
383
- msg = <<~MSG
384
- Ensure the content view version '#{cvv['name']}' has at least one repository.
385
- MSG
386
- raise _(msg)
387
- end
388
- return HammerCLI::EX_OK
389
- end
390
-
391
- def create_tar(cv, cvv, repositories, json)
392
- export_prefix = "export-#{cv['label']}-#{cvv['major']}.#{cvv['minor']}"
393
- export_file = "#{export_prefix}.json"
394
- export_repos_tar = "#{export_prefix}-repos.tar"
395
- export_tar = "#{export_prefix}.tar"
396
- export_dir = File.expand_path(options['option_export_dir'].to_s)
397
-
398
- Dir.mkdir("#{export_dir}/#{export_prefix}")
399
-
400
- if repositories&.any?
401
-
402
- Dir.chdir(PUBLISHED_REPOS_DIR) do
403
- repo_tar = "#{export_dir}/#{export_prefix}/#{export_repos_tar}"
404
- repo_dirs = []
405
-
406
- repositories.each do |repo|
407
- repo_dirs.push(repo['relative_path'])
408
- end
409
-
410
- `tar cvfh #{repo_tar} #{repo_dirs.join(" ")}`
411
- end
412
- end
413
-
414
- Dir.chdir("#{export_dir}/#{export_prefix}") do
415
- File.open(export_file, 'w') do |file|
416
- file.write(JSON.pretty_generate(json))
417
- end
418
- end
419
-
420
- Dir.chdir(export_dir) do
421
- `tar cf #{export_tar} #{export_prefix}`
422
- FileUtils.rm_rf(export_prefix)
423
- end
424
- end
425
- end
426
-
427
- class ImportCommand < HammerCLIForeman::Command
428
- include HammerCLIForemanTasks::Async
429
- include HammerCLIKatello::LocalHelper
430
- include HammerCLIKatello::ApipieHelper
431
- include HammerCLIKatello::CVImportExportHelper
432
-
433
- attr_accessor :export_tar_dir, :export_tar_file, :export_tar_prefix
434
-
435
- desc _('Import a content view version')
436
-
437
- command_name "import"
438
-
439
- success_message _("Content view imported.")
440
- failure_message _("Could not import the content view")
441
-
442
- option "--organization-id", "ORGANIZATION_ID", _("Organization numeric identifier")
443
- option(
444
- '--export-tar', 'EXPORT_TAR',
445
- _("Location of export tar on disk")
446
- )
447
-
448
- validate_options do
449
- option(:option_export_tar).required
450
- option(:option_organization_id).required
451
- end
452
-
453
- build_options
454
-
455
- # rubocop:disable Metrics/AbcSize
456
- def execute
457
- validate_pulp3_not_enabled(fail_msg_import)
458
-
459
- unless File.exist?(options['option_export_tar'])
460
- raise _("Export tar #{options['option_export_tar']} does not exist.")
461
- end
462
-
463
- import_tar_params = obtain_export_params(options['option_export_tar'])
464
- untar_export(import_tar_params)
465
-
466
- export_json = read_json(import_tar_params)
467
- cv = content_view(export_json['name'], options['option_organization_id'])
468
- major = export_json['major'].to_s
469
- minor = export_json['minor'].to_s
470
- import_checks(export_json, cv, major, minor)
471
-
472
- if export_json['composite_components']
473
- composite_version_ids = export_json['composite_components'].map do |component|
474
- find_local_component_id(component)
475
- end
476
- update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids)
477
- publish(cv['id'], export_json['major'], export_json['minor'])
478
- else
479
- sync_repositories(export_json['repositories'], options['option_organization_id'],
480
- import_tar_params)
481
-
482
- unless cv['default']
483
- publish(
484
- cv['id'], export_json['major'],
485
- export_json['minor'], repos_units(export_json['repositories'])
486
- )
487
- end
488
- end
489
- return HammerCLI::EX_OK
490
- end
491
- # rubocop:enable Metrics/AbcSize
492
-
493
- def sync_repositories(repositories, organization_id, options)
494
- export_tar_dir = options[:dirname]
495
- export_tar_prefix = options[:prefix]
496
-
497
- repositories.each do |repo|
498
- library_repos = index(
499
- :repositories,
500
- 'organization_id' => organization_id,
501
- 'library' => true,
502
- 'label' => repo['label']
503
- )
504
-
505
- library_repo = library_repos.select do |candidate_repo|
506
- candidate_repo['label'] == repo['label']
507
- end
508
-
509
- library_repo = library_repo.first
510
-
511
- if library_repo.nil?
512
- msg = _("Unable to sync repositories, no library repository found for %s")
513
- raise msg % repo['label']
514
- end
515
-
516
- synchronize(
517
- library_repo['id'],
518
- "file://#{export_tar_dir}/#{export_tar_prefix}/#{repo['relative_path']}"
519
- )
520
- end
521
- end
522
-
523
- def repos_units(repositories)
524
- repositories.collect do |repo|
525
- {
526
- 'label' => repo['label'],
527
- 'rpm_filenames' => repo['rpm_filenames']
528
- }
529
- end
530
- end
531
-
532
- def content_view(name, organization_id)
533
- index(:content_views, 'name' => name, 'organization_id' => organization_id).first
534
- end
535
-
536
- def synchronize(id, source_url)
537
- task_progress(call(:sync, :repositories, 'id' => id, 'source_url' => source_url))
538
- end
539
-
540
- def publish(id, major, minor, repos_units = nil)
541
- params = {'id' => id, 'major' => major, 'minor' => minor }
542
- params['repos_units'] = repos_units if repos_units
543
- task_progress(call(:publish, :content_views, params))
544
- end
545
- end
546
-
547
274
  autoload_subcommands
548
275
  end
549
276
  end
@@ -0,0 +1,13 @@
1
+ module HammerCLIKatello
2
+ class DockerCommand < HammerCLI::AbstractCommand
3
+ require 'hammer_cli_katello/docker_manifest'
4
+ subcommand 'manifest',
5
+ HammerCLIKatello::DockerManifestCommand.desc,
6
+ HammerCLIKatello::DockerManifestCommand
7
+
8
+ require 'hammer_cli_katello/docker_tag'
9
+ subcommand 'tag',
10
+ HammerCLIKatello::DockerTagCommand.desc,
11
+ HammerCLIKatello::DockerTagCommand
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ module HammerCLIKatello
2
+ class DockerManifestCommand < HammerCLIForeman::Command
3
+ resource :docker_manifests
4
+ command_name 'manifest'
5
+ desc _('Manage docker manifests')
6
+
7
+ class ListCommand < HammerCLIKatello::ListCommand
8
+ include HammerCLIKatello::LifecycleEnvironmentNameMapping
9
+
10
+ output do
11
+ field :id, _("ID")
12
+ field :name, _("Name")
13
+ field :schema_version, _("Schema Version")
14
+ field :digest, _("Digest")
15
+ field :downloaded, _("Downloaded"), Fields::Boolean
16
+ field :_tags, _("Tags")
17
+ end
18
+
19
+ def extend_data(manifest)
20
+ manifest['_tags'] = manifest['tags'].map { |e| e["name"] }.join(", ")
21
+ manifest
22
+ end
23
+
24
+ build_options do |o|
25
+ o.expand.including(:products, :organizations, :content_views)
26
+ end
27
+
28
+ extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
29
+ end
30
+
31
+ class InfoCommand < HammerCLIKatello::InfoCommand
32
+ output do
33
+ field :id, _("ID")
34
+ field :name, _("Name")
35
+ field :schema_version, _("Schema Version")
36
+ field :digest, _("Digest")
37
+ field :downloaded, _("Downloaded"), Fields::Boolean
38
+ collection :tags, _("Tags") do
39
+ field :name, _("Name")
40
+ end
41
+ end
42
+
43
+ def extend_data(manifest)
44
+ manifest['_tags'] = manifest['tags'].map { |e| { name: e["name"] } }.join(", ")
45
+ manifest
46
+ end
47
+
48
+ build_options
49
+ end
50
+
51
+ autoload_subcommands
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module HammerCLIKatello
2
+ class DockerTagCommand < HammerCLIForeman::Command
3
+ resource :docker_tags
4
+ command_name 'tag'
5
+ desc _('Manage docker tags')
6
+
7
+ class ListCommand < HammerCLIKatello::ListCommand
8
+ include HammerCLIKatello::LifecycleEnvironmentNameMapping
9
+
10
+ output do
11
+ field :id, _("ID")
12
+ field :name, _("Tag")
13
+ field :repository_id, _("Repository ID")
14
+ end
15
+
16
+ build_options do |o|
17
+ o.expand.including(:products, :organizations, :content_views)
18
+ end
19
+
20
+ extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
21
+ end
22
+
23
+ class InfoCommand < HammerCLIKatello::InfoCommand
24
+ output do
25
+ field :id, _("ID")
26
+ field :name, _("Tag")
27
+ field :repository_id, _("Repository ID")
28
+
29
+ from :manifest do
30
+ field :id, _("Docker Manifest ID")
31
+ field :name, _("Docker Manifest Name")
32
+ end
33
+ end
34
+
35
+ build_options
36
+ end
37
+
38
+ autoload_subcommands
39
+ end
40
+ end