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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ef1231a1d905ff53eb70cc86e37c9fe6312ff5aca6183165e172cf03e88ac44
4
- data.tar.gz: b377c06ddefb1ca00b8ed84d02f90b66dc51fb27ef4817b87d2c8a7d0cdc62af
3
+ metadata.gz: b5fa880828d3804a98b06e439b6ea10c6f0784102ac00d5ba686b3ff2e27ced6
4
+ data.tar.gz: 52650dc243f073826a2f47cbe69939a2c8af4e2dd8acf3f1843b0acf3dab4063
5
5
  SHA512:
6
- metadata.gz: 3c85164176d1e27213fde99d8a7ca7135fe85dc0b3ee0bf7fdf552e1644b0a42c249d415eb546a40286e5b7895c12b56bae227fca7043329bd20ca584c67fc41
7
- data.tar.gz: 675dfa2798671df7b13caf791f107626ada1289f36f1ca4c0fa9986cf9602cd90275293125a61cf3bf738961a4ba2ca31d91ed76a7f3e2d99db106c753384e01
6
+ metadata.gz: b782ea88258329a25f04d308d7f419328a931e2d8ed9d757da44bc7ce54fc37351635cea13d1d990de6d5a399ba6793c2aeecf5ed65f374dfb4d51a2fded2308
7
+ data.tar.gz: e7883bbd668c0eb608b2ad4dc31191f41f8e0837a4648003d2313a0fc13d425778f0f803a46c1343d25dcd25317c27d8ba2d6fc671be846b7bedeb9b60df0beb
@@ -30,7 +30,7 @@ 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'
33
+ require 'hammer_cli_katello/content_export_helper'
34
34
 
35
35
  # commands
36
36
  HammerCLI::MainCommand.lazy_subcommand("activation-key", _("Manipulate activation keys"),
@@ -43,15 +43,6 @@ module HammerCLIKatello
43
43
  'hammer_cli_katello/organization'
44
44
  )
45
45
 
46
- HammerCLI::MainCommand.lazy_subcommand("gpg",
47
- _("Manipulate GPG Key actions on the server"),
48
- 'HammerCLIKatello::GpgKeyCommand',
49
- 'hammer_cli_katello/gpg_key',
50
- :warning =>
51
- _('The gpg sub-command is deprecated and will be removed in one of the future versions.' \
52
- ' Please use the content-credentials command instead.')
53
- )
54
-
55
46
  HammerCLI::MainCommand.lazy_subcommand("content-credentials",
56
47
  _("Manipulate content credentials on the server"),
57
48
  'HammerCLIKatello::ContentCredentialCommand',
@@ -69,11 +60,6 @@ module HammerCLIKatello
69
60
  'hammer_cli_katello/product'
70
61
  )
71
62
 
72
- HammerCLI::MainCommand.lazy_subcommand("puppet-module", _("View Puppet Module details"),
73
- 'HammerCLIKatello::PuppetModule',
74
- 'hammer_cli_katello/puppet_module'
75
- )
76
-
77
63
  HammerCLI::MainCommand.lazy_subcommand("repository", _("Manipulate repositories"),
78
64
  'HammerCLIKatello::Repository',
79
65
  'hammer_cli_katello/repository'
@@ -141,6 +127,18 @@ module HammerCLIKatello
141
127
  'hammer_cli_katello/file'
142
128
  )
143
129
 
130
+ HammerCLI::MainCommand.lazy_subcommand("content-export",
131
+ _("Prepare content for export to a disconnected Katello"),
132
+ 'HammerCLIKatello::ContentExport',
133
+ 'hammer_cli_katello/content_export'
134
+ )
135
+
136
+ HammerCLI::MainCommand.lazy_subcommand("content-import",
137
+ _("Import content from an upstream archive."),
138
+ 'HammerCLIKatello::ContentImport',
139
+ 'hammer_cli_katello/content_import'
140
+ )
141
+
144
142
  HammerCLI::MainCommand.lazy_subcommand("module-stream", _("View Module Streams"),
145
143
  'HammerCLIKatello::ModuleStreamCommand',
146
144
  'hammer_cli_katello/module_stream'
@@ -151,6 +149,17 @@ module HammerCLIKatello
151
149
  'hammer_cli_katello/srpm'
152
150
  )
153
151
 
152
+ HammerCLI::MainCommand.lazy_subcommand("simple-content-access",
153
+ _("Simple content access commands"),
154
+ 'HammerCLIKatello::SimpleContentAccess',
155
+ 'hammer_cli_katello/simple_content_access'
156
+ )
157
+
158
+ HammerCLI::MainCommand.lazy_subcommand("docker", _("Manipulate docker content"),
159
+ 'HammerCLIKatello::DockerCommand',
160
+ 'hammer_cli_katello/docker'
161
+ )
162
+
154
163
  # subcommands to hammer_cli_foreman commands
155
164
  require 'hammer_cli_katello/host'
156
165
  require 'hammer_cli_katello/hostgroup'
@@ -11,7 +11,7 @@ module HammerCLIKatello
11
11
  action :index
12
12
 
13
13
  output do
14
- field :id, _("ID")
14
+ field :id, _("Id")
15
15
  field :name, _("Name")
16
16
  field :format_consumed, _("Host Limit")
17
17
  from :environment do
@@ -53,7 +53,7 @@ module HammerCLIKatello
53
53
 
54
54
  output do
55
55
  field :name, _("Name")
56
- field :id, _("ID")
56
+ field :id, _("Id")
57
57
  field :description, _("Description")
58
58
  field :format_limit, _("Host Limit")
59
59
  field :auto_attach, _("Auto Attach")
@@ -67,7 +67,7 @@ module HammerCLIKatello
67
67
  end
68
68
 
69
69
  collection :host_collections, _("Host Collections") do
70
- field :id, _("ID")
70
+ field :id, _("Id")
71
71
  field :name, _("Name")
72
72
  end
73
73
 
@@ -150,7 +150,7 @@ module HammerCLIKatello
150
150
  command_name "subscriptions"
151
151
 
152
152
  output do
153
- field :id, _("ID")
153
+ field :id, _("Id")
154
154
  field :product_name, _("Name")
155
155
  field :format_consumed, _("Attached")
156
156
  field :quantity_attached, _("Quantity")
@@ -230,7 +230,7 @@ module HammerCLIKatello
230
230
  command_name "host-collections"
231
231
 
232
232
  output do
233
- field :id, _("ID")
233
+ field :id, _("Id")
234
234
  field :name, _("Name")
235
235
  end
236
236
 
@@ -13,7 +13,7 @@ module HammerCLIKatello
13
13
  command_name 'lifecycle-environments'
14
14
 
15
15
  output do
16
- field :id, _("ID")
16
+ field :id, _("Id")
17
17
  field :name, _("Name")
18
18
  from :organization do
19
19
  field :name, _("Organization")
@@ -28,7 +28,7 @@ module HammerCLIKatello
28
28
  command_name 'available-lifecycle-environments'
29
29
 
30
30
  output do
31
- field :id, _("ID")
31
+ field :id, _("Id")
32
32
  field :name, _("Name")
33
33
  from :organization do
34
34
  field :name, _("Organization")
@@ -167,7 +167,6 @@ module HammerCLIKatello
167
167
  field :packages, _('Packages')
168
168
  field :package_groups, _('Package groups')
169
169
  field :errata, _('Errata')
170
- field :puppet_modules, _('Puppet modules')
171
170
  end
172
171
  end
173
172
  end
@@ -2,13 +2,16 @@ module HammerCLIKatello
2
2
  module CommandExtensions
3
3
  class LifecycleEnvironment < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environment options is ended.
5
- option '--environment', 'ENVIRONMENT_NAME', _('Lifecycle environment name to search by'),
6
- attribute_name: :option_environment_name,
7
- deprecated: { '--environment' => _('Use --lifecycle-environment instead') }
8
- option '--environment-id', 'ENVIRONMENT_ID', _(''),
9
- format: HammerCLI::Options::Normalizers::Number.new,
10
- attribute_name: :option_environment_id,
11
- deprecated: { '--environment-id' => _('Use --lifecycle-environment-id instead') }
5
+ option_family(
6
+ deprecated: { '--environment' => _("Use %s instead") % '--lifecycle-environment',
7
+ '--environment-id' => _("Use %s instead") % '--lifecycle-environment-id'}
8
+ ) do
9
+ child '--environment', 'ENVIRONMENT_NAME', _('Lifecycle environment name to search by'),
10
+ attribute_name: :option_environment_name
11
+ parent '--environment-id', 'ENVIRONMENT_ID', _(''),
12
+ format: HammerCLI::Options::Normalizers::Number.new,
13
+ attribute_name: :option_environment_id
14
+ end
12
15
 
13
16
  option_sources do |sources, command|
14
17
  sources.find_by_name('IdResolution').insert_relative(
@@ -2,14 +2,17 @@ module HammerCLIKatello
2
2
  module CommandExtensions
3
3
  class LifecycleEnvironments < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environments options is ended.
5
- option '--environments', 'ENVIRONMENT_NAMES', _(''),
6
- format: HammerCLI::Options::Normalizers::List.new,
7
- attribute_name: :option_environment_names,
8
- deprecated: { '--environments' => _('Use --lifecycle-environments instead') }
9
- option '--environment-ids', 'ENVIRONMENT_IDS', _(''),
10
- format: HammerCLI::Options::Normalizers::List.new,
11
- attribute_name: :option_environment_ids,
12
- deprecated: { '--environment-ids' => _('Use --lifecycle-environment-ids instead') }
5
+ option_family(
6
+ format: HammerCLI::Options::Normalizers::List.new,
7
+ deprecation: _("Use %s instead") % '--lifecycle-environment[s|-ids]',
8
+ deprecated: { '--environments' => _("Use %s instead") % '--lifecycle-environments',
9
+ '--environment-ids' => _("Use %s instead") % '--lifecycle-environment-ids'}
10
+ ) do
11
+ parent '--environment-ids', 'ENVIRONMENT_IDS', _(''),
12
+ attribute_name: :option_environment_ids
13
+ child '--environments', 'ENVIRONMENT_NAMES', _(''),
14
+ attribute_name: :option_environment_names
15
+ end
13
16
 
14
17
  option_sources do |sources, command|
15
18
  sources.find_by_name('IdResolution').insert_relative(
@@ -4,8 +4,9 @@ module HammerCLIKatello
4
4
 
5
5
  class ListCommand < HammerCLIKatello::ListCommand
6
6
  output do
7
- field :id, _("ID")
8
- field :name, _("Name")
7
+ field :id, _('Id')
8
+ field :name, _('Name')
9
+ field :content_type, _('Content Type')
9
10
  end
10
11
 
11
12
  build_options
@@ -13,51 +14,51 @@ module HammerCLIKatello
13
14
 
14
15
  class InfoCommand < HammerCLIKatello::InfoCommand
15
16
  output do
16
- field :id, _("ID")
17
- field :name, _("Name")
17
+ field :id, _('Id')
18
+ field :name, _('Name')
18
19
  from :organization do
19
- field :name, _("Organization")
20
+ field :name, _('Organization')
20
21
  end
21
22
 
22
- collection :repositories, "Repositories" do
23
- field :id, _("ID")
24
- field :name, _("Name")
25
- field :content_type, _("Content Type")
23
+ collection :repositories, 'Repositories' do
24
+ field :id, _('Id')
25
+ field :name, _('Name')
26
+ field :content_type, _('Content Type')
26
27
  from :product do
27
- field :name, _("Product")
28
+ field :name, _('Product')
28
29
  end
29
30
  end
30
31
 
31
- field :content, _("Content"), Fields::LongText
32
+ field :content, _('Content'), Fields::LongText
32
33
  end
33
34
 
34
35
  build_options
35
36
  end
36
37
 
37
38
  class CreateCommand < HammerCLIKatello::CreateCommand
38
- success_message _("Content credential created.")
39
- failure_message _("Could not create GPG key")
39
+ success_message _('Content Credential created.')
40
+ failure_message _('Could not create Content Credential')
40
41
 
41
42
  build_options :without => [:content]
42
- option "--key", "GPG_KEY_FILE", _("GPG Key file"),
43
+ option '--path', 'KEY_FILE', _('Key file'),
43
44
  :attribute_name => :option_content,
44
45
  :required => true,
45
46
  :format => HammerCLI::Options::Normalizers::File.new
46
47
  end
47
48
 
48
49
  class UpdateCommand < HammerCLIKatello::UpdateCommand
49
- success_message _("GPG Key updated.")
50
- failure_message _("Could not update GPG Key")
50
+ success_message _('Content Credential updated.')
51
+ failure_message _('Could not update Content Credential')
51
52
 
52
53
  build_options :without => [:content]
53
- option "--key", "GPG_KEY_FILE", _("GPG Key file"),
54
+ option '--path', 'KEY_FILE', _('Key file'),
54
55
  :attribute_name => :option_content,
55
56
  :format => HammerCLI::Options::Normalizers::File.new
56
57
  end
57
58
 
58
59
  class DeleteCommand < HammerCLIKatello::DeleteCommand
59
- success_message _("GPG Key deleted.")
60
- failure_message _("Could not delete the GPG Key")
60
+ success_message _('Content Credential deleted.')
61
+ failure_message _('Could not delete the Content Credential')
61
62
 
62
63
  build_options
63
64
  end
@@ -0,0 +1,73 @@
1
+ require 'hammer_cli_katello/content_export_complete'
2
+ require 'hammer_cli_katello/content_export_incremental'
3
+
4
+ module HammerCLIKatello
5
+ class ContentExport < HammerCLIKatello::Command
6
+ desc "Prepare content for export to a disconnected Katello"
7
+ resource :content_exports
8
+
9
+ class GenerateMetadataCommand < HammerCLIKatello::Command
10
+ desc _("Writes export metadata to disk for use by the importing Katello. This command "\
11
+ + "only needs to be used if the export was performed asynchronously "\
12
+ + "or if the metadata was lost")
13
+
14
+ command_name 'generate-metadata'
15
+
16
+ include ContentExportHelper
17
+
18
+ option "--task-id", "TASK_ID",
19
+ _("Generate metadata based on output of the specified export task"),
20
+ :attribute_name => :option_task_id,
21
+ :required => false
22
+
23
+ option "--id", "ID",
24
+ _("Generate metadata based on specified export history"),
25
+ :attribute_name => :option_export_id,
26
+ :required => false
27
+
28
+ def execute
29
+ export_history = if option_task_id
30
+ export_task = reload_task(option_task_id)
31
+ fetch_export_history_from_task(export_task)
32
+ else
33
+ fetch_export_history(option_export_id)
34
+ end
35
+
36
+ unless export_history
37
+ raise _("No export history was found. Verify the value given for "\
38
+ + "--task-id or --id")
39
+ end
40
+
41
+ generate_metadata_json(export_history)
42
+
43
+ HammerCLI::EX_OK
44
+ end
45
+ end
46
+
47
+ class ListCommand < HammerCLIKatello::ListCommand
48
+ desc "View content view export histories"
49
+ output do
50
+ field :id, _('ID')
51
+ field :destination_server, _('Destination Server')
52
+ field :path, _('Path')
53
+ field :type, _('Type')
54
+ field :content_view_version, _('Content View Version')
55
+ field :content_view_version_id, _('Content View Version ID')
56
+ field :created_at, _('Created at')
57
+ field :updated_at, _('Updated at'), Fields::Field, :hide_blank => true
58
+ end
59
+
60
+ build_options
61
+ end
62
+
63
+ autoload_subcommands
64
+
65
+ subcommand HammerCLIKatello::ContentExportComplete.command_name,
66
+ HammerCLIKatello::ContentExportComplete.desc,
67
+ HammerCLIKatello::ContentExportComplete
68
+
69
+ subcommand HammerCLIKatello::ContentExportIncremental.command_name,
70
+ HammerCLIKatello::ContentExportIncremental.desc,
71
+ HammerCLIKatello::ContentExportIncremental
72
+ end
73
+ end
@@ -0,0 +1,25 @@
1
+ module HammerCLIKatello
2
+ class ContentExportComplete < HammerCLIKatello::Command
3
+ desc "Prepare content for a full export to a disconnected Katello"
4
+ resource :content_exports
5
+ command_name 'complete'
6
+
7
+ class VersionCommand < HammerCLIKatello::SingleResourceCommand
8
+ desc _('Performs a full export 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 a full 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,181 @@
1
+ require 'hammer_cli_katello/repository'
2
+ # rubocop:disable ModuleLength
3
+ module HammerCLIKatello
4
+ module ContentExportHelper
5
+ include ApipieHelper
6
+
7
+ def execute
8
+ warn_unexportable_repositories
9
+ response = super
10
+ if option_async?
11
+ output.print_message _("Once the task completes the export metadata must be generated "\
12
+ + "with the command:")
13
+ output.print_message(" hammer content-export generate-metadata --task-id #{@task['id']}")
14
+ HammerCLI::EX_OK
15
+ elsif response != HammerCLI::EX_OK
16
+ response
17
+ else
18
+ export_history = fetch_export_history_from_task(reload_task(@task))
19
+ if export_history
20
+ generate_metadata_json(export_history)
21
+ HammerCLI::EX_OK
22
+ else
23
+ output.print_error _("Could not fetch the export history")
24
+ HammerCLI::EX_CANTCREAT
25
+ end
26
+ end
27
+ end
28
+
29
+ def send_request
30
+ @task = super
31
+ end
32
+
33
+ def reload_task(task)
34
+ task_id = if task.is_a? Hash
35
+ task['id']
36
+ else
37
+ task
38
+ end
39
+ show(:foreman_tasks, id: task_id)
40
+ end
41
+
42
+ def fetch_export_history(export_history_id)
43
+ index(:content_exports, :id => export_history_id).first if export_history_id
44
+ end
45
+
46
+ def fetch_export_history_from_task(task)
47
+ # checking this here implies the task object was loaded recently
48
+ if %w(error warning).include?(task['result'])
49
+ raise _("Can not fetch export history from an unfinished task")
50
+ end
51
+
52
+ export_history_id = task.dig('output', 'export_history_id')
53
+ fetch_export_history(export_history_id)
54
+ end
55
+
56
+ def generate_metadata_json(export_history)
57
+ metadata_json = export_history["metadata"].to_json
58
+ begin
59
+ metadata_path = "#{export_history['path']}/metadata.json"
60
+ File.write(metadata_path, metadata_json)
61
+ output.print_message _("Generated #{metadata_path}")
62
+ rescue SystemCallError
63
+ filename = "metadata-#{export_history['id']}.json"
64
+ File.write(filename, metadata_json)
65
+ output.print_message _("Unable to access/write to '#{export_history['path']}'. "\
66
+ "Generated '#{Dir.pwd}/#{filename}' instead. "\
67
+ "This file is necessary to perform an import.")
68
+ end
69
+ end
70
+
71
+ def version_command?
72
+ self.class.command_name.first.to_sym == :version
73
+ end
74
+
75
+ def fetch_repositories
76
+ repo_options = {
77
+ library: true,
78
+ content_type: 'yum',
79
+ search: 'download_policy != immediate'
80
+ }
81
+ if version_command?
82
+ repo_options[:content_view_version_id] = resolver.content_view_version_id(options)
83
+ else
84
+ repo_options[:organization_id] = options["option_organization_id"]
85
+ end
86
+ index(:repositories, repo_options)
87
+ end
88
+
89
+ def warn_unexportable_repositories
90
+ repos = fetch_repositories
91
+ unless repos.empty?
92
+ if version_command?
93
+ output.print_message _("NOTE: Unable to fully export this version because"\
94
+ " it contains repositories without the 'immediate' download policy."\
95
+ " Update the download policy and sync affected repositories."\
96
+ " Once synced republish the content view"\
97
+ " and export the generated version.")
98
+ else
99
+ output.print_message _("NOTE: Unable to fully export this organization's library because"\
100
+ " it contains repositories without the 'immediate' download policy."\
101
+ " Update the download policy and sync affected"\
102
+ " repositories to include them in the export.")
103
+ end
104
+ output.print_message _("Use the following command to update the "\
105
+ "download policy of these repositories.")
106
+ output.print_message "hammer repository update --id=<REPOSITORY_ID> "\
107
+ "--download-policy='immediate'"
108
+ output.print_message ""
109
+ print_record(::HammerCLIKatello::Repository::ListCommand.output_definition, repos)
110
+ exit(HammerCLI::EX_SOFTWARE) if option_fail_on_missing_content?
111
+ end
112
+ end
113
+
114
+ def self.included(base)
115
+ if base.command_name.first.to_sym == :version
116
+ setup_version(base)
117
+ elsif base.command_name.first.to_sym == :library
118
+ setup_library(base)
119
+ end
120
+ end
121
+
122
+ def self.setup_library(base)
123
+ base.action(:library)
124
+ base.success_message _("Library environment is being exported in task %{id}.")
125
+ base.failure_message _("Could not export the library")
126
+ base.option "--fail-on-missing-content", :flag,
127
+ _("Fails if any of the repositories belonging"\
128
+ " to this organization are unexportable.")
129
+
130
+ base.build_options do |o|
131
+ o.expand(:all).including(:organizations)
132
+ end
133
+ end
134
+
135
+ def self.setup_version(base)
136
+ base.action(:version)
137
+ setup_version_options(base)
138
+ base.success_message _("Content view version is being exported in task %{id}.")
139
+ base.failure_message _("Could not export the content view version")
140
+
141
+ base.extend_with(
142
+ HammerCLIKatello::CommandExtensions::LifecycleEnvironments.new(only: :option_sources)
143
+ )
144
+ base.include(LifecycleEnvironmentNameMapping)
145
+
146
+ base.class_eval do
147
+ def request_params
148
+ super.tap do |opts|
149
+ opts["id"] = resolver.content_view_version_id(options)
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def self.setup_version_options(base)
156
+ base.option "--fail-on-missing-content", :flag,
157
+ _("Fails if any of the repositories belonging"\
158
+ " to this version are unexportable.")
159
+
160
+ base.option "--version", "VERSION", _("Filter versions by version number."),
161
+ :attribute_name => :option_version,
162
+ :required => false
163
+
164
+ base.build_options do |o|
165
+ o.expand(:all).including(:content_views, :organizations, :environments)
166
+ o.without(:environment_ids, :environment_id)
167
+ end
168
+
169
+ base.validate_options do
170
+ unless option(:option_id).exist?
171
+ any(:option_id, :option_content_view_name, :option_content_view_id).required
172
+ any(:option_version, :option_environment_id, :option_environment_name).required
173
+ unless option(:option_content_view_id).exist?
174
+ any(:option_organization_id, :option_organization_name, \
175
+ :option_organization_label).required
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end