hammer_cli_katello 0.0.4 → 0.0.5

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 (38) hide show
  1. checksums.yaml +8 -8
  2. data/lib/hammer_cli_katello.rb +81 -15
  3. data/lib/hammer_cli_katello/activation_key.rb +34 -4
  4. data/lib/hammer_cli_katello/associating_commands.rb +3 -1
  5. data/lib/hammer_cli_katello/capsule.rb +8 -1
  6. data/lib/hammer_cli_katello/commands.rb +12 -0
  7. data/lib/hammer_cli_katello/content_host.rb +38 -5
  8. data/lib/hammer_cli_katello/content_host_errata.rb +39 -0
  9. data/lib/hammer_cli_katello/content_host_package.rb +58 -0
  10. data/lib/hammer_cli_katello/content_host_package_group.rb +38 -0
  11. data/lib/hammer_cli_katello/content_view.rb +19 -7
  12. data/lib/hammer_cli_katello/content_view_puppet_module.rb +11 -35
  13. data/lib/hammer_cli_katello/content_view_version.rb +46 -11
  14. data/lib/hammer_cli_katello/exception_handler.rb +7 -1
  15. data/lib/hammer_cli_katello/filter_rule.rb +0 -4
  16. data/lib/hammer_cli_katello/gpg_key.rb +1 -4
  17. data/lib/hammer_cli_katello/host_collection.rb +47 -9
  18. data/lib/hammer_cli_katello/id_resolver.rb +85 -10
  19. data/lib/hammer_cli_katello/lifecycle_environment.rb +19 -27
  20. data/lib/hammer_cli_katello/lifecycle_environment_name_resolvable.rb +33 -0
  21. data/lib/hammer_cli_katello/organization.rb +5 -4
  22. data/lib/hammer_cli_katello/output/fields.rb +15 -0
  23. data/lib/hammer_cli_katello/output/formatters.rb +34 -0
  24. data/lib/hammer_cli_katello/ping.rb +3 -6
  25. data/lib/hammer_cli_katello/product.rb +5 -8
  26. data/lib/hammer_cli_katello/puppet_module.rb +13 -10
  27. data/lib/hammer_cli_katello/repository.rb +112 -11
  28. data/lib/hammer_cli_katello/repository_scoped_to_product.rb +13 -0
  29. data/lib/hammer_cli_katello/repository_set.rb +0 -2
  30. data/lib/hammer_cli_katello/subscription.rb +14 -7
  31. data/lib/hammer_cli_katello/sync_plan.rb +0 -3
  32. data/lib/hammer_cli_katello/version.rb +1 -1
  33. data/locale/Makefile +65 -0
  34. data/locale/README.md +18 -0
  35. data/locale/en/LC_MESSAGES/hammer-cli-katello.mo +0 -0
  36. data/locale/en/hammer-cli-katello.po +1215 -0
  37. data/locale/hammer-cli-katello.pot +833 -639
  38. metadata +32 -5
@@ -0,0 +1,38 @@
1
+ module HammerCLIKatello
2
+
3
+ class ContentHostPackageGroup < HammerCLIKatello::Command
4
+
5
+ desc "Manage package-groups on your content hosts"
6
+
7
+ class InstallCommand < HammerCLIKatello::SingleResourceCommand
8
+ include HammerCLIForemanTasks::Async
9
+ resource :system_packages, :install
10
+ command_name "install"
11
+ success_message "Package-groups installed successfully"
12
+ failure_message "Could not install package-groups"
13
+
14
+ validate_options do
15
+ option(:option_groups).required
16
+ end
17
+
18
+ build_options :without => [:packages]
19
+ end
20
+
21
+ class RemoveCommand < HammerCLIKatello::SingleResourceCommand
22
+ include HammerCLIForemanTasks::Async
23
+ resource :system_packages, :remove
24
+ command_name "remove"
25
+ success_message "Package-groups removed successfully"
26
+ failure_message "Could not remove package-groups"
27
+
28
+ validate_options do
29
+ option(:option_groups).required
30
+ end
31
+
32
+ build_options :without => [:packages]
33
+ end
34
+
35
+ autoload_subcommands
36
+ end
37
+
38
+ end
@@ -8,6 +8,7 @@ module HammerCLIKatello
8
8
  resource :content_views
9
9
 
10
10
  class ListCommand < HammerCLIKatello::ListCommand
11
+ include LifecycleEnvironmentNameResolvable
11
12
  output do
12
13
  field :id, _("Content View ID")
13
14
  field :name, _("Name")
@@ -26,6 +27,7 @@ module HammerCLIKatello
26
27
  field :label, _("Label")
27
28
  field :composite, _("Composite")
28
29
  field :description, _("Description")
30
+ field :content_host_count, _("Content Host Count")
29
31
 
30
32
  from :organization do
31
33
  field :name, _("Organization")
@@ -61,6 +63,10 @@ module HammerCLIKatello
61
63
  field :id, _("ID")
62
64
  field :name, _("Name")
63
65
  end
66
+
67
+ collection :activation_keys, _("Activation Keys") do
68
+ custom_field Fields::Reference
69
+ end
64
70
  end
65
71
 
66
72
  build_options
@@ -88,7 +94,9 @@ module HammerCLIKatello
88
94
  build_options
89
95
  end
90
96
 
91
- class DeleteCommand < HammerCLIForemanTasks::AsyncCommand
97
+ class DeleteCommand < HammerCLIKatello::DeleteCommand
98
+ include HammerCLIForemanTasks::Async
99
+
92
100
  action :destroy
93
101
  command_name "delete"
94
102
 
@@ -98,7 +106,9 @@ module HammerCLIKatello
98
106
  build_options
99
107
  end
100
108
 
101
- class PublishCommand < HammerCLIForemanTasks::AsyncCommand
109
+ class PublishCommand < HammerCLIKatello::SingleResourceCommand
110
+ include HammerCLIForemanTasks::Async
111
+
102
112
  action :publish
103
113
  command_name "publish"
104
114
 
@@ -108,7 +118,10 @@ module HammerCLIKatello
108
118
  build_options
109
119
  end
110
120
 
111
- class RemoveFromEnvironmentCommand < HammerCLIForemanTasks::AsyncCommand
121
+ class RemoveFromEnvironmentCommand < HammerCLIKatello::SingleResourceCommand
122
+ include LifecycleEnvironmentNameResolvable
123
+ include HammerCLIForemanTasks::Async
124
+
112
125
  action :remove_from_environment
113
126
  command_name "remove-from-environment"
114
127
 
@@ -118,7 +131,9 @@ module HammerCLIKatello
118
131
  build_options
119
132
  end
120
133
 
121
- class RemoveCommand < HammerCLIForemanTasks::AsyncCommand
134
+ class RemoveCommand < HammerCLIKatello::SingleResourceCommand
135
+ include HammerCLIForemanTasks::Async
136
+
122
137
  # command to remove content view environments and versions from a content view.
123
138
  # corresponds to the UI screen.
124
139
  action :remove
@@ -188,6 +203,3 @@ module HammerCLIKatello
188
203
  HammerCLIKatello::ContentViewVersion
189
204
  end
190
205
  end
191
-
192
- HammerCLI::MainCommand.subcommand "content-view", _("Manipulate content views."),
193
- HammerCLIKatello::ContentView
@@ -12,30 +12,22 @@ module HammerCLIKatello
12
12
  field :uuid, _("UUID")
13
13
  field :name, _("Name")
14
14
  field :author, _("Author")
15
+ field :version, _("Version")
15
16
  end
16
17
 
17
- build_options
18
- end
19
-
20
- class InfoCommand < HammerCLIKatello::InfoCommand
21
- output do
22
- field :id, _("ID")
23
- field :uuid, _("UUID"), Fields::Field, :hide_blank => true
24
- field :name, _("Name")
25
- field :author, _("Author")
26
- field :created_at, _("Created"), Fields::Date
27
- field :updated_at, _("Updated"), Fields::Date
28
- end
29
-
30
- def request_params
31
- super.merge(method_options)
18
+ def extend_data(mod)
19
+ if mod['uuid']
20
+ mod['version'] = mod['computed_version']
21
+ else
22
+ mod['version'] = _("Latest(Currently %s)") % mod['computed_version']
23
+ end
24
+ mod
32
25
  end
33
26
 
34
27
  build_options
35
28
  end
36
29
 
37
- class CreateCommand < HammerCLIKatello::Command
38
- action :create
30
+ class CreateCommand < HammerCLIKatello::CreateCommand
39
31
  command_name "add"
40
32
 
41
33
  success_message _("Puppet module added to content view")
@@ -44,27 +36,11 @@ module HammerCLIKatello
44
36
  build_options
45
37
  end
46
38
 
47
- class UpdateCommand < HammerCLIKatello::UpdateCommand
48
- success_message _("Puppet module updated for content view")
49
- failure_message _("Could not update the puppet module")
50
-
51
- def request_params
52
- super.merge(method_options)
53
- end
54
-
55
- build_options
56
- end
57
-
58
- class DeleteCommand < HammerCLIKatello::Command
59
- action :destroy
39
+ class DeleteCommand < HammerCLIKatello::DeleteCommand
60
40
  command_name "remove"
61
41
 
62
42
  success_message _("Puppet module removed from content view")
63
- failure_message _("Could not delete the filter")
64
-
65
- def request_params
66
- super.merge(method_options)
67
- end
43
+ failure_message _("Couldn't remove puppet module from the content view")
68
44
 
69
45
  build_options
70
46
  end
@@ -10,12 +10,12 @@ module HammerCLIKatello
10
10
  field :id, _("ID")
11
11
  field :name, _("Name")
12
12
  field :version, _("Version")
13
+ field :environments, _("Lifecycle Environments"), Fields::List
14
+ end
13
15
 
14
- from :content_view do
15
- field :id, _("Content View ID")
16
- field :name, _("Content View Name")
17
- field :label, _("Content View Label")
18
- end
16
+ def extend_data(version)
17
+ version['environments'] = version['environments'].map { |e| e["name"] }
18
+ version
19
19
  end
20
20
 
21
21
  build_options
@@ -33,7 +33,7 @@ module HammerCLIKatello
33
33
  field :label, _("Content View Label")
34
34
  end
35
35
 
36
- collection :environments, _("Environments") do
36
+ collection :environments, _("Lifecycle Environments") do
37
37
  field :id, _("ID")
38
38
  field :name, _("Name")
39
39
  field :label, _("Label")
@@ -53,27 +53,62 @@ module HammerCLIKatello
53
53
  end
54
54
  end
55
55
 
56
- build_options
56
+ build_options do |o|
57
+ o.expand(:all).including(:environments)
58
+ end
57
59
  end
58
60
 
59
- class PromoteCommand < HammerCLIForemanTasks::AsyncCommand
61
+ class PromoteCommand < HammerCLIKatello::SingleResourceCommand
62
+ include HammerCLIForemanTasks::Async
63
+
60
64
  action :promote
61
65
  command_name "promote"
62
66
 
63
67
  success_message _("Content view is being promoted with task %{id}")
64
68
  failure_message _("Could not promote the content view")
65
69
 
66
- build_options
70
+ option "--from-lifecycle-environment", "FROM_ENVIRONMENT",
71
+ _("Name of the source environment"), :attribute_name => :option_environment_name
72
+ option "--from-lifecycle-environment-id", "FROM_ENVIRONMENT_ID",
73
+ _("Id of the source environment"), :attribute_name => :option_environment_id
74
+ option "--to-lifecycle-environment", "TO_ENVIRONMENT",
75
+ _("Name of the target environment"), :attribute_name => :option_to_environment_name
76
+ option "--to-lifecycle-environment-id", "TO_ENVIRONMENT_ID",
77
+ _("Id of the target environment"), :attribute_name => :option_to_environment_id
78
+
79
+ def request_params
80
+ params = super
81
+
82
+ env_search_opts = {
83
+ "option_id" => options["option_to_environment_id"],
84
+ "option_name" => options["option_to_environment_name"],
85
+ "option_organization_id" => options["option_organization_id"],
86
+ "option_organization_name" => options["option_organization_name"],
87
+ "option_organization_label" => options["option_organization_label"]
88
+ }
89
+
90
+ params['environment_id'] = resolver.lifecycle_environment_id(env_search_opts)
91
+ params
92
+ end
93
+
94
+ build_options do |o|
95
+ o.expand(:all).except(:environments)
96
+ o.without(:environment_id)
97
+ end
67
98
  end
68
99
 
69
- class DeleteCommand < HammerCLIForemanTasks::AsyncCommand
100
+ class DeleteCommand < HammerCLIKatello::DeleteCommand
101
+ include HammerCLIForemanTasks::Async
102
+
70
103
  action :destroy
71
104
  command_name "delete"
72
105
 
73
106
  success_message _("Content view is being deleted with task %{id}")
74
107
  failure_message _("Could not delete the content view")
75
108
 
76
- build_options
109
+ build_options do |o|
110
+ o.expand(:all).including(:environments)
111
+ end
77
112
  end
78
113
 
79
114
  autoload_subcommands
@@ -4,7 +4,8 @@ module HammerCLIKatello
4
4
 
5
5
  def mappings
6
6
  super + [
7
- [RestClient::InternalServerError, :handle_internal_error]
7
+ [RestClient::InternalServerError, :handle_internal_error],
8
+ [RestClient::BadRequest, :handle_bad_request]
8
9
  ]
9
10
  end
10
11
 
@@ -25,6 +26,11 @@ module HammerCLIKatello
25
26
  HammerCLI::EX_NOT_FOUND
26
27
  end
27
28
 
29
+ def handle_bad_request(e)
30
+ handle_katello_error(e)
31
+ HammerCLI::EX_NOT_FOUND
32
+ end
33
+
28
34
  def handle_katello_error(e)
29
35
  response = JSON.parse(e.response)
30
36
  response = HammerCLIForeman.record_to_common_format(response)
@@ -61,10 +61,6 @@ module HammerCLIKatello
61
61
  success_message _("Filter rule deleted")
62
62
  failure_message _("Could not delete the filter rule")
63
63
 
64
- def request_params
65
- super.merge(method_options)
66
- end
67
-
68
64
  build_options
69
65
  end
70
66
 
@@ -42,7 +42,7 @@ module HammerCLIKatello
42
42
  success_message _("GPG Key created")
43
43
  failure_message _("Could not create GPG Key")
44
44
 
45
- build_options :without => [:content]
45
+ build_options :without => [:content]
46
46
  option "--key", "GPG_KEY_FILE", _("GPG Key file"),
47
47
  :attribute_name => :option_content,
48
48
  :required => true,
@@ -69,7 +69,4 @@ module HammerCLIKatello
69
69
  autoload_subcommands
70
70
  end
71
71
 
72
- HammerCLI::MainCommand.subcommand("gpg",
73
- _("manipulate GPG Key actions on the server"),
74
- HammerCLIKatello::GpgKeyCommand)
75
72
  end
@@ -3,6 +3,22 @@ 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 content host ids to replace the content hosts in host collection"),
11
+ :format => HammerCLI::Options::Normalizers::List.new
12
+ end
13
+
14
+ def request_params
15
+ params = super
16
+ params['system_uuids'] = option_system_ids unless option_system_ids.nil?
17
+ params.delete('system_ids') if params.keys.include? 'system_ids'
18
+ params
19
+ end
20
+ end
21
+
6
22
  class ListCommand < HammerCLIKatello::ListCommand
7
23
  resource :host_collections, :index
8
24
 
@@ -17,12 +33,19 @@ module HammerCLIKatello
17
33
  end
18
34
 
19
35
  class CreateCommand < HammerCLIKatello::CreateCommand
36
+ include UuidRequestable
20
37
  resource :host_collections, :create
38
+ def request_params
39
+ super.tap do |params|
40
+ if params['max_content_hosts'] && params['unlimited_content_hosts'].nil?
41
+ params['unlimited_content_hosts'] = false
42
+ end
43
+ end
44
+ end
21
45
 
22
46
  success_message _("Host collection created")
23
47
  failure_message _("Could not create the host collection")
24
-
25
- build_options
48
+ build_options :without => [:system_uuids]
26
49
  end
27
50
 
28
51
  class InfoCommand < HammerCLIKatello::InfoCommand
@@ -41,8 +64,7 @@ module HammerCLIKatello
41
64
  command_name "content-hosts"
42
65
 
43
66
  output do
44
- field :id, _("ID")
45
- field :uuid, _("UUID")
67
+ field :uuid, _("ID")
46
68
  field :name, _("Name")
47
69
  end
48
70
 
@@ -66,10 +88,11 @@ module HammerCLIKatello
66
88
  end
67
89
 
68
90
  class UpdateCommand < HammerCLIKatello::UpdateCommand
91
+ include UuidRequestable
69
92
  success_message _("Host collection updated")
70
93
  failure_message _("Could not update the the host collection")
71
94
 
72
- build_options
95
+ build_options :without => [:system_uuids]
73
96
  end
74
97
 
75
98
  class DeleteCommand < HammerCLIKatello::DeleteCommand
@@ -81,11 +104,26 @@ module HammerCLIKatello
81
104
  build_options
82
105
  end
83
106
 
84
- HammerCLIKatello::AssociatingCommands::ContentHost.extend_command(self)
107
+ class AddContentHostCommand < HammerCLIKatello::SingleResourceCommand
108
+ command_name 'add-content-host'
109
+ action :add_systems
110
+
111
+ success_message _("The content host(s) has been added")
112
+ failure_message _("Could not add content host(s)")
113
+
114
+ build_options
115
+ end
116
+
117
+ class RemoveContentHostCommand < HammerCLIKatello::SingleResourceCommand
118
+ command_name 'remove-content-host'
119
+ action :remove_systems
120
+
121
+ success_message _("The content host(s) has been removed")
122
+ failure_message _("Could not remove content host(s)")
123
+
124
+ build_options
125
+ end
85
126
 
86
127
  autoload_subcommands
87
128
  end
88
129
  end
89
-
90
- HammerCLI::MainCommand.subcommand 'host-collection', _("Manipulate host collections"),
91
- HammerCLIKatello::HostCollection
@@ -1,15 +1,36 @@
1
1
  module HammerCLIKatello
2
2
 
3
- class Searchables
3
+ class Searchables < HammerCLIForeman::Searchables
4
4
 
5
5
  SEARCHABLES = {
6
- :organization => [
7
- HammerCLIForeman::Searchable.new("name", _("Name to search by")),
8
- HammerCLIForeman::Searchable.new("label", _("Label to search by"), :editable => false)
9
- ]
6
+ :activation_key => [s_name(_("Activation key name to search by"))],
7
+ :capsule => [s_name(_("Capsule name to search by"))],
8
+ :content_host => [s_name(_("Content host name to search by"))],
9
+ :content_view => [s_name(_("Content view name to search by"))],
10
+ :gpg => [s_name(_("Gpg key name to search by"))],
11
+ :host_collection => [s_name(_("Host collection name to search by"))],
12
+ :lifecycle_environment => [s_name(_("Lifecycle environment name to search by"))],
13
+ :organization => [s_name(_("Organization name to search by")),
14
+ s("label", _("Organization label to search by"),
15
+ :editable => false)
16
+ ],
17
+ :product => [s_name(_("Product name to search by"))],
18
+ :repository => [s_name(_("Repository name to search by"))],
19
+ :repository_set => [s_name(_("Repository set name to search by"))],
20
+ :subscription => [s_name(_("Subscription name to search by"))],
21
+ :sync_plan => [s_name(_("Sync plan name to search by"))],
22
+ :task => [s_name(_("Task name to search by"))],
23
+ :user => [s_name(_("User name to search by"))],
24
+ :content_view_puppet_module => [
25
+ s_name(_("Puppet module name to search by")),
26
+ s("author", _("Puppet module's author to search by")),
27
+ s("uuid", _("Puppet module's UUID to search by"))
28
+ ],
29
+ :content_view => [s_name(_("Content view name"))],
30
+ :content_view_version => [s("version", _("Content view version number"))]
10
31
  }
11
32
 
12
- DEFAULT_SEARCHABLES = [HammerCLIForeman::Searchable.new("name", _("Name to search by"))]
33
+ DEFAULT_SEARCHABLES = [s_name(_("Name to search by"))]
13
34
 
14
35
  def for(resource)
15
36
  SEARCHABLES[resource.singular_name.to_sym] || DEFAULT_SEARCHABLES
@@ -23,17 +44,71 @@ module HammerCLIKatello
23
44
  options[HammerCLI.option_accessor_name("id")] || find_resource(:systems, options)['uuid']
24
45
  end
25
46
 
26
- def create_search_options(options, resource)
27
- return super if resource.name == :organizations
47
+ def environment_id(options)
48
+ lifecycle_environment_id(options)
49
+ end
50
+
51
+ def repository_id(options)
52
+ key_id = HammerCLI.option_accessor_name("id")
53
+ key_product_id = HammerCLI.option_accessor_name("product_id")
54
+
55
+ return options[key_id] if options[key_id]
56
+
57
+ options[key_product_id] ||= product_id(scoped_options("product", options))
58
+ find_resource(:repositories, options)['id']
59
+ end
60
+
61
+ def content_view_version_id(options)
62
+ key_id = HammerCLI.option_accessor_name("id")
63
+ key_environment_id = HammerCLI.option_accessor_name("environment_id")
64
+
65
+ return options[key_id] if options[key_id]
66
+
67
+ begin
68
+ options[key_environment_id] ||= lifecycle_environment_id(
69
+ scoped_options("environment", options)
70
+ )
71
+ rescue HammerCLIForeman::MissingSeachOptions # rubocop:disable HandleExceptions
72
+ # Intentionally suppressing the exception,
73
+ # environment is not always required.
74
+ end
75
+ find_resource(:content_view_versions, options)['id']
76
+ end
77
+
78
+ def create_repositories_search_options(options)
79
+ search_options = {}
80
+ search_options['name'] = options[HammerCLI.option_accessor_name("name")]
81
+ search_options['product_id'] = options[HammerCLI.option_accessor_name("product_id")]
82
+ search_options
83
+ end
84
+
85
+ def create_content_view_versions_search_options(options)
86
+ environment_id = options[HammerCLI.option_accessor_name("environment_id")]
87
+ version = options[HammerCLI.option_accessor_name("version")]
88
+
89
+ search_options = {}
90
+ search_options['environment_id'] = environment_id if environment_id
91
+ search_options['version'] = version if version
92
+ search_options
93
+ end
94
+
95
+ def create_organizations_search_options(options)
96
+ create_search_options_without_katello_api(options, api.resource(:organizations))
97
+ end
28
98
 
99
+ def create_search_options_with_katello_api(options, resource)
100
+ search_options = {}
29
101
  searchables(resource).each do |s|
30
102
  value = options[HammerCLI.option_accessor_name(s.name.to_s)]
31
103
  if value
32
- return {"#{s.name}" => "#{value}"}
104
+ search_options.update("#{s.name}" => "#{value}")
33
105
  end
34
106
  end
35
- {}
107
+ search_options
36
108
  end
109
+ # alias_method_chain :create_search_options, :katello_api
110
+ alias_method :create_search_options_without_katello_api, :create_search_options
111
+ alias_method :create_search_options, :create_search_options_with_katello_api
37
112
 
38
113
  end
39
114
  end