hammer_cli_katello 0.19.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d2b30e958f929fc2fedbe5fe789e28cdeb4983a435a1321f824dd00cba28ddd
4
- data.tar.gz: 544f0f8c49df77a184272d8a726af95a894807655861c4309478b8b709a6c46d
3
+ metadata.gz: a27a924ef525708ffb735aa5dd369d47da3f2832e935110b51786cb82f74cb96
4
+ data.tar.gz: 60964599cd0f257228da611d8de998e11213c98726120d1bb8a12d0f13b215a1
5
5
  SHA512:
6
- metadata.gz: 861eea30b18630224089d34e3bc6a9131cfbe01c6f9dc172a7ab0dc4471d61ab780ebc97c4ef9ee8d084378f28cf84fa5da5e749de6a8db4cfcb3be058071c6f
7
- data.tar.gz: e1fa7a8bb29701c48ed214254ae0e089fa1c4665af88ecfa523456b5b16af70edd05f95aed76dd124f3a58f29178af51ad4128d7ff8877ad18646ccb2db7587c
6
+ metadata.gz: 8fd3cc4a42fecbb77241beea5d9871bfcc7290473088dfb68741082dbe9d4dd96f450dac72c7151894652a3d85ce142365ab3a885add5b30d8c6da503e8574d5
7
+ data.tar.gz: c73dabc6e9676b5385f91668e9c0c74a2c48dc956ea24a8ba7cb12545ebdfdbfcf51f84498e76953f0c70b4adb6e05b9127cfa194fe47c8c0a66fe119e65707f
@@ -54,11 +54,6 @@ module HammerCLIKatello
54
54
  'hammer_cli_katello/lifecycle_environment'
55
55
  )
56
56
 
57
- HammerCLI::MainCommand.lazy_subcommand("ping", _("Get the status of the server"),
58
- 'HammerCLIKatello::PingCommand',
59
- 'hammer_cli_katello/ping'
60
- )
61
-
62
57
  HammerCLI::MainCommand.lazy_subcommand("product", _("Manipulate products"),
63
58
  'HammerCLIKatello::Product',
64
59
  'hammer_cli_katello/product'
@@ -144,5 +139,7 @@ module HammerCLIKatello
144
139
  # subcommands to hammer_cli_foreman commands
145
140
  require 'hammer_cli_katello/host'
146
141
  require 'hammer_cli_katello/hostgroup'
142
+ require 'hammer_cli_katello/ping'
143
+ require 'hammer_cli_katello/status'
147
144
  end
148
145
  # rubocop:enable Metrics/ModuleLength
@@ -2,3 +2,4 @@
2
2
 
3
3
  require 'hammer_cli_katello/command_extensions/lifecycle_environment'
4
4
  require 'hammer_cli_katello/command_extensions/lifecycle_environments'
5
+ require 'hammer_cli_katello/command_extensions/ping'
@@ -0,0 +1,26 @@
1
+ module HammerCLIKatello
2
+ module CommandExtensions
3
+ class Ping < HammerCLI::CommandExtensions
4
+ before_print do |data|
5
+ unless data['results']['katello'].nil?
6
+ data['results']['katello']['services'].each do |_, service|
7
+ service['_response'] = get_server_response(service)
8
+ end
9
+ data['results'].merge!(data['results']['katello'])
10
+ end
11
+ end
12
+
13
+ output do |definition|
14
+ definition.append(HammerCLIKatello::PingCommand.output_definition.fields)
15
+ end
16
+
17
+ def self.get_server_response(service_hash)
18
+ if service_hash['duration_ms']
19
+ _("Duration: %sms") % service_hash['duration_ms']
20
+ elsif service_hash['message']
21
+ _("Message: %s") % service_hash['message']
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,8 @@
1
1
  module HammerCLIKatello
2
- RESOURCE_NAME_MAPPING = {}.freeze
2
+ RESOURCE_NAME_MAPPING = {
3
+ environment: :lifecycle_environment,
4
+ environments: :lifecycle_environments
5
+ }.freeze
3
6
 
4
7
  RESOURCE_ALIAS_NAME_MAPPING = {
5
8
  environment: :lifecycle_environment,
@@ -283,6 +283,11 @@ module HammerCLIKatello
283
283
  command_name 'add-version'
284
284
  desc _('Add a content view version to a composite view')
285
285
 
286
+ option "--content-view-id", "CONTENT_VIEW_ID",
287
+ _("Content view numeric identifier to search by"),
288
+ attribute_name: :option_content_view_id,
289
+ format: HammerCLI::Options::Normalizers::Number.new
290
+
286
291
  validate_options :before, 'IdResolution' do
287
292
  if option(:option_content_view_version_version).exist?
288
293
  any(:option_content_view_id, :option_content_view_name).required
@@ -372,10 +372,7 @@ module HammerCLIKatello
372
372
  end
373
373
  export_json_options[:repositories] = []
374
374
  else
375
- repositories = fetch_cvv_repositories(cvv)
376
- puppet_check(cvv)
377
- check_repo_type(repositories)
378
- check_repo_download_policy(repositories)
375
+ repositories = fetch_exportable_cvv_repositories(cvv)
379
376
  collect_packages(repositories)
380
377
 
381
378
  export_json_options[:repositories] = repositories
@@ -480,11 +477,14 @@ module HammerCLIKatello
480
477
  publish(cv['id'], export_json['major'], export_json['minor'])
481
478
  else
482
479
  sync_repositories(export_json['repositories'], options['option_organization_id'],
483
- import_tar_params)
484
- publish(
485
- cv['id'], export_json['major'],
486
- export_json['minor'], repos_units(export_json['repositories'])
487
- )
480
+ import_tar_params)
481
+
482
+ unless cv['default']
483
+ publish(
484
+ cv['id'], export_json['major'],
485
+ export_json['minor'], repos_units(export_json['repositories'])
486
+ )
487
+ end
488
488
  end
489
489
  return HammerCLI::EX_OK
490
490
  end
@@ -498,8 +498,7 @@ module HammerCLIKatello
498
498
  library_repos = index(
499
499
  :repositories,
500
500
  'organization_id' => organization_id,
501
- 'library' => true,
502
- 'label' => repo['label']
501
+ 'library' => true
503
502
  )
504
503
 
505
504
  library_repo = library_repos.select do |candidate_repo|
@@ -3,10 +3,32 @@ module HammerCLIKatello
3
3
  module CVImportExportHelper
4
4
  PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
5
5
 
6
- def fetch_cvv_repositories(cvv)
7
- cvv['repositories'].collect do |repo|
8
- show(:repositories, 'id' => repo['id'], :full_result => true)
6
+ def fetch_exportable_cvv_repositories(cvv)
7
+ immediate = []
8
+ non_immediate_names = []
9
+
10
+ cvv['repositories'].each do |repo|
11
+ next unless repo['content_type'] == 'yum'
12
+
13
+ api_repo = show(:repositories, 'id' => repo['id'], :full_result => true)
14
+
15
+ download_policy = if api_repo['library_instance_id']
16
+ library = show(:repositories, 'id' => api_repo['library_instance_id'])
17
+ library['download_policy']
18
+ else
19
+ api_repo['download_policy']
20
+ end
21
+
22
+ if download_policy == 'immediate'
23
+ immediate << api_repo
24
+ else
25
+ non_immediate_names << api_repo['name']
26
+ end
9
27
  end
28
+
29
+ warn_repo_download_policy(non_immediate_names)
30
+
31
+ return immediate
10
32
  end
11
33
 
12
34
  def find_local_component_id(component_from_export)
@@ -23,41 +45,15 @@ module HammerCLIKatello
23
45
  found_composite_version.first['id']
24
46
  end
25
47
 
26
- def puppet_check(cvv)
27
- unless cvv['puppet_modules'].empty?
28
- raise _("The Content View '#{cvv['content_view']['label']}'"\
29
- " contains Puppet modules, this is not supported at this time."\
30
- " Please remove the modules, publish a new version"\
31
- " and try the export again.")
32
- end
33
- end
48
+ def warn_repo_download_policy(repository_names)
49
+ return if repository_names.empty?
34
50
 
35
- def check_repo_type(repositories)
36
- repositories.select do |repo|
37
- if repo['content_type'] != 'yum'
38
- raise _("The Repository '#{repo['name']}' is a non-yum repository."\
39
- " Only Yum is supported at this time."\
40
- " Please remove the repository from the Content View,"\
41
- " republish and try the export again.")
42
- end
43
- end
44
- end
45
-
46
- def check_repo_download_policy(repositories)
47
- non_immediate = repositories.select do |repo|
48
- unless repo['library_instance_id'].nil?
49
- show(:repositories, 'id' => repo['library_instance_id'])['download_policy'] != 'immediate'
50
- end
51
- end
52
- unless non_immediate.empty?
53
- non_immediate_names = non_immediate.collect { |repo| repo['name'] }
54
- msg = <<~MSG
55
- All exported repositories must be set to an immediate download policy and re-synced.
56
- The following repositories need action:
57
- #{non_immediate_names.join(', ')}
58
- MSG
59
- raise _(msg)
60
- end
51
+ msg = <<~MSG
52
+ The following repositories could not be exported due to the download policy
53
+ not being set to 'immediate':
54
+ #{repository_names.join(', ')}
55
+ MSG
56
+ print_message msg
61
57
  end
62
58
 
63
59
  def collect_packages(repositories)
@@ -88,10 +84,12 @@ module HammerCLIKatello
88
84
  " please create the Content View and try the import again.")
89
85
  end
90
86
 
91
- if import_cv['latest_version'].to_f >= version
92
- raise _("The latest version (#{import_cv['latest_version']}) of"\
93
- " the Content View '#{cv['name']}'"\
94
- " is greater or equal to the version you are trying to import (#{version})")
87
+ unless import_cv['default']
88
+ if import_cv['latest_version'].to_f >= version
89
+ raise _("The latest version (#{import_cv['latest_version']}) of"\
90
+ " the Content View '#{cv['name']}'"\
91
+ " is greater or equal to the version you are trying to import (#{version})")
92
+ end
95
93
  end
96
94
 
97
95
  unless import_cv['repository_ids'].nil?
@@ -61,7 +61,10 @@ module HammerCLIKatello
61
61
  super
62
62
  end
63
63
 
64
- build_options
64
+ build_options do |o|
65
+ o.expand.except(:module_streams)
66
+ o.without(:module_streams)
67
+ end
65
68
  end
66
69
 
67
70
  class UpdateCommand < HammerCLIKatello::UpdateCommand
@@ -37,7 +37,8 @@ module HammerCLIKatello
37
37
  build_options
38
38
  end
39
39
 
40
- class CreateCommand < HammerCLIKatello::CreateCommand
40
+ class CreateCommand < HammerCLIForeman::Organization::CreateCommand
41
+ include HammerCLIKatello::ResolverCommons
41
42
  resource :organizations, :create
42
43
 
43
44
  success_message _("Organization created.")
@@ -2,8 +2,8 @@ module HammerCLIKatello
2
2
  module Output
3
3
  module Formatters
4
4
  class ChecksumFormatter < HammerCLI::Output::Formatters::FieldFormatter
5
- def tags
6
- [:screen]
5
+ def required_features
6
+ [:rich_text]
7
7
  end
8
8
 
9
9
  def format(items, _ = {})
@@ -1,3 +1,5 @@
1
+ require 'hammer_cli_foreman/ping'
2
+
1
3
  module HammerCLIKatello
2
4
  class PingCommand < HammerCLIKatello::Command
3
5
  resource :ping, :index
@@ -54,24 +56,23 @@ module HammerCLIKatello
54
56
 
55
57
  def send_request
56
58
  super.tap do |data|
59
+ data['services'] ||= {}
57
60
  data['services'].each do |_, service|
58
- service['_response'] = get_server_response(service)
61
+ service['_response'] =
62
+ HammerCLIKatello::CommandExtensions::Ping.get_server_response(service)
59
63
  end
60
64
  end
61
65
  end
62
66
 
63
- private
64
-
65
- def get_server_response(service_hash)
66
- if service_hash['duration_ms']
67
- _("Duration: %sms") % service_hash['duration_ms']
68
- elsif service_hash['message']
69
- _("Message: %s") % service_hash['message']
70
- end
71
- end
72
-
73
67
  def request_options
74
68
  { with_authentication: false }
75
69
  end
76
70
  end # class PingCommand
71
+
72
+ HammerCLIForeman::PingCommand.subcommand 'katello',
73
+ HammerCLIKatello::PingCommand.desc,
74
+ HammerCLIKatello::PingCommand
75
+ HammerCLIForeman::PingCommand::ForemanCommand.extend_with(
76
+ HammerCLIKatello::CommandExtensions::Ping.new
77
+ )
77
78
  end # module HammerCLIKatello
@@ -212,13 +212,6 @@ module HammerCLIKatello
212
212
  if option(:option_product_name).exist?
213
213
  any(*organization_options).required
214
214
  end
215
-
216
- if option(:option_docker_tag).exist? != option(:option_docker_digest).exist?
217
- option(:option_docker_tag).rejected(
218
- :msg => _('--docker-digest required with --docker-tag'))
219
- option(:option_docker_digest).rejected(
220
- :msg => _('--docker-tag required with --docker-digest'))
221
- end
222
215
  end
223
216
 
224
217
  build_options(:without => [:unprotected]) do |o|
@@ -227,60 +220,12 @@ module HammerCLIKatello
227
220
  option "--publish-via-http", "ENABLE", _("Publish Via HTTP"),
228
221
  :attribute_name => :option_unprotected,
229
222
  :format => HammerCLI::Options::Normalizers::Bool.new
230
- option "--docker-tag", "TAG",
231
- _("Optional custom Container Image tag to specify the value of the Docker digest")
232
- option "--docker-digest", "DIGEST", _("Container Image manifest digest")
233
223
 
234
224
  def execute
235
225
  @failure = false
236
-
237
- if option_docker_tag
238
- upload_tag(option_docker_tag, option_docker_digest)
239
- else
240
- super
241
- end
242
-
226
+ super
243
227
  @failure ? HammerCLI::EX_DATAERR : HammerCLI::EX_OK
244
228
  end
245
-
246
- def content_upload_resource
247
- ::HammerCLIForeman.foreman_resource(:content_uploads)
248
- end
249
-
250
- def upload_tag(tag, digest)
251
- upload_id = create_content_upload
252
- import_uploads([
253
- {
254
- id: upload_id,
255
- name: tag,
256
- digest: digest
257
- }
258
- ], last_file: true)
259
- print_message _("Repository updated")
260
- rescue => e
261
- @failure = true
262
- logger.error e
263
- output.print_error _("Failed to upload tag '%s' to repository.") % tag
264
- ensure
265
- content_upload_resource.call(:destroy, :repository_id => get_identifier, :id => upload_id)
266
- end
267
-
268
- def create_content_upload
269
- response = content_upload_resource.call(:create, :repository_id => get_identifier)
270
-
271
- response["upload_id"]
272
- end
273
-
274
- def import_uploads(uploads, opts = {})
275
- publish_repository = opts.fetch(:last_file, false)
276
- sync_capsule = opts.fetch(:last_file, false)
277
- params = {:id => get_identifier,
278
- :uploads => uploads,
279
- publish_repository: publish_repository,
280
- sync_capsule: sync_capsule
281
- }
282
- resource.call(:import_uploads, params)
283
- end
284
229
  end
285
230
 
286
231
  class DeleteCommand < HammerCLIKatello::DeleteCommand
@@ -382,38 +327,41 @@ module HammerCLIKatello
382
327
  private
383
328
 
384
329
  def upload_file(file, opts = {})
385
- upload_id = create_content_upload
386
- repo_id = get_identifier
330
+ total_size = File.size(file)
331
+ checksum = Digest::SHA256.hexdigest(File.read(file))
332
+ content_type = options["option_content_type"] ? options["option_content_type"] : nil
387
333
  filename = File.basename(file.path)
388
-
389
- update_content_upload(upload_id, repo_id, file)
390
-
391
- file.rewind
392
- content = file.read
393
-
334
+ upload_create_response = create_content_upload(total_size, checksum, content_type)
335
+ upload_id = upload_create_response["upload_id"] || "duplicate"
336
+ content_unit_id = upload_create_response["content_unit_href"]
337
+ unless content_unit_id
338
+ repo_id = get_identifier
339
+ update_content_upload(upload_id, repo_id, file)
340
+ end
394
341
  results = import_uploads([
395
342
  {
396
343
  id: upload_id,
344
+ content_unit_id: content_unit_id,
397
345
  name: filename,
398
346
  size: file.size,
399
- checksum: Digest::SHA256.hexdigest(content)
400
- }
401
- ], opts)
402
-
347
+ checksum: checksum
348
+ }], opts)
403
349
  print_results(filename, results)
404
- rescue => e
405
- @failure = true
406
- logger.error e
407
- output.print_error _("Failed to upload file '%s' to repository. Please check "\
408
- "the file and try again.") % filename
409
350
  ensure
410
- content_upload_resource.call(:destroy, :repository_id => get_identifier, :id => upload_id)
351
+ if upload_id
352
+ content_upload_resource.call(:destroy, :repository_id => get_identifier, :id => upload_id)
353
+ end
411
354
  end
412
355
 
413
- def create_content_upload
414
- response = content_upload_resource.call(:create, :repository_id => get_identifier)
415
-
416
- response["upload_id"]
356
+ def create_content_upload(size, checksum, content_type)
357
+ params = {
358
+ :repository_id => get_identifier,
359
+ :size => size,
360
+ :checksum => checksum,
361
+ :content_type => content_type
362
+ }
363
+ response = content_upload_resource.call(:create, params)
364
+ response
417
365
  end
418
366
 
419
367
  def update_content_upload(upload_id, repo_id, file)
@@ -424,10 +372,10 @@ module HammerCLIKatello
424
372
  :offset => offset,
425
373
  :id => upload_id,
426
374
  :content => content,
375
+ :size => file.size,
427
376
  :repository_id => repo_id,
428
377
  :multipart => true
429
378
  }
430
-
431
379
  # To workaround rest-client bug with false negative warnings,
432
380
  # see https://github.com/rest-client/rest-client/pull/670 for more details
433
381
  silence_warnings do
@@ -450,7 +398,7 @@ module HammerCLIKatello
450
398
  end
451
399
 
452
400
  def print_results(name, results)
453
- if results.empty?
401
+ if results.empty? || results.dig('output', 'upload_results').empty?
454
402
  print_message _("Successfully uploaded file '%{name}'") % {
455
403
  :name => name
456
404
  }