hammer_cli_katello 0.11.5.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +5 -0
  3. data/lib/hammer_cli_katello/content_view.rb +22 -8
  4. data/lib/hammer_cli_katello/file.rb +72 -0
  5. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +34 -34
  6. data/lib/hammer_cli_katello/host_collection.rb +18 -0
  7. data/lib/hammer_cli_katello/host_content_source_options.rb +25 -0
  8. data/lib/hammer_cli_katello/host_extensions.rb +34 -3
  9. data/lib/hammer_cli_katello/host_kickstart_repository_options.rb +49 -0
  10. data/lib/hammer_cli_katello/hostgroup_extensions.rb +25 -3
  11. data/lib/hammer_cli_katello/id_resolver.rb +15 -9
  12. data/lib/hammer_cli_katello/repository.rb +47 -1
  13. data/lib/hammer_cli_katello/search_options_creators.rb +23 -16
  14. data/lib/hammer_cli_katello/sync_plan.rb +5 -0
  15. data/lib/hammer_cli_katello/version.rb +1 -1
  16. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +3 -3
  17. data/test/functional/capsule/content/cancel_synchronization_test.rb +3 -3
  18. data/test/functional/capsule/content/info_test.rb +3 -3
  19. data/test/functional/capsule/content/lifecycle_environments_test.rb +1 -1
  20. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +3 -3
  21. data/test/functional/capsule/content/synchronization_status_test.rb +3 -3
  22. data/test/functional/content_view/content_view_helpers.rb +4 -0
  23. data/test/functional/content_view/create_test.rb +2 -2
  24. data/test/functional/content_view/filter/delete_test.rb +1 -4
  25. data/test/functional/content_view/filter/info_test.rb +1 -4
  26. data/test/functional/content_view/filter/list_test.rb +1 -1
  27. data/test/functional/content_view/filter/update_test.rb +1 -4
  28. data/test/functional/erratum/list_test.rb +1 -1
  29. data/test/functional/file/file_helpers.rb +13 -0
  30. data/test/functional/file/info_test.rb +162 -0
  31. data/test/functional/file/list_test.rb +112 -0
  32. data/test/functional/filter_rule/info_test.rb +1 -1
  33. data/test/functional/filter_rule/update_test.rb +1 -1
  34. data/test/functional/host/extensions/create_test.rb +95 -0
  35. data/test/functional/host/extensions/data/host.json +4 -0
  36. data/test/functional/host/extensions/info_test.rb +5 -3
  37. data/test/functional/host/extensions/update_test.rb +69 -0
  38. data/test/functional/host_collection/add_host_test.rb +36 -3
  39. data/test/functional/host_collection/copy_test.rb +4 -4
  40. data/test/functional/host_collection/delete_test.rb +3 -3
  41. data/test/functional/host_collection/hosts_test.rb +1 -2
  42. data/test/functional/host_collection/info_test.rb +3 -3
  43. data/test/functional/host_collection/remove_host_test.rb +36 -3
  44. data/test/functional/host_collection/update_test.rb +3 -3
  45. data/test/functional/hostgroup/create_test.rb +46 -1
  46. data/test/functional/hostgroup/data/hostgroup.json +48 -46
  47. data/test/functional/hostgroup/info_test.rb +5 -3
  48. data/test/functional/hostgroup/update_test.rb +48 -1
  49. data/test/functional/lifecycle_environment/create_test.rb +1 -1
  50. data/test/functional/package/list_test.rb +1 -1
  51. data/test/functional/product/product_helpers.rb +6 -4
  52. data/test/functional/repository/upload_test.rb +32 -14
  53. data/test/functional/sync_plan/info_test.rb +37 -0
  54. data/test/functional/sync_plan/list_test.rb +31 -0
  55. metadata +21 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1b17e43ccbcfaf220d361b7e38f27e0f802c9c5
4
- data.tar.gz: f40513f0493f3260beadcd2db8b0f1c1bd521c69
3
+ metadata.gz: d52505bd4dd9f8f24e11ed2d97b6209f59dcc640
4
+ data.tar.gz: 7fdacb6740cd55f57e50836cb11ab385e0db829b
5
5
  SHA512:
6
- metadata.gz: 38e9c93e7f82ef4e940df154a236bf90f0941c00846763271bd01501c9c183e72097fd10403b5e29b77ae5e28b366bb849b2b4a60de04b8d47ddcc5376cbf871
7
- data.tar.gz: d0b51c64c1e9457b9041c02670682c9ebad4c4dd013ac3f074d8033f4bc0913547163e4e81e02547a01475f04703de130f9371370711207336cac3b96842ec0c
6
+ metadata.gz: 9a90171a78059eeb5f24ed52d0fd6acd066550104f41b5d71e89f66a0558ce1d80c5917e2fdcb9acdf2b334d2d160f525447a8d2923fb266718d6ef8070c1ef9
7
+ data.tar.gz: 617c7b2d2333c6d48773674de56761bc242544efd8878d54454145c452fd134cb81d2d6ff5db2ca1e1b83ebf8aeb1079ac614db310d5bedb1b348fe1e18c7b27
@@ -121,6 +121,11 @@ module HammerCLIKatello
121
121
  'hammer_cli_katello/ostree_branch'
122
122
  )
123
123
 
124
+ HammerCLI::MainCommand.lazy_subcommand("file", _("Manipulate files"),
125
+ 'HammerCLIKatello::FileCommand',
126
+ 'hammer_cli_katello/file'
127
+ )
128
+
124
129
  # subcommands to hammer_cli_foreman commands
125
130
  require 'hammer_cli_katello/host'
126
131
  require 'hammer_cli_katello/hostgroup'
@@ -225,6 +225,18 @@ module HammerCLIKatello
225
225
  build_options
226
226
  end
227
227
 
228
+ class CVEnvParamsSource
229
+ def initialize(command)
230
+ @command = command
231
+ end
232
+
233
+ def get_options(_defined_options, result)
234
+ result['option_content_view_id'] = @command.option_id
235
+ result['option_lifecycle_environment_names'] = result['option_environment_names']
236
+ result
237
+ end
238
+ end
239
+
228
240
  class RemoveCommand < HammerCLIKatello::SingleResourceCommand
229
241
  include HammerCLIForemanTasks::Async
230
242
  include OrganizationOptions
@@ -235,15 +247,17 @@ module HammerCLIKatello
235
247
  command_name "remove"
236
248
 
237
249
  option ["--content-view-version-ids"], "VERSION_IDS",
238
- _("Comma separated list of version ids to remove")
250
+ _("Version ids to remove"),
251
+ :format => HammerCLI::Options::Normalizers::List.new
239
252
  option ["--environment-ids"], "ENVIRONMENT_IDS",
240
- _("Comma separated list of environment ids to remove")
241
-
242
- def all_options
243
- opts = super
244
- opts['option_content_view_id'] = option_id
245
- opts['option_lifecycle_environment_names'] = opts['option_environment_names']
246
- opts
253
+ _("Environment ids to remove"),
254
+ :format => HammerCLI::Options::Normalizers::List.new
255
+
256
+ def option_sources
257
+ sources = super
258
+ idx = sources.index { |s| s.class == HammerCLIForeman::OptionSources::IdParams }
259
+ sources.insert(idx, CVEnvParamsSource.new(self))
260
+ sources
247
261
  end
248
262
 
249
263
  def request_params
@@ -0,0 +1,72 @@
1
+ module HammerCLIKatello
2
+ class FileCommand < HammerCLIKatello::Command
3
+ resource :file_units
4
+
5
+ class ListCommand < HammerCLIKatello::ListCommand
6
+ output do
7
+ field :id, _("ID")
8
+ field :name, _("Name")
9
+ field :path, _("Path")
10
+ end
11
+
12
+ validate_options do
13
+ organization_options = [:option_organization_id, :option_organization_name,
14
+ :option_organization_label]
15
+ product_options = [:option_product_id, :option_product_name]
16
+
17
+ if any(:option_product_name, :option_content_view_name).exist?
18
+ any(*organization_options).required
19
+ end
20
+
21
+ if option(:option_repository_name).exist?
22
+ any(*product_options).required
23
+ end
24
+ end
25
+
26
+ build_options do |o|
27
+ o.expand.including(:products, :organizations, :content_views)
28
+ end
29
+ end
30
+
31
+ class InfoCommand < HammerCLIKatello::InfoCommand
32
+ output do
33
+ field :id, _("ID")
34
+ field :name, _("Name")
35
+ field :path, _("Path")
36
+ field :uuid, _("UUID")
37
+ field :checksum, _("Checksum")
38
+ end
39
+
40
+ validate_options do
41
+ organization_options = [:option_organization_id, :option_organization_name,
42
+ :option_organization_label]
43
+ product_options = [:option_product_id, :option_product_name]
44
+ repository_options = [:option_repository_id, :option_repository_name]
45
+ content_view_version_options = [:option_content_view_version_id,
46
+ :option_content_view_version_version]
47
+
48
+ if option(:option_product_name).exist?
49
+ any(*organization_options).required
50
+ end
51
+
52
+ if option(:option_repository_name).exist?
53
+ any(*product_options).required
54
+ end
55
+
56
+ if option(:option_name).exist?
57
+ any(*(repository_options + content_view_version_options)).required
58
+ end
59
+ end
60
+
61
+ def all_options
62
+ super.merge(options)
63
+ end
64
+
65
+ build_options do |o|
66
+ o.expand.including(:products, :organizations, :content_views, :content_view_versions)
67
+ end
68
+ end
69
+
70
+ autoload_subcommands
71
+ end
72
+ end
@@ -1,71 +1,71 @@
1
1
  module HammerCLIKatello
2
2
  module ForemanSearchOptionsCreators
3
- def create_environments_search_options(options)
4
- create_search_options_without_katello_api(options, api.resource(:environments))
3
+ def create_environments_search_options(options, mode = nil)
4
+ create_search_options_without_katello_api(options, api.resource(:environments), mode)
5
5
  end
6
6
 
7
- def create_organizations_search_options(options)
8
- create_search_options_without_katello_api(options, api.resource(:organizations))
7
+ def create_organizations_search_options(options, mode = nil)
8
+ create_search_options_without_katello_api(options, api.resource(:organizations), mode)
9
9
  end
10
10
 
11
- def create_smart_proxies_search_options(options)
12
- create_search_options_without_katello_api(options, api.resource(:smart_proxies))
11
+ def create_smart_proxies_search_options(options, mode = nil)
12
+ create_search_options_without_katello_api(options, api.resource(:smart_proxies), mode)
13
13
  end
14
14
 
15
- def create_capsules_search_options(options)
16
- create_search_options_without_katello_api(options, api.resource(:smart_proxies))
15
+ def create_capsules_search_options(options, mode = nil)
16
+ create_search_options_without_katello_api(options, api.resource(:smart_proxies), mode)
17
17
  end
18
18
 
19
- def create_hosts_search_options(options)
20
- create_search_options_without_katello_api(options, api.resource(:hosts))
19
+ def create_hosts_search_options(options, mode = nil)
20
+ create_search_options_without_katello_api(options, api.resource(:hosts), mode)
21
21
  end
22
22
 
23
- def create_architectures_search_options(options)
24
- create_search_options_without_katello_api(options, api.resource(:architectures))
23
+ def create_architectures_search_options(options, mode = nil)
24
+ create_search_options_without_katello_api(options, api.resource(:architectures), mode)
25
25
  end
26
26
 
27
- def create_operatingsystems_search_options(options)
28
- create_search_options_without_katello_api(options, api.resource(:operatingsystems))
27
+ def create_operatingsystems_search_options(options, mode = nil)
28
+ create_search_options_without_katello_api(options, api.resource(:operatingsystems), mode)
29
29
  end
30
30
 
31
- def create_domains_search_options(options)
32
- create_search_options_without_katello_api(options, api.resource(:domains))
31
+ def create_domains_search_options(options, mode = nil)
32
+ create_search_options_without_katello_api(options, api.resource(:domains), mode)
33
33
  end
34
34
 
35
- def create_locations_search_options(options)
36
- create_search_options_without_katello_api(options, api.resource(:locations))
35
+ def create_locations_search_options(options, mode = nil)
36
+ create_search_options_without_katello_api(options, api.resource(:locations), mode)
37
37
  end
38
38
 
39
- def create_media_search_options(options)
40
- create_search_options_without_katello_api(options, api.resource(:media))
39
+ def create_media_search_options(options, mode = nil)
40
+ create_search_options_without_katello_api(options, api.resource(:media), mode)
41
41
  end
42
42
 
43
- def create_hostgroups_search_options(options)
44
- create_search_options_without_katello_api(options, api.resource(:hostgroups))
43
+ def create_hostgroups_search_options(options, mode = nil)
44
+ create_search_options_without_katello_api(options, api.resource(:hostgroups), mode)
45
45
  end
46
46
 
47
- def create_ptables_search_options(options)
48
- create_search_options_without_katello_api(options, api.resource(:ptables))
47
+ def create_ptables_search_options(options, mode = nil)
48
+ create_search_options_without_katello_api(options, api.resource(:ptables), mode)
49
49
  end
50
50
 
51
- def create_puppet_ca_proxies_search_options(options)
52
- create_search_options_without_katello_api(options, api.resource(:puppet_ca_proxies))
51
+ def create_puppet_ca_proxies_search_options(options, mode = nil)
52
+ create_search_options_without_katello_api(options, api.resource(:puppet_ca_proxies), mode)
53
53
  end
54
54
 
55
- def create_puppet_proxies_search_options(options)
56
- create_search_options_without_katello_api(options, api.resource(:puppet_proxies))
55
+ def create_puppet_proxies_search_options(options, mode = nil)
56
+ create_search_options_without_katello_api(options, api.resource(:puppet_proxies), mode)
57
57
  end
58
58
 
59
- def create_puppetclasses_search_options(options)
60
- create_search_options_without_katello_api(options, api.resource(:puppetclasses))
59
+ def create_puppetclasses_search_options(options, mode = nil)
60
+ create_search_options_without_katello_api(options, api.resource(:puppetclasses), mode)
61
61
  end
62
62
 
63
- def create_subnets_search_options(options)
64
- create_search_options_without_katello_api(options, api.resource(:subnets))
63
+ def create_subnets_search_options(options, mode = nil)
64
+ create_search_options_without_katello_api(options, api.resource(:subnets), mode)
65
65
  end
66
66
 
67
- def create_realms_search_options(options)
68
- create_search_options_without_katello_api(options, api.resource(:realms))
67
+ def create_realms_search_options(options, mode = nil)
68
+ create_search_options_without_katello_api(options, api.resource(:realms), mode)
69
69
  end
70
70
  end
71
71
  end
@@ -9,6 +9,20 @@ module HammerCLIKatello
9
9
  end
10
10
  end
11
11
 
12
+ module HostCollectionUpdateHostsErrorHandler
13
+ def execute
14
+ response = send_request
15
+ if response['error'].any?
16
+ print_message(failure_message)
17
+ puts response['error'].join("\n")
18
+ HammerCLI::EX_CANTCREAT
19
+ else
20
+ print_data(response)
21
+ HammerCLI::EX_OK
22
+ end
23
+ end
24
+ end
25
+
12
26
  class ListCommand < HammerCLIKatello::ListCommand
13
27
  include LimitFieldDataExtension
14
28
  resource :host_collections, :index
@@ -129,6 +143,8 @@ module HammerCLIKatello
129
143
  end
130
144
 
131
145
  class AddHostCommand < HammerCLIKatello::SingleResourceCommand
146
+ include HostCollectionUpdateHostsErrorHandler
147
+
132
148
  command_name 'add-host'
133
149
  action :add_hosts
134
150
 
@@ -139,6 +155,8 @@ module HammerCLIKatello
139
155
  end
140
156
 
141
157
  class RemoveHostCommand < HammerCLIKatello::SingleResourceCommand
158
+ include HostCollectionUpdateHostsErrorHandler
159
+
142
160
  command_name 'remove-host'
143
161
  action :remove_hosts
144
162
 
@@ -0,0 +1,25 @@
1
+ module HammerCLIKatello
2
+ module HostContentSourceOptions
3
+ def self.included(base)
4
+ base.option "--content-source", "CONTENT_SOURCE_NAME",
5
+ _("Content Source name "),
6
+ :attribute_name => :option_content_source
7
+ end
8
+
9
+ def request_params
10
+ super.tap do |mod|
11
+ resource_name = resource.singular_name
12
+ if option_content_source && !option_content_source_id
13
+ resource_hash = if resource_name == "hostgroup"
14
+ mod[resource_name]
15
+ else
16
+ mod[resource_name]["content_facet_attributes"]
17
+ end
18
+
19
+ proxy_options = { HammerCLI.option_accessor_name('name') => option_content_source}
20
+ resource_hash["content_source_id"] = resolver.smart_proxy_id(proxy_options)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,9 +3,23 @@ require 'hammer_cli_katello/host_errata'
3
3
  require 'hammer_cli_katello/host_subscription'
4
4
  require 'hammer_cli_katello/host_package'
5
5
  require 'hammer_cli_katello/host_package_group'
6
+ require 'hammer_cli_katello/host_kickstart_repository_options'
7
+ require 'hammer_cli_katello/host_content_source_options'
6
8
 
7
9
  module HammerCLIKatello
8
10
  module HostExtensions
11
+ ::HammerCLIForeman::Host::CreateCommand.instance_eval do
12
+ include HammerCLIKatello::ResolverCommons
13
+ include HammerCLIKatello::HostContentSourceOptions
14
+ include ::HammerCLIKatello::HostKickstartRepositoryOptions
15
+ end
16
+
17
+ ::HammerCLIForeman::Host::UpdateCommand.instance_eval do
18
+ include HammerCLIKatello::ResolverCommons
19
+ include HammerCLIKatello::HostContentSourceOptions
20
+ include ::HammerCLIKatello::HostKickstartRepositoryOptions
21
+ end
22
+
9
23
  ::HammerCLIForeman::Host::ListCommand.instance_eval do
10
24
  output do
11
25
  from :content_facet_attributes do
@@ -19,9 +33,26 @@ module HammerCLIKatello
19
33
  output do
20
34
  label _('Content Information') do
21
35
  from :content_facet_attributes do
22
- field :content_view_name, _('Content View')
23
- field :lifecycle_environment_name, _('Lifecycle Environment')
24
- field :content_source_name, _('Content Source')
36
+ label _("Content View") do
37
+ field :content_view_id, _("ID")
38
+ field :content_view_name, _("Name")
39
+ end
40
+
41
+ label _("Lifecycle Environment") do
42
+ field :lifecycle_environment_id, _("ID")
43
+ field :lifecycle_environment_name, _("Name")
44
+ end
45
+
46
+ label _("Content Source") do
47
+ field :content_source_id, _("ID")
48
+ field :content_source_name, _("Name")
49
+ end
50
+
51
+ label _("Kickstart Repository") do
52
+ field :kickstart_repository_id, _("ID")
53
+ field :kickstart_repository_name, _("Name")
54
+ end
55
+
25
56
  field :applicable_package_count, _('Applicable Packages')
26
57
  field :upgradable_package_count, _('Upgradable Packages')
27
58
 
@@ -0,0 +1,49 @@
1
+ module HammerCLIKatello
2
+ module HostKickstartRepositoryOptions
3
+ def self.included(base)
4
+ base.option "--kickstart-repository", "REPOSITORY_NAME",
5
+ _("Kickstart repository name "),
6
+ :attribute_name => :option_kickstart_repository
7
+ end
8
+
9
+ def request_params
10
+ super.tap do |mod|
11
+ resource_name = resource.singular_name
12
+ if option_kickstart_repository && !option_kickstart_repository_id
13
+ resource_hash = if resource_name == "hostgroup"
14
+ mod[resource_name]
15
+ else
16
+ mod[resource_name]["content_facet_attributes"]
17
+ end
18
+
19
+ resource_hash ||= {}
20
+
21
+ env_id = resource_hash["lifecycle_environment_id"]
22
+ cv_id = resource_hash["content_view_id"]
23
+
24
+ raise _("Please provide --lifecycle-environment-id") unless env_id
25
+
26
+ raise _("Please provide --content-view-id") unless cv_id
27
+
28
+ resource_hash["kickstart_repository_id"] = fetch_repo_id(cv_id, env_id,
29
+ option_kickstart_repository)
30
+ end
31
+ end
32
+ end
33
+
34
+ def fetch_repo_id(cv_id, env_id, repo_name)
35
+ repo_resource = HammerCLIForeman.foreman_resource(:repositories)
36
+ index_options = {
37
+ "content_view_id" => cv_id,
38
+ "environment_id" => env_id,
39
+ "name" => repo_name
40
+ }
41
+ repos = repo_resource.call(:index, index_options)["results"]
42
+ if repos.empty?
43
+ raise _("No such repository with name %{name}, in lifecycle environment"\
44
+ " %{environment_id} and content view %{content_view_id}" % index_options)
45
+ end
46
+ repos.first["id"]
47
+ end
48
+ end
49
+ end
@@ -1,4 +1,6 @@
1
1
  require 'hammer_cli_foreman/hostgroup'
2
+ require 'hammer_cli_katello/host_kickstart_repository_options'
3
+ require 'hammer_cli_katello/host_content_source_options'
2
4
 
3
5
  module HammerCLIKatello
4
6
  module PuppetEnvironmentNameResolvable
@@ -39,6 +41,8 @@ module HammerCLIKatello
39
41
  include HammerCLIKatello::PuppetEnvironmentNameResolvable
40
42
  include HammerCLIKatello::ContentViewNameResolvable
41
43
  include HammerCLIKatello::QueryOrganizationOptions
44
+ include HammerCLIKatello::HostContentSourceOptions
45
+ include HammerCLIKatello::HostKickstartRepositoryOptions
42
46
  end
43
47
 
44
48
  ::HammerCLIForeman::Hostgroup::UpdateCommand.instance_eval do
@@ -46,13 +50,31 @@ module HammerCLIKatello
46
50
  include HammerCLIKatello::PuppetEnvironmentNameResolvable
47
51
  include HammerCLIKatello::ContentViewNameResolvable
48
52
  include HammerCLIKatello::QueryOrganizationOptions
53
+ include HammerCLIKatello::HostContentSourceOptions
54
+ include HammerCLIKatello::HostKickstartRepositoryOptions
49
55
  end
50
56
 
51
57
  ::HammerCLIForeman::Hostgroup::InfoCommand.instance_eval do
52
58
  output do
53
- field :content_view_name, _('Content View')
54
- field :lifecycle_environment_name, _('Lifecycle Environment')
55
- field :content_source_name, _('Content Source')
59
+ label _("Content View") do
60
+ field :content_view_id, _("ID")
61
+ field :content_view_name, _("Name")
62
+ end
63
+
64
+ label _("Lifecycle Environment") do
65
+ field :lifecycle_environment_id, _("ID")
66
+ field :lifecycle_environment_name, _("Name")
67
+ end
68
+
69
+ label _("Content Source") do
70
+ field :content_source_id, _("ID")
71
+ field :content_source_name, _("Name")
72
+ end
73
+
74
+ label _("Kickstart Repository") do
75
+ field :kickstart_repository_id, _("ID")
76
+ field :kickstart_repository_name, _("Name")
77
+ end
56
78
  end
57
79
  end
58
80
  end