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
@@ -3,6 +3,19 @@ module HammerCLIKatello
3
3
  class LifecycleEnvironmentCommand < HammerCLIKatello::Command
4
4
  resource :lifecycle_environments
5
5
 
6
+ module PriorIdResolvable
7
+ def request_params
8
+ params = super
9
+ if params["prior"]
10
+ params["prior"] = resolver.lifecycle_environment_id(
11
+ HammerCLI.option_accessor_name("name") => params["prior"],
12
+ HammerCLI.option_accessor_name("organization_id") => params["organization_id"]
13
+ )
14
+ end
15
+ params
16
+ end
17
+ end
18
+
6
19
  class ListCommand < HammerCLIKatello::ListCommand
7
20
  output do
8
21
  field :id, _("ID")
@@ -20,14 +33,11 @@ module HammerCLIKatello
20
33
  command_name "paths"
21
34
 
22
35
  output do
23
- field :pretty_path, _("Lifecycle Path")
36
+ field :_pretty_path, _("Lifecycle Path")
24
37
  end
25
38
 
26
39
  def extend_data(data)
27
- route = []
28
- data["path"].each { |step| route << step["environment"]["name"] }
29
-
30
- data[:pretty_path] = route.join(" >> ")
40
+ data["_pretty_path"] = data["environments"].map { |env| env["name"] }.join(" >> ")
31
41
  data
32
42
  end
33
43
 
@@ -53,34 +63,20 @@ module HammerCLIKatello
53
63
  end
54
64
 
55
65
  class CreateCommand < HammerCLIKatello::CreateCommand
66
+ include PriorIdResolvable
67
+
56
68
  success_message _("Environment created")
57
69
  failure_message _("Could not create environment")
58
70
 
59
- def request_params
60
- params = super
61
- params["prior"] = resolver.lifecycle_environment_id(
62
- HammerCLI.option_accessor_name("name") => params["prior"],
63
- HammerCLI.option_accessor_name("organization_id") => params["organization_id"]
64
- )
65
- params
66
- end
67
-
68
71
  build_options
69
72
  end
70
73
 
71
74
  class UpdateCommand < HammerCLIKatello::UpdateCommand
75
+ include PriorIdResolvable
76
+
72
77
  success_message _("Environment updated")
73
78
  failure_message _("Could not update environment")
74
79
 
75
- def request_params
76
- params = super
77
- params["prior"] = resolver.lifecycle_environment_id(
78
- HammerCLI.option_accessor_name("name") => params["prior"],
79
- HammerCLI.option_accessor_name("organization_id") => params["organization_id"]
80
- )
81
- params
82
- end
83
-
84
80
  build_options
85
81
  end
86
82
 
@@ -94,8 +90,4 @@ module HammerCLIKatello
94
90
  autoload_subcommands
95
91
  end
96
92
 
97
- cmd_name = "lifecycle-environment"
98
- cmd_desc = _("manipulate lifecycle_environments on the server")
99
- cmd_cls = HammerCLIKatello::LifecycleEnvironmentCommand
100
- HammerCLI::MainCommand.subcommand(cmd_name, cmd_desc, cmd_cls)
101
93
  end
@@ -0,0 +1,33 @@
1
+ module HammerCLIKatello
2
+ module LifecycleEnvironmentNameResolvable
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def resource_name_mapping
9
+ mapping = Command.resource_name_mapping
10
+ mapping[:environment] = :lifecycle_environment
11
+ mapping
12
+ end
13
+ end
14
+
15
+ def lifecycle_environment_resolve_options(options)
16
+ {
17
+ HammerCLI.option_accessor_name("name") => options['option_environment_name'],
18
+ HammerCLI.option_accessor_name("id") => options['option_environment_id'],
19
+ HammerCLI.option_accessor_name("organization_id") => options["option_organization_id"],
20
+ HammerCLI.option_accessor_name("organization_name") => options["option_organization_name"]
21
+ }
22
+ end
23
+
24
+ def all_options
25
+ result = super.clone
26
+ if result['option_environment_name']
27
+ result['option_environment_id'] = resolver.lifecycle_environment_id(
28
+ lifecycle_environment_resolve_options(result))
29
+ end
30
+ result
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,5 @@
1
+ require 'hammer_cli_foreman/organization'
2
+
1
3
  module HammerCLIKatello
2
4
 
3
5
  class Organization < HammerCLIForeman::Organization
@@ -46,7 +48,9 @@ module HammerCLIKatello
46
48
  build_options
47
49
  end
48
50
 
49
- class DeleteCommand < HammerCLIKatello::DeleteCommand
51
+ class DeleteCommand < HammerCLIForeman::Organization::DeleteCommand
52
+ include HammerCLIKatello::ResolverCommons
53
+ include HammerCLIForemanTasks::Async
50
54
  resource :organizations, :destroy
51
55
 
52
56
  success_message _("Organization deleted")
@@ -59,6 +63,3 @@ module HammerCLIKatello
59
63
  end
60
64
 
61
65
  end
62
-
63
- HammerCLI::MainCommand.subcommand! 'organization', _("Manipulate organizations"),
64
- HammerCLIKatello::Organization
@@ -0,0 +1,15 @@
1
+ require 'hammer_cli'
2
+
3
+ module HammerCLIKatello
4
+ module Output
5
+ module Fields
6
+
7
+ class ChecksumFilePair < ::Fields::Field
8
+ end
9
+
10
+ class Dependency < ::Fields::Field
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module HammerCLIKatello
2
+ module Output
3
+ module Formatters
4
+
5
+ class ChecksumFormatter < HammerCLI::Output::Formatters::FieldFormatter
6
+
7
+ def tags
8
+ [:screen]
9
+ end
10
+
11
+ def format(items, _ = {})
12
+ "%s %s" % items.reverse
13
+ end
14
+ end
15
+
16
+ class DependencyFormatter < HammerCLI::Output::Formatters::FieldFormatter
17
+
18
+ def format(dependency, _ = {})
19
+ name = dependency[:name] || dependency['name']
20
+ version = dependency[:version_requirement] || dependency['version_requirement']
21
+ if version
22
+ "%s ( %s )" % [name, version]
23
+ else
24
+ name
25
+ end
26
+ end
27
+ end
28
+
29
+ HammerCLI::Output::Output.register_formatter(ChecksumFormatter.new, :ChecksumFilePair)
30
+ HammerCLI::Output::Output.register_formatter(DependencyFormatter.new, :Dependency)
31
+
32
+ end
33
+ end
34
+ end
@@ -42,8 +42,8 @@ module HammerCLIKatello
42
42
  end
43
43
  end
44
44
 
45
- label "katello_jobs" do
46
- from "katello_jobs" do
45
+ label "foreman_tasks" do
46
+ from "foreman_tasks" do
47
47
  field "status", _("Status")
48
48
  field "_response", _("Server Response")
49
49
  end
@@ -60,7 +60,7 @@ module HammerCLIKatello
60
60
 
61
61
  def send_request
62
62
  super.tap do |data|
63
- data['services'].each do |name, service|
63
+ data['services'].each do |_, service|
64
64
  service['_response'] = get_server_response(service)
65
65
  end
66
66
  end
@@ -78,7 +78,4 @@ module HammerCLIKatello
78
78
 
79
79
  end # class PingCommand
80
80
 
81
- HammerCLI::MainCommand.subcommand("ping", _("get the status of the server"),
82
- HammerCLIKatello::PingCommand)
83
-
84
81
  end # module HammerCLIKatello
@@ -7,6 +7,7 @@ module HammerCLIKatello
7
7
  output do
8
8
  field :id, _("ID")
9
9
  field :name, _("Name")
10
+ field :description, _("Description")
10
11
 
11
12
  from :organization do
12
13
  field :name, _("Organization")
@@ -96,9 +97,6 @@ module HammerCLIKatello
96
97
  resource :products, :update
97
98
 
98
99
  build_options :without => [:name, :label, :provider_id, :description, :gpg_key_id]
99
- # TODO: set to --sync-plan-id
100
- option "--sync_plan_id", "SYNC_PLAN_ID", _("plan numeric identifier"),
101
- :attribute_name => :option_sync_plan_id, :required => true
102
100
  end
103
101
 
104
102
  class RemoveSyncPlanCommand < HammerCLIKatello::UpdateCommand
@@ -112,13 +110,12 @@ module HammerCLIKatello
112
110
 
113
111
  build_options :without => [:name, :label, :provider_id, :description,
114
112
  :gpg_key_id, :sync_plan_id]
115
- option "--sync_plan_id", "SYNC_PLAN_ID", _("plan numeric identifier"),
116
- :attribute_name => :option_sync_plan_id, :required => true
113
+
114
+ def request_params
115
+ super.merge("sync_plan_id" => nil)
116
+ end
117
117
  end
118
118
 
119
119
  autoload_subcommands
120
120
  end
121
121
  end
122
-
123
- HammerCLI::MainCommand.subcommand "product", _("Manipulate products."),
124
- HammerCLIKatello::Product
@@ -7,8 +7,8 @@ module HammerCLIKatello
7
7
  output do
8
8
  field :id, _("ID")
9
9
  field :name, _("Name")
10
- field :version, _("Version")
11
10
  field :author, _("Author")
11
+ field :version, _("Version")
12
12
  end
13
13
 
14
14
  build_options
@@ -26,13 +26,20 @@ module HammerCLIKatello
26
26
  field :license, _("License")
27
27
  field :project_page, _("Project Page")
28
28
  field :source, _("Source")
29
- field :dependencies, _("Dependencies"), Fields::List
30
- field :checksums, _("Checksums"), Fields::List
29
+
30
+ collection :dependencies, _("Dependencies"), :numbered => false do
31
+ field nil, nil, HammerCLIKatello::Output::Fields::Dependency
32
+ end
33
+ collection :checksums, _("File checksums"), :numbered => false do
34
+ field nil, nil, HammerCLIKatello::Output::Fields::ChecksumFilePair
35
+ end
36
+
31
37
  field :tag_list, _("Tag List"), Fields::List
32
- end
33
38
 
34
- def request_params
35
- super.merge(method_options)
39
+ collection :repositories, _("Repositories") do
40
+ field :id, _("Id")
41
+ field :name, _("Name")
42
+ end
36
43
  end
37
44
 
38
45
  build_options
@@ -41,7 +48,3 @@ module HammerCLIKatello
41
48
  autoload_subcommands
42
49
  end
43
50
  end
44
-
45
- HammerCLI::MainCommand.subcommand "puppet-module",
46
- "View Puppet Module details.",
47
- HammerCLIKatello::PuppetModule
@@ -7,13 +7,19 @@ module HammerCLIKatello
7
7
  output do
8
8
  field :id, _("Id")
9
9
  field :name, _("Name")
10
+ from :product do
11
+ field :name, _("Product")
12
+ end
10
13
  field :content_type, _("Content Type")
14
+ field :url, _("URL")
11
15
  end
12
16
 
13
17
  build_options
14
18
  end
15
19
 
16
20
  class InfoCommand < HammerCLIKatello::InfoCommand
21
+ include RepositoryScopedToProduct
22
+
17
23
  output do
18
24
  field :id, _("ID")
19
25
  field :name, _("Name")
@@ -94,21 +100,24 @@ module HammerCLIKatello
94
100
  sync_states[state]
95
101
  end
96
102
 
97
- def request_params
98
- super.merge(method_options)
103
+ build_options do |o|
104
+ o.expand.including(:products)
99
105
  end
100
-
101
- build_options
102
106
  end
103
107
 
104
- class SyncCommand < HammerCLIForemanTasks::AsyncCommand
108
+ class SyncCommand < HammerCLIKatello::SingleResourceCommand
109
+ include HammerCLIForemanTasks::Async
110
+ include RepositoryScopedToProduct
111
+
105
112
  action :sync
106
113
  command_name "synchronize"
107
114
 
108
115
  success_message _("Repository is being synchronized in task %{id}")
109
116
  failure_message _("Could not synchronize the repository")
110
117
 
111
- build_options
118
+ build_options do |o|
119
+ o.expand.including(:products)
120
+ end
112
121
  end
113
122
 
114
123
  class CreateCommand < HammerCLIKatello::CreateCommand
@@ -123,25 +132,117 @@ module HammerCLIKatello
123
132
  end
124
133
 
125
134
  class UpdateCommand < HammerCLIKatello::UpdateCommand
135
+ include RepositoryScopedToProduct
136
+
126
137
  success_message _("Repository updated")
127
138
  failure_message _("Could not update the repository")
128
139
 
129
- build_options :without => [:unprotected]
140
+ build_options(:without => [:unprotected]) do |o|
141
+ o.expand.including(:products)
142
+ end
130
143
  option "--publish-via-http", "ENABLE", _("Publish Via HTTP"),
131
144
  :attribute_name => :option_unprotected,
132
145
  :format => HammerCLI::Options::Normalizers::Bool.new
133
146
  end
134
147
 
135
148
  class DeleteCommand < HammerCLIKatello::DeleteCommand
149
+ include RepositoryScopedToProduct
150
+
136
151
  success_message _("Repository deleted")
137
152
  failure_message _("Could not delete the Repository")
138
153
 
139
- build_options
154
+ build_options do |o|
155
+ o.expand.including(:products)
156
+ end
157
+ end
158
+
159
+ class UploadContentCommand < HammerCLIKatello::InfoCommand
160
+ include RepositoryScopedToProduct
161
+
162
+ resource :repositories, :upload_content
163
+ command_name "upload-content"
164
+ CONTENT_CHUNK_SIZE = 4_000_000 # bytes
165
+
166
+ class BinaryPath < HammerCLI::Options::Normalizers::File
167
+ def format(path)
168
+ fullpath = ::File.expand_path(path)
169
+
170
+ if File.directory?(fullpath)
171
+ Dir["#{fullpath}/*"].map { |file| ::File.new(file, 'rb') }
172
+ else
173
+ [::File.new(fullpath, 'rb')]
174
+ end
175
+ end
176
+ end
177
+
178
+ def request_headers
179
+ {:content_type => 'multipart/form-data', :multipart => true}
180
+ end
181
+
182
+ def execute
183
+ @failure = false
184
+ option_content.each { |file| upload_file(file) }
185
+
186
+ @failure ? HammerCLI::EX_DATAERR : HammerCLI::EX_OK
187
+ end
188
+
189
+ def content_upload_resource
190
+ ::HammerCLIForeman.foreman_resource(:content_uploads)
191
+ end
192
+
193
+ success_message _("Repository content uploaded")
194
+ failure_message _("Could not upload the content")
195
+
196
+ build_options(:without => [:content]) do |o|
197
+ o.expand.including(:products)
198
+ end
199
+ option "--path", "PATH", _("Upload file or directory of files as content for a repository"),
200
+ :attribute_name => :option_content,
201
+ :required => true, :format => BinaryPath.new
202
+
203
+ private
204
+
205
+ def upload_file(file)
206
+ upload_id = create_content_upload
207
+ repo_id = get_identifier
208
+ filename = File.basename(file.path)
209
+
210
+ offset = 0
211
+ while (content = file.read(CONTENT_CHUNK_SIZE))
212
+ params = {:offset => offset,
213
+ :id => upload_id,
214
+ :content => content,
215
+ :repository_id => repo_id
216
+ }
217
+
218
+ content_upload_resource.call(:update, params, request_headers)
219
+ offset += CONTENT_CHUNK_SIZE
220
+ end
221
+
222
+ import_upload_ids([upload_id])
223
+ print_message _("Successfully uploaded file '%s'.") % filename
224
+ rescue
225
+ @failure = true
226
+ print_message _("Failed to upload file '%s' to repository. Please check "\
227
+ "the file and try again.") % filename
228
+ ensure
229
+ content_upload_resource.call(:destroy, :repository_id => get_identifier, :id => upload_id)
230
+ end
231
+
232
+ def create_content_upload
233
+ response = content_upload_resource.call(:create, :repository_id => get_identifier)
234
+
235
+ response["upload_id"]
236
+ end
237
+
238
+ def import_upload_ids(ids)
239
+ params = {:id => get_identifier,
240
+ :upload_ids => ids
241
+ }
242
+ resource.call(:import_uploads, params)
243
+ end
140
244
  end
141
245
 
142
246
  autoload_subcommands
143
247
  end
144
248
  end
145
-
146
- HammerCLI::MainCommand.subcommand "repository", _("Manipulate repositories"),
147
- HammerCLIKatello::Repository