hammer_cli_katello 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +1 -0
  3. data/lib/hammer_cli_katello/activation_key.rb +8 -6
  4. data/lib/hammer_cli_katello/capsule.rb +2 -21
  5. data/lib/hammer_cli_katello/commands.rb +2 -2
  6. data/lib/hammer_cli_katello/content_host.rb +3 -49
  7. data/lib/hammer_cli_katello/content_view.rb +19 -4
  8. data/lib/hammer_cli_katello/content_view_puppet_module.rb +8 -0
  9. data/lib/hammer_cli_katello/content_view_version.rb +69 -20
  10. data/lib/hammer_cli_katello/host.rb +4 -0
  11. data/lib/hammer_cli_katello/host_collection.rb +3 -22
  12. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  13. data/lib/hammer_cli_katello/host_subscription.rb +31 -0
  14. data/lib/hammer_cli_katello/id_resolver.rb +45 -65
  15. data/lib/hammer_cli_katello/katello_environment_name_resolvable.rb +33 -0
  16. data/lib/hammer_cli_katello/lifecycle_environment_name_resolvable.rb +1 -13
  17. data/lib/hammer_cli_katello/ping.rb +4 -0
  18. data/lib/hammer_cli_katello/repository.rb +10 -8
  19. data/lib/hammer_cli_katello/search_options_creators.rb +70 -0
  20. data/lib/hammer_cli_katello/version.rb +1 -1
  21. data/test/data/3.0/foreman_api.json +1 -0
  22. data/test/functional/activaton_key/list_test.rb +69 -0
  23. data/test/functional/content_view/content_view_helpers.rb +10 -0
  24. data/test/functional/content_view/create_test.rb +119 -0
  25. data/test/functional/content_view/list_test.rb +67 -0
  26. data/test/functional/content_view/version/incremental_update_test.rb +91 -0
  27. data/test/functional/host/errata/apply_test.rb +46 -0
  28. data/test/functional/host/host_helpers.rb +10 -0
  29. data/test/functional/host/subscription/register_test.rb +53 -0
  30. data/test/functional/host/subscription/unregister_test.rb +37 -0
  31. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +17 -0
  32. data/test/functional/organization/organization_helpers.rb +10 -0
  33. data/test/functional/ping_test.rb +19 -0
  34. data/test/functional/product/product_helpers.rb +8 -0
  35. data/test/functional/repository/info_test.rb +46 -0
  36. data/test/functional/repository/list_test.rb +69 -0
  37. data/test/functional/repository/repository_helpers.rb +9 -0
  38. data/test/functional/repository/synchronize_test.rb +57 -0
  39. data/test/functional/repository/upload_test.rb +86 -0
  40. data/test/task_helper.rb +7 -0
  41. data/test/test_helper.rb +16 -3
  42. data/test/unit/id_resolver_test.rb +32 -0
  43. data/test/unit/search_options_creators_test.rb +107 -0
  44. metadata +53 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b5a3be27eb8f7e7652ea66673432162879a55d9
4
- data.tar.gz: a6205c061e84fca880057d9369650271300dad5b
3
+ metadata.gz: 479861dfdbc99ab869476405b911f43cd02672ac
4
+ data.tar.gz: d7497c5d258268d20a953ae4a0690d9d74b5014e
5
5
  SHA512:
6
- metadata.gz: ca9eb16c655bff58be0162b0933bf50fe2ed3361bc79c429aa2001550564dee28bff7e8344f31fd1196b2843b9d4eb8f1124bd22f76a92f69332eefb561a00a6
7
- data.tar.gz: bb7008968db6aec201bf65774fd4882664ced950ce8a36941e6622e1b89264c0bb1dcbe11142ce31f179e8c97c6bf7afc2ba18df43dc08087eda4b2bdedc5da6
6
+ metadata.gz: 92377f9a91f074f9bed31e5b6c4b239eee4b841ed69a801bbd5d6d49b1fcd666507dfe25cd07d781f01f910880d7cfbcda5f2e988f321e67f5da5a9694baab5b
7
+ data.tar.gz: bf30d08e52fbe4a85162b695c7e48a81f688d1a14859125a8a0bd24e27aeb5c85721a417589e42b31297be6e77d56c7ddf0a1170253346df97a57d49db7869ae
@@ -13,6 +13,7 @@ module HammerCLIKatello
13
13
 
14
14
  require 'hammer_cli_katello/output/fields'
15
15
  require 'hammer_cli_katello/output/formatters'
16
+ require 'hammer_cli_katello/katello_environment_name_resolvable'
16
17
  require 'hammer_cli_katello/lifecycle_environment_name_resolvable'
17
18
  require 'hammer_cli_katello/repository_scoped_to_product'
18
19
  require "hammer_cli_katello/commands"
@@ -4,7 +4,7 @@ module HammerCLIKatello
4
4
  resource :activation_keys
5
5
 
6
6
  class ListCommand < HammerCLIKatello::ListCommand
7
- include LifecycleEnvironmentNameResolvable
7
+ include KatelloEnvironmentNameResolvable
8
8
  action :index
9
9
 
10
10
  output do
@@ -32,7 +32,7 @@ module HammerCLIKatello
32
32
  end
33
33
 
34
34
  class InfoCommand < HammerCLIKatello::InfoCommand
35
- include LifecycleEnvironmentNameResolvable
35
+ include KatelloEnvironmentNameResolvable
36
36
  action :show
37
37
 
38
38
  def request_params
@@ -73,7 +73,7 @@ module HammerCLIKatello
73
73
  end
74
74
 
75
75
  class CreateCommand < HammerCLIKatello::CreateCommand
76
- include LifecycleEnvironmentNameResolvable
76
+ include KatelloEnvironmentNameResolvable
77
77
  action :create
78
78
  success_message _("Activation key created")
79
79
  failure_message _("Could not create the activation key")
@@ -88,7 +88,7 @@ module HammerCLIKatello
88
88
  end
89
89
 
90
90
  class CopyCommand < HammerCLIKatello::CreateCommand
91
- include LifecycleEnvironmentNameResolvable
91
+ include KatelloEnvironmentNameResolvable
92
92
  action :copy
93
93
 
94
94
  desc _("Copy an activation key")
@@ -101,11 +101,13 @@ module HammerCLIKatello
101
101
  end
102
102
 
103
103
  class UpdateCommand < HammerCLIKatello::UpdateCommand
104
- include LifecycleEnvironmentNameResolvable
104
+ include KatelloEnvironmentNameResolvable
105
105
  action :update
106
106
  success_message _("Activation key updated")
107
107
  failure_message _("Could not update the activation key")
108
108
 
109
+ option "--unlimited-hosts", :flag, "set hosts max to unlimited"
110
+
109
111
  validate_options do
110
112
  all(:option_unlimited_hosts, :option_max_hosts).rejected
111
113
  end
@@ -114,7 +116,7 @@ module HammerCLIKatello
114
116
  end
115
117
 
116
118
  class DeleteCommand < HammerCLIKatello::DeleteCommand
117
- include LifecycleEnvironmentNameResolvable
119
+ include KatelloEnvironmentNameResolvable
118
120
  action :destroy
119
121
  success_message _("Activation key deleted")
120
122
  failure_message _("Could not delete the activation key")
@@ -2,26 +2,6 @@ require 'hammer_cli_foreman/smart_proxy'
2
2
 
3
3
  module HammerCLIKatello
4
4
  module Capsule
5
- module LifecycleEnvironmentNameResolvable
6
- def lifecycle_environment_resolve_options(options)
7
- {
8
- HammerCLI.option_accessor_name("name") => options['option_environment_name'],
9
- HammerCLI.option_accessor_name("id") => options['option_environment_id'],
10
- HammerCLI.option_accessor_name("organization_id") => options["option_organization_id"],
11
- HammerCLI.option_accessor_name("organization_name") => options["option_organization_name"]
12
- }
13
- end
14
-
15
- def all_options
16
- result = super.clone
17
- if result['option_environment_name']
18
- result['option_environment_id'] = resolver.lifecycle_environment_id(
19
- lifecycle_environment_resolve_options(result))
20
- end
21
- result
22
- end
23
- end
24
-
25
5
  class Content < HammerCLIKatello::Command
26
6
  command_name 'content'
27
7
  desc _('Manage the capsule content')
@@ -90,7 +70,8 @@ module HammerCLIKatello
90
70
  build_options
91
71
  end
92
72
 
93
- class SyncCommand < HammerCLIForemanTasks::AsyncCommand
73
+ class SyncCommand < HammerCLIKatello::SingleResourceCommand
74
+ include HammerCLIForemanTasks::Async
94
75
  include LifecycleEnvironmentNameResolvable
95
76
  resource :capsule_content, :sync
96
77
  command_name "synchronize"
@@ -2,7 +2,7 @@ module HammerCLIKatello
2
2
 
3
3
  RESOURCE_NAME_MAPPING = {
4
4
  :system => :content_host
5
- }
5
+ }.freeze
6
6
 
7
7
  module ResolverCommons
8
8
 
@@ -23,7 +23,7 @@ module HammerCLIKatello
23
23
  end
24
24
 
25
25
  def resource_name_mapping
26
- HammerCLIKatello::RESOURCE_NAME_MAPPING
26
+ HammerCLIKatello::RESOURCE_NAME_MAPPING.dup
27
27
  end
28
28
 
29
29
  end
@@ -9,7 +9,7 @@ module HammerCLIKatello
9
9
  end
10
10
 
11
11
  class ListCommand < HammerCLIKatello::ListCommand
12
- include LifecycleEnvironmentNameResolvable
12
+ include KatelloEnvironmentNameResolvable
13
13
  resource :systems, :index
14
14
 
15
15
  output do
@@ -24,7 +24,7 @@ module HammerCLIKatello
24
24
  end
25
25
 
26
26
  class InfoCommand < HammerCLIKatello::InfoCommand
27
- include LifecycleEnvironmentNameResolvable
27
+ include KatelloEnvironmentNameResolvable
28
28
  include IdDescriptionOverridable
29
29
  resource :systems, :show
30
30
 
@@ -32,7 +32,6 @@ module HammerCLIKatello
32
32
  field :name, _("Name")
33
33
  field :uuid, _("ID")
34
34
  field :katello_agent_installed, _("Katello Agent Installed"), Fields::Boolean
35
- field :description, _("Description")
36
35
  field :location, _("Location")
37
36
  from :environment do
38
37
  field :name, _("Lifecycle Environment")
@@ -53,34 +52,9 @@ module HammerCLIKatello
53
52
  build_options
54
53
  end
55
54
 
56
- class CreateCommand < HammerCLIKatello::CreateCommand
57
- include LifecycleEnvironmentNameResolvable
58
- resource :systems, :create
59
-
60
- output InfoCommand.output_definition
61
-
62
- success_message _("Content host created")
63
- failure_message _("Could not create content host")
64
-
65
- def request_params
66
- super.tap do |params|
67
- params['type'] = "system"
68
- params['facts'] = {"uname.machine" => "unknown"}
69
- end
70
- end
71
-
72
- validate_options do
73
- if any(:option_environment_id, :option_environment_name).exist?
74
- any(:option_content_view_name, :option_content_view_id).required
75
- end
76
- end
77
-
78
- build_options :without => [:facts, :type, :installed_products]
79
- end
80
-
81
55
  class UpdateCommand < HammerCLIKatello::UpdateCommand
82
56
  include IdDescriptionOverridable
83
- include LifecycleEnvironmentNameResolvable
57
+ include KatelloEnvironmentNameResolvable
84
58
  resource :systems, :update
85
59
 
86
60
  success_message _("Content host updated")
@@ -95,26 +69,6 @@ module HammerCLIKatello
95
69
  build_options :without => [:facts, :type, :installed_products]
96
70
  end
97
71
 
98
- class DeleteCommand < HammerCLIKatello::DeleteCommand
99
- include IdDescriptionOverridable
100
- include LifecycleEnvironmentNameResolvable
101
- resource :systems, :destroy
102
-
103
- success_message _("Content host deleted")
104
- failure_message _("Could not delete content host")
105
-
106
- build_options
107
- end
108
-
109
- class TasksCommand < HammerCLIKatello::ListCommand
110
- include IdDescriptionOverridable
111
- resource :systems, :tasks
112
-
113
- command_name "tasks"
114
-
115
- build_options
116
- end
117
-
118
72
  class AvailableIncrementalUpdates < HammerCLIKatello::ListCommand
119
73
  resource :systems_bulk_actions, :available_incremental_updates
120
74
  command_name 'available-incremental-updates'
@@ -8,7 +8,7 @@ module HammerCLIKatello
8
8
  resource :content_views
9
9
 
10
10
  class ListCommand < HammerCLIKatello::ListCommand
11
- include LifecycleEnvironmentNameResolvable
11
+ include KatelloEnvironmentNameResolvable
12
12
  output do
13
13
  field :id, _("Content View ID")
14
14
  field :name, _("Name")
@@ -106,7 +106,21 @@ module HammerCLIKatello
106
106
  end
107
107
  end
108
108
 
109
- build_options
109
+ validate_options do
110
+ product_options = [:option_product_id, :option_product_name]
111
+ if option(:option_repository_ids).exist?
112
+ any(*product_options).rejected
113
+ option(:option_repository_names).rejected
114
+ end
115
+
116
+ if option(:option_repository_names).exist?
117
+ any(*product_options).required
118
+ end
119
+ end
120
+
121
+ build_options do |o|
122
+ o.expand.including(:products)
123
+ end
110
124
  end
111
125
 
112
126
  class CopyCommand < HammerCLIKatello::CreateCommand
@@ -154,7 +168,7 @@ module HammerCLIKatello
154
168
  end
155
169
 
156
170
  class RemoveFromEnvironmentCommand < HammerCLIKatello::SingleResourceCommand
157
- include LifecycleEnvironmentNameResolvable
171
+ include KatelloEnvironmentNameResolvable
158
172
  include HammerCLIForemanTasks::Async
159
173
 
160
174
  action :remove_from_environment
@@ -195,6 +209,7 @@ module HammerCLIKatello
195
209
 
196
210
  class AddContentViewVersionCommand < HammerCLIKatello::AddAssociatedCommand
197
211
  command_name 'add-version'
212
+ desc _('Add a content view version to a composite view')
198
213
 
199
214
  def association_name(plural = false)
200
215
  plural ? "components" : "component"
@@ -209,7 +224,7 @@ module HammerCLIKatello
209
224
 
210
225
  class RemoveContentViewVersionCommand < HammerCLIKatello::RemoveAssociatedCommand
211
226
  command_name 'remove-version'
212
- desc _('Remove a version of a content view')
227
+ desc _('Remove a content view version from a composite view')
213
228
 
214
229
  def association_name(plural = false)
215
230
  plural ? "components" : "component"
@@ -33,6 +33,14 @@ module HammerCLIKatello
33
33
  failure_message _("Could not add the puppet module")
34
34
 
35
35
  build_options
36
+
37
+ # rubocop:disable Style/AccessorMethodName:
38
+ def get_identifier
39
+ # This will intentionally disable the id resolver. Without it, if the user were to
40
+ # execute the 'add' command specifying a 'name', the id resolver will attempt to
41
+ # translate the 'name' to an 'id'. That is not desirable for this command.
42
+ nil
43
+ end
36
44
  end
37
45
 
38
46
  class DeleteCommand < HammerCLIKatello::DeleteCommand
@@ -132,33 +132,68 @@ module HammerCLIKatello
132
132
  success_message _("Incremental update is being performed with task %{id}")
133
133
  failure_message _("An error occurred incrementally updating the content view")
134
134
 
135
- option('--environment-ids',
136
- 'ENVIRONMENTS',
137
- _("list of environment IDs to update the content view version in"),
138
- :required => true,
135
+ option('--lifecycle-environment-ids',
136
+ 'ENVIRONMENT_IDS',
137
+ _("list of lifecycle environment IDs to update the content view version in"),
139
138
  :format => HammerCLI::Options::Normalizers::List.new
140
139
  )
141
140
 
142
- option('--content-host-ids',
143
- 'CONTENT_HOST_IDS',
144
- _("IDs of content hosts to update"),
141
+ option('--lifecycle-environments',
142
+ 'ENVIRONMENTS',
143
+ _("list of lifecycle environment names to update the content view version in"),
144
+ :format => HammerCLI::Options::Normalizers::List.new,
145
+ :attribute_name => :option_lifecycle_environment_names
146
+ )
147
+
148
+ option('--organization',
149
+ 'ORGANIZATION_NAME',
150
+ _("Organization name for resolving lifecycle environment names"),
151
+ :attribute_name => :option_organization_name
152
+ )
153
+
154
+ option('--organization-id',
155
+ 'ORGANIZATION_ID',
156
+ _("Organization id for resolving lifecycle environment names")
157
+ )
158
+
159
+ option('--update-all-hosts',
160
+ 'UPDATE',
161
+ _('Update all editable and applicable hosts within the specified Content View and \
162
+ Lifecycle Environments'),
163
+ :format => HammerCLI::Options::Normalizers::Bool.new
164
+ )
165
+
166
+ option('--host-ids',
167
+ 'HOST_IDS',
168
+ _("IDs of hosts to update"),
145
169
  :format => HammerCLI::Options::Normalizers::List.new
146
170
  )
147
171
 
172
+ validate_options do
173
+ organization_options = [:option_organization_id, :option_organization_name]
174
+
175
+ if option(:option_lifecycle_environment_ids).exist?
176
+ any(*organization_options).rejected
177
+ option(:option_lifecycle_environment_names).rejected
178
+ end
179
+
180
+ if option(:option_lifecycle_environment_names).exist?
181
+ any(*organization_options).required
182
+ end
183
+ end
184
+
148
185
  def request_params
149
186
  params = super
150
-
151
187
  params[:content_view_version_environments] = [
152
188
  {
153
- :environment_ids => option_environment_ids,
154
189
  :content_view_version_id => option_content_view_version_id
155
190
  }
156
191
  ]
157
192
 
158
- if params['update_systems']['included'].key?('ids')
159
- params['update_systems'].delete('excluded')
160
- else
161
- params.delete('update_systems')
193
+ if options.key?(HammerCLI.option_accessor_name(:lifecycle_environment_names)) ||
194
+ options.key?(HammerCLI.option_accessor_name(:lifecycle_environment_ids))
195
+ params[:content_view_version_environments][0][:environment_ids] =
196
+ resolver.environment_ids(options)
162
197
  end
163
198
 
164
199
  add_content = {}
@@ -166,19 +201,33 @@ module HammerCLIKatello
166
201
  add_content[key] = value if options.key?(HammerCLI.option_accessor_name(key))
167
202
  end
168
203
 
169
- if option_content_host_ids
170
- params['update_systems'] = {'included' => {'ids' => option_content_host_ids}}
171
- end
172
-
204
+ params = request_params_hosts(params)
173
205
  params['add_content'] = add_content
174
206
 
175
207
  params.delete('id')
176
208
  params
177
209
  end
178
210
 
179
- build_options do |opt|
180
- opt.expand(:all)
181
- opt.without(:content_view_version_environments, :ids)
211
+ def request_params_hosts(params)
212
+ if params['update_hosts'] && params['update_hosts']['included'] &&
213
+ params['update_hosts']['included'].key?('ids')
214
+ params['update_hosts'].delete('excluded')
215
+ else
216
+ params.delete('update_hosts')
217
+ end
218
+
219
+ if option_host_ids
220
+ params['update_hosts'] = {'included' => {'ids' => option_host_ids}}
221
+ elsif option_update_all_hosts
222
+ params['update_hosts'] = { 'included' => {:search => ''}}
223
+ end
224
+
225
+ params
226
+ end
227
+
228
+ build_options do |o|
229
+ o.expand(:all).except(:environments)
230
+ o.without(:content_view_version_environments, :ids, :update_hosts, :update_hosts_included)
182
231
  end
183
232
  end
184
233
 
@@ -1,5 +1,6 @@
1
1
  require 'hammer_cli_foreman/host'
2
2
  require 'hammer_cli_katello/host_errata'
3
+ require 'hammer_cli_katello/host_subscription'
3
4
  require 'hammer_cli_katello/host_package'
4
5
  require 'hammer_cli_katello/host_package_group'
5
6
 
@@ -16,4 +17,7 @@ module HammerCLIKatello
16
17
  HammerCLIKatello::HostPackageGroup.desc,
17
18
  HammerCLIKatello::HostPackageGroup
18
19
 
20
+ HammerCLIForeman::Host.subcommand "subscription",
21
+ HammerCLIKatello::HostSubscription.desc,
22
+ HammerCLIKatello::HostSubscription
19
23
  end
@@ -3,22 +3,6 @@ module HammerCLIKatello
3
3
  class HostCollection < HammerCLIKatello::Command
4
4
  resource :host_collections
5
5
 
6
- module UuidRequestable
7
- def self.included(base)
8
- base.option("--host-collection-ids",
9
- "HOST_COLLECTION_IDS",
10
- _("Array of host ids to replace the hosts in host collection"),
11
- :format => HammerCLI::Options::Normalizers::List.new)
12
- end
13
-
14
- def request_params
15
- params = super
16
- params['host_ids'] = option_host_ids unless option_host_ids.nil?
17
- params.delete('host_ids') if params.keys.include? 'host_ids'
18
- params
19
- end
20
- end
21
-
22
6
  module LimitFieldDataExtension
23
7
  def extend_data(data)
24
8
  data['_limit'] = data['unlimited_hosts'] ? 'None' : data['max_hosts']
@@ -52,10 +36,8 @@ module HammerCLIKatello
52
36
 
53
37
  success_message _("Host collection created")
54
38
  failure_message _("Could not create the host collection")
55
- build_options do |o|
56
- o.expand.except(:hosts)
57
- o.without(:host_ids)
58
- end
39
+
40
+ build_options
59
41
  end
60
42
 
61
43
  class InfoCommand < HammerCLIKatello::InfoCommand
@@ -98,11 +80,10 @@ module HammerCLIKatello
98
80
  end
99
81
 
100
82
  class UpdateCommand < HammerCLIKatello::UpdateCommand
101
- include UuidRequestable
102
83
  success_message _("Host collection updated")
103
84
  failure_message _("Could not update the the host collection")
104
85
 
105
- build_options :without => [:host_ids]
86
+ build_options
106
87
  end
107
88
 
108
89
  class DeleteCommand < HammerCLIKatello::DeleteCommand