hammer_cli_katello 0.24.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +24 -15
  3. data/lib/hammer_cli_katello/activation_key.rb +5 -5
  4. data/lib/hammer_cli_katello/capsule.rb +2 -3
  5. data/lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb +10 -7
  6. data/lib/hammer_cli_katello/command_extensions/lifecycle_environments.rb +11 -8
  7. data/lib/hammer_cli_katello/content_credential.rb +20 -19
  8. data/lib/hammer_cli_katello/content_export.rb +73 -0
  9. data/lib/hammer_cli_katello/content_export_complete.rb +25 -0
  10. data/lib/hammer_cli_katello/content_export_helper.rb +181 -0
  11. data/lib/hammer_cli_katello/content_export_incremental.rb +25 -0
  12. data/lib/hammer_cli_katello/content_import.rb +78 -0
  13. data/lib/hammer_cli_katello/content_view.rb +19 -32
  14. data/lib/hammer_cli_katello/content_view_version.rb +4 -290
  15. data/lib/hammer_cli_katello/deb_package.rb +3 -3
  16. data/lib/hammer_cli_katello/docker.rb +13 -0
  17. data/lib/hammer_cli_katello/docker_manifest.rb +53 -0
  18. data/lib/hammer_cli_katello/docker_tag.rb +40 -0
  19. data/lib/hammer_cli_katello/erratum.rb +1 -1
  20. data/lib/hammer_cli_katello/erratum_info_command.rb +1 -1
  21. data/lib/hammer_cli_katello/file.rb +3 -3
  22. data/lib/hammer_cli_katello/filter.rb +2 -2
  23. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  24. data/lib/hammer_cli_katello/host_collection.rb +2 -2
  25. data/lib/hammer_cli_katello/host_deb.rb +1 -1
  26. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  27. data/lib/hammer_cli_katello/host_extensions.rb +5 -5
  28. data/lib/hammer_cli_katello/host_package.rb +1 -1
  29. data/lib/hammer_cli_katello/hostgroup_extensions.rb +4 -4
  30. data/lib/hammer_cli_katello/id_resolver.rb +8 -7
  31. data/lib/hammer_cli_katello/lifecycle_environment.rb +2 -2
  32. data/lib/hammer_cli_katello/module_stream.rb +8 -8
  33. data/lib/hammer_cli_katello/organization.rb +10 -0
  34. data/lib/hammer_cli_katello/organization_options.rb +8 -6
  35. data/lib/hammer_cli_katello/ostree_branch.rb +2 -2
  36. data/lib/hammer_cli_katello/package.rb +5 -5
  37. data/lib/hammer_cli_katello/package_group.rb +4 -4
  38. data/lib/hammer_cli_katello/ping.rb +13 -19
  39. data/lib/hammer_cli_katello/product.rb +3 -3
  40. data/lib/hammer_cli_katello/product_content.rb +2 -2
  41. data/lib/hammer_cli_katello/repository.rb +27 -37
  42. data/lib/hammer_cli_katello/repository_set.rb +4 -4
  43. data/lib/hammer_cli_katello/simple_content_access.rb +42 -0
  44. data/lib/hammer_cli_katello/srpm.rb +2 -2
  45. data/lib/hammer_cli_katello/subscription.rb +2 -3
  46. data/lib/hammer_cli_katello/sync_plan.rb +2 -2
  47. data/lib/hammer_cli_katello/version.rb +1 -1
  48. data/locale/hammer-cli-katello.pot +0 -25
  49. data/test/data/3.19/foreman_api.json +1 -0
  50. data/test/data/4.0/foreman_api.json +1 -0
  51. data/test/data/4.1/foreman_api.json +1 -0
  52. data/test/functional/activation_key/subscriptions_test.rb +5 -2
  53. data/test/functional/capsule/content/info_test.rb +1 -2
  54. data/test/functional/content_credentials/create_test.rb +32 -0
  55. data/test/functional/{repository → content_credentials}/data/test_cert.json +0 -0
  56. data/test/functional/content_credentials/list_test.rb +6 -8
  57. data/test/functional/content_export/complete/library_test.rb +155 -0
  58. data/test/functional/content_export/complete/version_test.rb +217 -0
  59. data/test/functional/content_export/content_export_helpers.rb +26 -0
  60. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  61. data/test/functional/content_export/incremental/library_test.rb +172 -0
  62. data/test/functional/content_export/incremental/version_test.rb +268 -0
  63. data/test/functional/content_export/list_test.rb +64 -0
  64. data/test/functional/content_import/library_test.rb +85 -0
  65. data/test/functional/content_import/list_test.rb +65 -0
  66. data/test/functional/content_import/metadata.json +1 -0
  67. data/test/functional/content_import/version_test.rb +85 -0
  68. data/test/functional/content_view/content_view_helpers.rb +3 -1
  69. data/test/functional/content_view/list_test.rb +0 -2
  70. data/test/functional/content_view/publish_test.rb +0 -21
  71. data/test/functional/content_view/version/promote_test.rb +1 -2
  72. data/test/functional/content_view/version/republish_repositories_test.rb +1 -2
  73. data/test/functional/host/errata/apply_test.rb +0 -2
  74. data/test/functional/host/errata/recalculate_test.rb +0 -2
  75. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +1 -1
  76. data/test/functional/organization/info_test.rb +22 -0
  77. data/test/functional/ping_test.rb +52 -15
  78. data/test/functional/repository/create_test.rb +0 -30
  79. data/test/functional/repository/info_test.rb +4 -4
  80. data/test/functional/repository/list_test.rb +0 -2
  81. data/test/functional/search_helpers.rb +11 -0
  82. data/test/functional/simple_content_access/disable_test.rb +48 -0
  83. data/test/functional/simple_content_access/enable_test.rb +46 -0
  84. data/test/test_helper.rb +1 -1
  85. metadata +50 -56
  86. data/lib/hammer_cli_katello/content_view_puppet_module.rb +0 -60
  87. data/lib/hammer_cli_katello/cv_import_export_helper.rb +0 -166
  88. data/lib/hammer_cli_katello/gpg_key.rb +0 -67
  89. data/lib/hammer_cli_katello/puppet_module.rb +0 -59
  90. data/test/functional/content_view/puppet_module/add_test.rb +0 -24
  91. data/test/functional/content_view/puppet_module/remove_test.rb +0 -54
  92. data/test/functional/content_view/version/default_export_test.rb +0 -40
  93. data/test/functional/content_view/version/export_histories_test.rb +0 -34
  94. data/test/functional/content_view/version/export_test.rb +0 -136
  95. data/test/functional/content_view/version/import_test.rb +0 -318
  96. data/test/functional/gpg_test.rb +0 -39
  97. data/test/functional/repository/data/test_ca.json +0 -43
  98. data/test/functional/repository/data/test_key.json +0 -43
@@ -0,0 +1,25 @@
1
+ module HammerCLIKatello
2
+ class ContentExportIncremental < HammerCLIKatello::Command
3
+ desc "Prepare content for an incremental export to a disconnected Katello"
4
+ resource :content_export_incrementals
5
+ command_name 'incremental'
6
+
7
+ class VersionCommand < HammerCLIKatello::SingleResourceCommand
8
+ desc _('Performs an incremental export of a content view version')
9
+ command_name "version"
10
+
11
+ include HammerCLIForemanTasks::Async
12
+ include ContentExportHelper
13
+ end
14
+
15
+ class LibraryCommand < HammerCLIKatello::SingleResourceCommand
16
+ desc _("Performs an incremental export of the organization's library environment")
17
+ command_name "library"
18
+
19
+ include HammerCLIForemanTasks::Async
20
+ include ContentExportHelper
21
+ end
22
+
23
+ autoload_subcommands
24
+ end
25
+ end
@@ -0,0 +1,78 @@
1
+ module HammerCLIKatello
2
+ class ContentImport < HammerCLIKatello::Command
3
+ desc "Import content from a content archive"
4
+ resource :content_imports
5
+
6
+ module ContentImportCommon
7
+ def self.included(base)
8
+ base.option "--metadata-file",
9
+ "METADATA_FILE", _("Location of the metadata.json file. "\
10
+ "This is not required if the metadata.json file"\
11
+ " is already in the archive directory."),
12
+ :attribute_name => :option_metadata_file,
13
+ :required => false
14
+
15
+ base.build_options do |o|
16
+ o.expand(:all).including(:organizations).except(:metadata)
17
+ end
18
+
19
+ base.validate_options do
20
+ option(:option_path).required
21
+
22
+ metadata_file = option(:option_metadata_file).value ||
23
+ File.join(option(:option_path).value, "metadata.json")
24
+ unless File.exist?(metadata_file)
25
+ msg = _("Unable to find '#{metadata_file}'. "\
26
+ "If the metadata.json file is at a different location "\
27
+ "provide it to the --metadata-file option ")
28
+ raise HammerCLI::Options::Validators::ValidationError, msg
29
+ end
30
+ end
31
+ base.success_message _("Archive is being imported in task %{id}.")
32
+ base.failure_message _("Could not import the archive.")
33
+ end
34
+
35
+ def request_params
36
+ super.tap do |opts|
37
+ metadata_file = option_metadata_file || File.join(option_path, "metadata.json")
38
+ opts["metadata"] = JSON.parse(File.read(metadata_file))
39
+ end
40
+ end
41
+ end
42
+
43
+ class VersionCommand < HammerCLIKatello::SingleResourceCommand
44
+ desc _('Imports a content archive to a content view version')
45
+ action :version
46
+ command_name "version"
47
+
48
+ include HammerCLIForemanTasks::Async
49
+ include ContentImportCommon
50
+ end
51
+
52
+ class LibraryCommand < HammerCLIKatello::SingleResourceCommand
53
+ desc _("Imports a content archive to an organization's library lifecycle environment")
54
+ action :library
55
+ command_name "library"
56
+
57
+ include HammerCLIForemanTasks::Async
58
+ include ContentImportCommon
59
+ end
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
+
76
+ autoload_subcommands
77
+ end
78
+ end
@@ -1,4 +1,3 @@
1
- require 'hammer_cli_katello/content_view_puppet_module'
2
1
  require 'hammer_cli_katello/content_view_purge'
3
2
  require 'hammer_cli_katello/filter'
4
3
  require 'hammer_cli_katello/content_view_version'
@@ -29,13 +28,12 @@ module HammerCLIKatello
29
28
  include OrganizationOptions
30
29
 
31
30
  output do
32
- field :id, _("ID")
31
+ field :id, _("Id")
33
32
  field :name, _("Name")
34
33
  field :label, _("Label")
35
34
  field :composite, _("Composite")
36
35
  field :description, _("Description")
37
36
  field :content_host_count, _("Content Host Count")
38
- field :force_puppet_environment, _("Force Puppet")
39
37
  field :solve_dependencies, _("Solve Dependencies")
40
38
 
41
39
  from :organization do
@@ -43,43 +41,36 @@ module HammerCLIKatello
43
41
  end
44
42
 
45
43
  collection :_yum_repositories, _("Yum Repositories") do
46
- field :id, _("ID")
44
+ field :id, _("Id")
47
45
  field :name, _("Name")
48
46
  field :label, _("Label")
49
47
  end
50
48
 
51
49
  collection :_docker_repositories, _("Container Image Repositories") do
52
- field :id, _("ID")
50
+ field :id, _("Id")
53
51
  field :name, _("Name")
54
52
  field :label, _("Label")
55
53
  end
56
54
 
57
55
  collection :_ostree_repositories, _("OSTree Repositories") do
58
- field :id, _("ID")
56
+ field :id, _("Id")
59
57
  field :name, _("Name")
60
58
  field :label, _("Label")
61
59
  end
62
60
 
63
- collection :puppet_modules, _("Puppet Modules") do
64
- field :id, _("ID")
65
- field :uuid, _("UUID"), Fields::Field, :hide_blank => true
66
- field :name, _("Name")
67
- field :author, _("Author")
68
- end
69
-
70
61
  collection :environments, _("Lifecycle Environments") do
71
- field :id, _("ID")
62
+ field :id, _("Id")
72
63
  field :name, _("Name")
73
64
  end
74
65
 
75
66
  collection :versions, _("Versions") do
76
- field :id, _("ID")
67
+ field :id, _("Id")
77
68
  field :version, _("Version")
78
69
  field :published, _("Published"), Fields::Date
79
70
  end
80
71
 
81
72
  collection :components, _("Components") do
82
- field :id, _("ID")
73
+ field :id, _("Id")
83
74
  field :name, _("Name")
84
75
  end
85
76
 
@@ -106,10 +97,12 @@ module HammerCLIKatello
106
97
  failure_message _("Could not create the content view")
107
98
 
108
99
  option ["--composite"], :flag, _("Create a composite content view")
109
-
100
+ option ["--import-only"], :flag, _("Designate this Content View for "\
101
+ "importing from upstream servers only.")
110
102
  def request_params
111
103
  super.tap do |opts|
112
104
  opts['composite'] = option_composite? || false
105
+ opts['import_only'] = option_import_only? || false
113
106
  end
114
107
  end
115
108
 
@@ -244,13 +237,6 @@ module HammerCLIKatello
244
237
  action :remove
245
238
  command_name "remove"
246
239
 
247
- option ["--content-view-version-ids"], "VERSION_IDS",
248
- _("Version ids to remove"),
249
- :format => HammerCLI::Options::Normalizers::List.new
250
- option ["--lifecycle-environment-ids"], "LIFECYCLE_ENVIRONMENT_IDS",
251
- _("Environment ids to remove"),
252
- :format => HammerCLI::Options::Normalizers::List.new
253
-
254
240
  def option_sources
255
241
  sources = super
256
242
  sources.find_by_name('IdResolution').insert_relative(
@@ -283,10 +269,15 @@ module HammerCLIKatello
283
269
  command_name 'add-version'
284
270
  desc _('Add a content view version to a composite view')
285
271
 
286
- option "--content-view-id", "CONTENT_VIEW_ID",
287
- _("Content view numeric identifier to search by"),
288
- attribute_name: :option_content_view_id,
289
- format: HammerCLI::Options::Normalizers::Number.new
272
+ option_family do
273
+ parent "--content-view-id", "CONTENT_VIEW_ID",
274
+ _("Content view id to search by"),
275
+ attribute_name: :option_content_view_id,
276
+ format: HammerCLI::Options::Normalizers::Number.new
277
+ child "--content-view", "CONTENT_VIEW_NAME",
278
+ _("Content view name to search by"),
279
+ attribute_name: :option_content_view_name
280
+ end
290
281
 
291
282
  validate_options :before, 'IdResolution' do
292
283
  if option(:option_content_view_version_version).exist?
@@ -356,10 +347,6 @@ module HammerCLIKatello
356
347
 
357
348
  autoload_subcommands
358
349
 
359
- subcommand 'puppet-module',
360
- HammerCLIKatello::ContentViewPuppetModule.desc,
361
- HammerCLIKatello::ContentViewPuppetModule
362
-
363
350
  subcommand HammerCLIKatello::Filter.command_name,
364
351
  HammerCLIKatello::Filter.desc,
365
352
  HammerCLIKatello::Filter
@@ -10,7 +10,7 @@ module HammerCLIKatello
10
10
  include LifecycleEnvironmentNameMapping
11
11
 
12
12
  output do
13
- field :id, _("ID")
13
+ field :id, _("Id")
14
14
  field :name, _("Name")
15
15
  field :version, _("Version")
16
16
  field :description, _("Description")
@@ -35,7 +35,7 @@ module HammerCLIKatello
35
35
  resource :content_view_versions, :show
36
36
 
37
37
  output do
38
- field :id, _("ID")
38
+ field :id, _("Id")
39
39
  field :name, _("Name")
40
40
  field :version, _("Version")
41
41
  field :description, _("Description")
@@ -47,23 +47,16 @@ module HammerCLIKatello
47
47
  end
48
48
 
49
49
  collection :environments, _("Lifecycle Environments") do
50
- field :id, _("ID")
50
+ field :id, _("Id")
51
51
  field :name, _("Name")
52
52
  field :label, _("Label")
53
53
  end
54
54
 
55
55
  collection :repositories, _("Repositories") do
56
- field :id, _("ID")
56
+ field :id, _("Id")
57
57
  field :name, _("Name")
58
58
  field :label, _("Label")
59
59
  end
60
-
61
- collection :puppet_modules, _("Puppet Modules") do
62
- field :id, _("ID")
63
- field :name, _("Name")
64
- field :author, _("Author")
65
- field :version, _("Version")
66
- end
67
60
  end
68
61
 
69
62
  build_options do |o|
@@ -278,285 +271,6 @@ module HammerCLIKatello
278
271
  end
279
272
  end
280
273
 
281
- class ExportHistoriesCommand < HammerCLIKatello::ListCommand
282
- desc "View content view export histories"
283
- command_name "export-histories"
284
- action :export_histories
285
-
286
- output do
287
- field :id, _('ID')
288
- field :destination_server, _('Destination Server')
289
- field :path, _('Path')
290
- field :content_view_version, _('Content View Version')
291
- field :content_view_version_id, _('Content View Version ID')
292
- field :created_at, _('Created at')
293
- field :updated_at, _('Updated at'), Fields::Field, :hide_blank => true
294
- end
295
-
296
- build_options
297
- end
298
-
299
- class ExportDefaultCommand < HammerCLIForeman::Command
300
- include HammerCLIKatello::LocalHelper
301
- include HammerCLIKatello::ApipieHelper
302
-
303
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
304
-
305
- desc _('Export the library default content view')
306
-
307
- command_name "export-default"
308
-
309
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
310
-
311
- validate_options do
312
- option(:option_export_dir).required
313
- end
314
-
315
- build_options
316
-
317
- def execute
318
- export_dir = options['option_export_dir']
319
-
320
- Dir.mkdir(export_dir) unless Dir.exist?(export_dir)
321
- result = Kernel.system("rsync -aL #{PUBLISHED_REPOS_DIR} #{export_dir}")
322
- if result == true
323
- output.print_message _("Default content view export is available at #{export_dir}")
324
- HammerCLI::EX_OK
325
- else
326
- output.print_error _("Could not export the default content view at #{export_dir}")
327
- HammerCLI::EX_CANTCREAT
328
- end
329
- end
330
- end
331
-
332
- class LegacyExportCommand < HammerCLIKatello::SingleResourceCommand
333
- include HammerCLIForemanTasks::Async
334
- include LifecycleEnvironmentNameMapping
335
- desc _('Export a content view (legacy method)')
336
-
337
- action :export
338
- command_name "export-legacy"
339
-
340
- success_message _("Content view is being exported in task %{id}.")
341
- failure_message _("Could not export the content view")
342
-
343
- build_options do |o|
344
- o.expand(:all).including(:environments, :content_views, :organizations)
345
- end
346
-
347
- extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
348
- end
349
-
350
- class ExportCommand < HammerCLIForeman::Command
351
- include HammerCLIKatello::LocalHelper
352
- include HammerCLIKatello::ApipieHelper
353
- include HammerCLIKatello::CVImportExportHelper
354
-
355
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
356
-
357
- desc _('Export a content view version')
358
-
359
- command_name "export"
360
-
361
- success_message _("Content view export is available in %{directory}.")
362
- failure_message _("Could not export the content view")
363
-
364
- option "--id", "ID", _("Content View Version numeric identifier")
365
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
366
-
367
- validate_options do
368
- option(:option_export_dir).required
369
- option(:option_id).required
370
- end
371
-
372
- build_options
373
-
374
- def execute
375
- cvv = show(:content_view_versions, 'id' => options['option_id'])
376
- cv = show(:content_views, 'id' => cvv['content_view_id'])
377
-
378
- composite = cv["composite"]
379
-
380
- export_json_options = { :cvv => cvv }
381
-
382
- if composite
383
- components = cv['components']
384
- export_json_options[:component_cvvs] = components.collect do |component|
385
- component['name']
386
- end
387
- export_json_options[:repositories] = []
388
- else
389
- repositories = fetch_exportable_cvv_repositories(cvv)
390
- collect_packages(repositories)
391
-
392
- export_json_options[:repositories] = repositories
393
- end
394
-
395
- json = export_json(export_json_options)
396
- if repositories&.any? || cv['composite']
397
- create_tar(cv, cvv, repositories, json)
398
- else
399
- msg = <<~MSG
400
- Ensure the content view version '#{cvv['name']}' has at least one repository.
401
- MSG
402
- raise _(msg)
403
- end
404
- return HammerCLI::EX_OK
405
- end
406
-
407
- def create_tar(cv, cvv, repositories, json)
408
- export_prefix = "export-#{cv['label']}-#{cvv['major']}.#{cvv['minor']}"
409
- export_file = "#{export_prefix}.json"
410
- export_repos_tar = "#{export_prefix}-repos.tar"
411
- export_tar = "#{export_prefix}.tar"
412
- export_dir = File.expand_path(options['option_export_dir'].to_s)
413
-
414
- Dir.mkdir("#{export_dir}/#{export_prefix}")
415
-
416
- if repositories&.any?
417
-
418
- Dir.chdir(PUBLISHED_REPOS_DIR) do
419
- repo_tar = "#{export_dir}/#{export_prefix}/#{export_repos_tar}"
420
- repo_dirs = []
421
-
422
- repositories.each do |repo|
423
- repo_dirs.push(repo['relative_path'])
424
- end
425
-
426
- `tar cvfh #{repo_tar} #{repo_dirs.join(" ")}`
427
- end
428
- end
429
-
430
- Dir.chdir("#{export_dir}/#{export_prefix}") do
431
- File.open(export_file, 'w') do |file|
432
- file.write(JSON.pretty_generate(json))
433
- end
434
- end
435
-
436
- Dir.chdir(export_dir) do
437
- `tar cf #{export_tar} #{export_prefix}`
438
- FileUtils.rm_rf(export_prefix)
439
- end
440
- end
441
- end
442
-
443
- class ImportCommand < HammerCLIForeman::Command
444
- include HammerCLIForemanTasks::Async
445
- include HammerCLIKatello::LocalHelper
446
- include HammerCLIKatello::ApipieHelper
447
- include HammerCLIKatello::CVImportExportHelper
448
-
449
- attr_accessor :export_tar_dir, :export_tar_file, :export_tar_prefix
450
-
451
- desc _('Import a content view version')
452
-
453
- command_name "import"
454
-
455
- success_message _("Content view imported.")
456
- failure_message _("Could not import the content view")
457
-
458
- option "--organization-id", "ORGANIZATION_ID", _("Organization numeric identifier")
459
- option(
460
- '--export-tar', 'EXPORT_TAR',
461
- _("Location of export tar on disk")
462
- )
463
-
464
- validate_options do
465
- option(:option_export_tar).required
466
- option(:option_organization_id).required
467
- end
468
-
469
- build_options
470
-
471
- # rubocop:disable Metrics/AbcSize
472
- def execute
473
- unless File.exist?(options['option_export_tar'])
474
- raise _("Export tar #{options['option_export_tar']} does not exist.")
475
- end
476
-
477
- import_tar_params = obtain_export_params(options['option_export_tar'])
478
- untar_export(import_tar_params)
479
-
480
- export_json = read_json(import_tar_params)
481
- cv = content_view(export_json['name'], options['option_organization_id'])
482
- major = export_json['major'].to_s
483
- minor = export_json['minor'].to_s
484
- import_checks(export_json, cv, major, minor)
485
-
486
- if export_json['composite_components']
487
- composite_version_ids = export_json['composite_components'].map do |component|
488
- find_local_component_id(component)
489
- end
490
- update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids)
491
- publish(cv['id'], export_json['major'], export_json['minor'])
492
- else
493
- sync_repositories(export_json['repositories'], options['option_organization_id'],
494
- import_tar_params)
495
-
496
- unless cv['default']
497
- publish(
498
- cv['id'], export_json['major'],
499
- export_json['minor'], repos_units(export_json['repositories'])
500
- )
501
- end
502
- end
503
- return HammerCLI::EX_OK
504
- end
505
- # rubocop:enable Metrics/AbcSize
506
-
507
- def sync_repositories(repositories, organization_id, options)
508
- export_tar_dir = options[:dirname]
509
- export_tar_prefix = options[:prefix]
510
-
511
- repositories.each do |repo|
512
- library_repos = index(
513
- :repositories,
514
- 'organization_id' => organization_id,
515
- 'library' => true
516
- )
517
-
518
- library_repo = library_repos.select do |candidate_repo|
519
- candidate_repo['label'] == repo['label']
520
- end
521
-
522
- library_repo = library_repo.first
523
-
524
- if library_repo.nil?
525
- msg = _("Unable to sync repositories, no library repository found for %s")
526
- raise msg % repo['label']
527
- end
528
-
529
- synchronize(
530
- library_repo['id'],
531
- "file://#{export_tar_dir}/#{export_tar_prefix}/#{repo['relative_path']}"
532
- )
533
- end
534
- end
535
-
536
- def repos_units(repositories)
537
- repositories.collect do |repo|
538
- {
539
- 'label' => repo['label'],
540
- 'rpm_filenames' => repo['rpm_filenames']
541
- }
542
- end
543
- end
544
-
545
- def content_view(name, organization_id)
546
- index(:content_views, 'name' => name, 'organization_id' => organization_id).first
547
- end
548
-
549
- def synchronize(id, source_url)
550
- task_progress(call(:sync, :repositories, 'id' => id, 'source_url' => source_url))
551
- end
552
-
553
- def publish(id, major, minor, repos_units = nil)
554
- params = {'id' => id, 'major' => major, 'minor' => minor }
555
- params['repos_units'] = repos_units if repos_units
556
- task_progress(call(:publish, :content_views, params))
557
- end
558
- end
559
-
560
274
  autoload_subcommands
561
275
  end
562
276
  end