hammer_cli_katello 1.4.0 → 1.5.1

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/acs.rb +79 -0
  3. data/lib/hammer_cli_katello/content_export_complete.rb +8 -0
  4. data/lib/hammer_cli_katello/content_export_helper.rb +55 -3
  5. data/lib/hammer_cli_katello/content_export_incremental.rb +8 -0
  6. data/lib/hammer_cli_katello/content_import.rb +9 -0
  7. data/lib/hammer_cli_katello/host_collection.rb +2 -0
  8. data/lib/hammer_cli_katello/id_resolver.rb +3 -2
  9. data/lib/hammer_cli_katello/organization.rb +11 -0
  10. data/lib/hammer_cli_katello/repository.rb +65 -3
  11. data/lib/hammer_cli_katello/version.rb +1 -1
  12. data/lib/hammer_cli_katello.rb +5 -0
  13. data/test/data/4.4/foreman_api.json +1 -0
  14. data/test/data/4.5/foreman_api.json +1 -0
  15. data/test/data/4.6/foreman_api.json +1 -0
  16. data/test/functional/acs/create_test.rb +27 -0
  17. data/test/functional/acs/delete_test.rb +13 -0
  18. data/test/functional/acs/info_test.rb +55 -0
  19. data/test/functional/acs/list_test.rb +62 -0
  20. data/test/functional/acs/update_test.rb +23 -0
  21. data/test/functional/content_export/complete/repository_test.rb +226 -0
  22. data/test/functional/content_export/content_export_helpers.rb +7 -0
  23. data/test/functional/content_export/incremental/repository_test.rb +212 -0
  24. data/test/functional/module_stream/info_test.rb +2 -2
  25. data/test/functional/organization/cdn_configuration_test.rb +5 -2
  26. data/test/functional/organization/info_test.rb +8 -2
  27. data/test/functional/repository/info_test.rb +4 -4
  28. data/test/functional/repository/reclaim_space_test.rb +105 -0
  29. data/test/functional/repository/republish_test.rb +37 -0
  30. data/test/functional/repository/update_test.rb +1 -0
  31. data/test/functional/repository_set/disable_test.rb +7 -1
  32. data/test/test_helper.rb +1 -1
  33. metadata +27 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a00c7f5dd067ab0cc8203da1989be46411dc15ed1079442b38bf27e4c1c5eef
4
- data.tar.gz: 4088650b9e19e79031e912cfc1f3c49ec11ef448e41c5c97cb41820fe5474bcc
3
+ metadata.gz: dfdda5a90efeac9e7d47035405683e52b32e23ae72b3a328cdd538f7e88cda8d
4
+ data.tar.gz: 635453faff97d59d798cd9fab861ef470b046752277ee5d533d34e3729b5b345
5
5
  SHA512:
6
- metadata.gz: 0b638de29d5f9ebf39fa1962ec41d316f23579c64f9b0bd387bc3bd0323d447368fb9dacf283ea8e10d898e1d2bd4e6956c99f435080f38c835092c154e85f03
7
- data.tar.gz: 8c59ab30460634b1098d74933284052ee98492897a04d17358166597fb2d53e2412e521228486b5df37c8d8cb2f254565eb79ccb3cc29e5dfd8cfc9b42b4e399
6
+ metadata.gz: bd86eedc7a1bdd74530697770c9fd1b028e17f82429a5fa092f4886fa553069ba3c35f3b540d6eefeb72ccb398797c4fe9f97d3a4957742a9e93cc1725c0ecfb
7
+ data.tar.gz: 06b29a389f4cca7a3165b6dbadb29d7ed4301974b3ff62f299a569c94526adb91a1697ab388e11dd024f734202cb58a5b035cc45e0fba772f25c690d7a8bfd3e
@@ -0,0 +1,79 @@
1
+ module HammerCLIKatello
2
+ class AcsCommand < HammerCLIKatello::Command
3
+ resource :alternate_content_sources
4
+
5
+ class ListCommand < HammerCLIKatello::ListCommand
6
+ output do
7
+ field :id, _('ID')
8
+ field :name, _('Name')
9
+ field :alternate_content_source_type, _('Type')
10
+ end
11
+
12
+ build_options
13
+ end
14
+
15
+ class CreateCommand < HammerCLIKatello::CreateCommand
16
+ success_message _('Alternate Content Source created.')
17
+ failure_message _('Could not create the Alternate Content Source.')
18
+
19
+ build_options
20
+ end
21
+
22
+ class InfoCommand < HammerCLIKatello::InfoCommand
23
+ output do
24
+ field :id, _('ID')
25
+ field :name, _('Name')
26
+ field :label, _('Label')
27
+ field :description, _('Description'), Fields::Field, :hide_blank => true
28
+ field :base_url, _('Base URL')
29
+ field :content_type, _('Content type')
30
+ field :alternate_content_source_type, _('Alternate content source type')
31
+ field :upstream_username, _('Upstream username'), Fields::Field, :hide_blank => true
32
+
33
+ collection :subpaths, _('Subpaths') do
34
+ field nil, _('')
35
+ end
36
+
37
+ collection :smart_proxies, _('Smart proxies') do
38
+ field :id, _('Id')
39
+ field :name, _('Name')
40
+ field :url, _('URL')
41
+ field :created_at, _('Created at')
42
+ field :updated_at, _('Updated at')
43
+ field :expired_logs, _('Expired logs')
44
+ field :puppet_path, _('Puppet path'), Fields::Field, :hide_blank => true
45
+ field :download_policy, _('Download policy')
46
+ end
47
+ end
48
+
49
+ build_options
50
+ end
51
+
52
+ class UpdateCommand < HammerCLIKatello::UpdateCommand
53
+ success_message _('Alternate Content Source updated.')
54
+ failure_message _('Could not update the Alternate Content Source.')
55
+
56
+ build_options
57
+ end
58
+
59
+ class DeleteCommand < HammerCLIKatello::DeleteCommand
60
+ success_message _('Alternate Content Source deleted.')
61
+ failure_message _('Could not delete the Alternate Content Source.')
62
+
63
+ build_options
64
+ end
65
+
66
+ class RefreshCommand < HammerCLIKatello::SingleResourceCommand
67
+ include HammerCLIForemanTasks::Async
68
+
69
+ action :refresh
70
+ command_name 'refresh'
71
+
72
+ success_message _("Alternate content source is being refreshed in task %{id}.")
73
+ failure_message _('Could not refresh the alternate content source')
74
+
75
+ build_options
76
+ end
77
+ autoload_subcommands
78
+ end
79
+ end
@@ -20,6 +20,14 @@ module HammerCLIKatello
20
20
  include ContentExportHelper
21
21
  end
22
22
 
23
+ class RepositoryCommand < HammerCLIKatello::SingleResourceCommand
24
+ desc _("Performs a full export of a repository")
25
+ command_name "repository"
26
+
27
+ include HammerCLIForemanTasks::Async
28
+ include ContentExportHelper
29
+ end
30
+
23
31
  autoload_subcommands
24
32
  end
25
33
  end
@@ -1,4 +1,5 @@
1
1
  require 'hammer_cli_katello/repository'
2
+
2
3
  # rubocop:disable ModuleLength
3
4
  module HammerCLIKatello
4
5
  module ContentExportHelper
@@ -40,7 +41,8 @@ module HammerCLIKatello
40
41
  end
41
42
 
42
43
  def fetch_export_history(export_history_id)
43
- index(:content_exports, :id => export_history_id).first if export_history_id
44
+ return unless export_history_id
45
+ index(:content_exports, :id => export_history_id).first
44
46
  end
45
47
 
46
48
  def fetch_export_history_from_task(task)
@@ -48,7 +50,6 @@ module HammerCLIKatello
48
50
  if %w(error warning).include?(task['result'])
49
51
  raise _("Can not fetch export history from an unfinished task")
50
52
  end
51
-
52
53
  export_history_id = task.dig('output', 'export_history_id')
53
54
  fetch_export_history(export_history_id)
54
55
  end
@@ -72,7 +73,16 @@ module HammerCLIKatello
72
73
  self.class.command_name.first.to_sym == :version
73
74
  end
74
75
 
76
+ def repository_command?
77
+ self.class.command_name.first.to_sym == :repository
78
+ end
79
+
75
80
  def fetch_repositories
81
+ if repository_command?
82
+ resp = show(:repositories, id: resolver.repository_id(options))
83
+ return resp["download_policy"] == "immediate" ? [] : [resp]
84
+ end
85
+
76
86
  repo_options = {
77
87
  library: true,
78
88
  content_type: 'yum',
@@ -95,6 +105,10 @@ module HammerCLIKatello
95
105
  " Update the download policy and sync affected repositories."\
96
106
  " Once synced republish the content view"\
97
107
  " and export the generated version.")
108
+ elsif repository_command?
109
+ output.print_message _("NOTE: Unable to fully export this repository because"\
110
+ " it does not have the 'immediate' download policy."\
111
+ " Update the download policy, sync the repository and export.")
98
112
  else
99
113
  output.print_message _("NOTE: Unable to fully export this organization's library because"\
100
114
  " it contains repositories without the 'immediate' download policy."\
@@ -107,7 +121,7 @@ module HammerCLIKatello
107
121
  "--download-policy='immediate'"
108
122
  output.print_message ""
109
123
  print_record(::HammerCLIKatello::Repository::ListCommand.output_definition, repos)
110
- exit(HammerCLI::EX_SOFTWARE) if option_fail_on_missing_content?
124
+ exit(HammerCLI::EX_SOFTWARE) if repository_command? || option_fail_on_missing_content?
111
125
  end
112
126
  end
113
127
 
@@ -116,6 +130,44 @@ module HammerCLIKatello
116
130
  setup_version(base)
117
131
  elsif base.command_name.first.to_sym == :library
118
132
  setup_library(base)
133
+ elsif base.command_name.first.to_sym == :repository
134
+ setup_repository(base)
135
+ end
136
+ end
137
+
138
+ def self.setup_repository(base)
139
+ base.action(:repository)
140
+ base.success_message _("Repository is being exported in task %{id}.")
141
+ base.failure_message _("Could not export the repository")
142
+
143
+ base.option "--name", "NAME", _("Filter repositories by name."),
144
+ :attribute_name => :option_name,
145
+ :required => false
146
+
147
+ base.build_options do |o|
148
+ o.expand(:all).including(:products, :organizations)
149
+ end
150
+
151
+ base.validate_options do
152
+ any(:option_id, :option_name).required
153
+ unless option(:option_id).exist?
154
+ any(
155
+ :option_product_id,
156
+ :option_product_name
157
+ ).required
158
+ unless option(:option_product_id).exist?
159
+ any(:option_organization_id, :option_organization_name, \
160
+ :option_organization_label).required
161
+ end
162
+ end
163
+ end
164
+
165
+ base.class_eval do
166
+ def request_params
167
+ super.tap do |opts|
168
+ opts["id"] = resolver.repository_id(options)
169
+ end
170
+ end
119
171
  end
120
172
  end
121
173
 
@@ -20,6 +20,14 @@ module HammerCLIKatello
20
20
  include ContentExportHelper
21
21
  end
22
22
 
23
+ class RepositoryCommand < HammerCLIKatello::SingleResourceCommand
24
+ desc _("Performs an incremental export of a repository")
25
+ command_name "repository"
26
+
27
+ include HammerCLIForemanTasks::Async
28
+ include ContentExportHelper
29
+ end
30
+
23
31
  autoload_subcommands
24
32
  end
25
33
  end
@@ -58,6 +58,15 @@ module HammerCLIKatello
58
58
  include ContentImportCommon
59
59
  end
60
60
 
61
+ class RepositoryCommand < HammerCLIKatello::SingleResourceCommand
62
+ desc _("Imports a repository")
63
+ action :repository
64
+ command_name "repository"
65
+
66
+ include HammerCLIForemanTasks::Async
67
+ include ContentImportCommon
68
+ end
69
+
61
70
  class ListCommand < HammerCLIKatello::ListCommand
62
71
  desc "View content view import histories"
63
72
  output do
@@ -143,6 +143,8 @@ module HammerCLIKatello
143
143
  success_message _("Host collection updated.")
144
144
  failure_message _("Could not update the the host collection")
145
145
 
146
+ option "--unlimited-hosts", :flag, "Set hosts max to unlimited"
147
+
146
148
  build_options { |o| o.expand(:all).including(:organizations) }
147
149
  end
148
150
 
@@ -29,8 +29,9 @@ module HammerCLIKatello
29
29
  :sync_plan => [s_name(_("Sync plan name to search by"))],
30
30
  :task => [s_name(_("Task name to search by"))],
31
31
  :content_view_version => [s("version", _("Content view version number"))],
32
- :content_export => [],
33
- :content_import => []
32
+ :content_export => [],
33
+ :content_export_incremental => [],
34
+ :content_import => []
34
35
  }.freeze
35
36
 
36
37
  DEFAULT_SEARCHABLES = [s_name(_("Name to search by"))].freeze
@@ -24,6 +24,7 @@ module HammerCLIKatello
24
24
  field :service_levels, _("Service Levels"), Fields::List
25
25
  from :cdn_configuration do
26
26
  label "CDN configuration", hide_blank: true do
27
+ field :type_label, _("Type"), Fields::Field
27
28
  field :url, _("URL"), Fields::Field, hide_blank: true
28
29
  field :upstream_organization_label, _("Upstream Organization"),
29
30
  Fields::Field, hide_blank: true
@@ -39,9 +40,19 @@ module HammerCLIKatello
39
40
  else
40
41
  _("Disabled")
41
42
  end
43
+ setup_cdn_type(data)
42
44
  data
43
45
  end
44
46
 
47
+ def setup_cdn_type(data)
48
+ types = {
49
+ 'export_sync' => _("Export Sync"),
50
+ 'network_sync' => _("Network Sync"),
51
+ 'redhat_cdn' => _("Red Hat CDN")
52
+ }
53
+ data["cdn_configuration"].merge!("type_label" => types[data["cdn_configuration"]["type"]])
54
+ end
55
+
45
56
  build_options
46
57
  end
47
58
 
@@ -56,7 +56,7 @@ module HammerCLIKatello
56
56
  field :_redhat_repo, _("Red Hat Repository")
57
57
  field :content_type, _("Content Type")
58
58
  field :checksum_type, _("Checksum Type"), Fields::Field, :hide_blank => true
59
- field :_mirror_on_sync, _("Mirror on Sync")
59
+ field :_mirroring_policy, _("Mirroring Policy"), Fields::Field, :hide_blank => true
60
60
  field :url, _("Url")
61
61
  field :_publish_via_http, _("Publish Via HTTP")
62
62
  field :full_path, _("Published At")
@@ -126,6 +126,7 @@ module HammerCLIKatello
126
126
 
127
127
  setup_sync_state(data)
128
128
  setup_booleans(data)
129
+ setup_mirroring_policy(data)
129
130
  setup_content_counts(data) if data["content_counts"]
130
131
  data
131
132
  end
@@ -133,7 +134,16 @@ module HammerCLIKatello
133
134
  def setup_booleans(data)
134
135
  data["_redhat_repo"] = data.dig("product", "redhat") ? _("yes") : _("no")
135
136
  data["_publish_via_http"] = data["unprotected"] ? _("yes") : _("no")
136
- data["_mirror_on_sync"] = data["mirror_on_sync"] ? _("yes") : _("no")
137
+ end
138
+
139
+ def setup_mirroring_policy(data)
140
+ policies = {
141
+ 'additive' => _("Additive"),
142
+ 'mirror_content_only' => _("Content Only"),
143
+ 'mirror_complete' => _("Complete Mirroring")
144
+ }
145
+ mirroring_policy = data["mirroring_policy"]
146
+ data["_mirroring_policy"] = policies[mirroring_policy]
137
147
  end
138
148
 
139
149
  def setup_sync_state(data)
@@ -530,7 +540,6 @@ module HammerCLIKatello
530
540
  end
531
541
  end
532
542
  end
533
- # rubocop:enable ClassLength
534
543
 
535
544
  class RemoveContentCommand < HammerCLIKatello::SingleResourceCommand
536
545
  extend RepositoryScopedToProduct
@@ -558,6 +567,59 @@ module HammerCLIKatello
558
567
  end
559
568
  end
560
569
 
570
+ class RepublishCommand < HammerCLIKatello::SingleResourceCommand
571
+ extend RepositoryScopedToProduct
572
+ include HammerCLIForemanTasks::Async
573
+ include OrganizationOptions
574
+
575
+ validate_repo_name_requires_product_options
576
+ action :republish
577
+ command_name "republish"
578
+ desc _("Forces a republish of the specified repository.")
579
+
580
+ success_message _("Repository republished.")
581
+ failure_message _("Could not republish the repository.")
582
+
583
+ validate_options :before, 'IdResolution' do
584
+ organization_options = [:option_organization_id, :option_organization_name, \
585
+ :option_organization_label]
586
+
587
+ if option(:option_product_name).exist?
588
+ any(*organization_options).required
589
+ end
590
+ end
591
+
592
+ build_options do |o|
593
+ o.expand.including(:products)
594
+ end
595
+ end
596
+
597
+ class ReclaimSpaceCommand < HammerCLIKatello::SingleResourceCommand
598
+ extend RepositoryScopedToProduct
599
+ include HammerCLIForemanTasks::Async
600
+ include OrganizationOptions
601
+ validate_repo_name_requires_product_options
602
+ action :reclaim_space
603
+ command_name "reclaim-space"
604
+ desc _("Reclaim space from an On Demand repository")
605
+
606
+ success_message _("Repository space reclaimed.")
607
+ failure_message _("Could not reclaim the repository")
608
+
609
+ validate_options :before, 'IdResolution' do
610
+ organization_options = [:option_organization_id, :option_organization_name, \
611
+ :option_organization_label]
612
+
613
+ if option(:option_product_name).exist?
614
+ any(*organization_options).required
615
+ end
616
+ end
617
+
618
+ build_options do |o|
619
+ o.expand.including(:products)
620
+ end
621
+ end
622
+ # rubocop:enable ClassLength
561
623
  autoload_subcommands
562
624
  end
563
625
  end
@@ -1,5 +1,5 @@
1
1
  module HammerCLIKatello
2
2
  def self.version
3
- @version ||= Gem::Version.new('1.4.0')
3
+ @version ||= Gem::Version.new('1.5.1')
4
4
  end
5
5
  end
@@ -43,6 +43,11 @@ module HammerCLIKatello
43
43
  'hammer_cli_katello/organization'
44
44
  )
45
45
 
46
+ HammerCLI::MainCommand.lazy_subcommand!("alternate-content-sources", _("Manipulate alternate content sources"), # rubocop:disable LineLength
47
+ 'HammerCLIKatello::AcsCommand',
48
+ 'hammer_cli_katello/acs'
49
+ )
50
+
46
51
  HammerCLI::MainCommand.lazy_subcommand("content-credentials",
47
52
  _("Manipulate content credentials on the server"),
48
53
  'HammerCLIKatello::ContentCredentialCommand',