hammer_cli_katello 1.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4a20566a58ddf6462ecdc274f1d4f7e107c482ac79ab93b42db2ab11b6d45e
4
- data.tar.gz: 6ad63b1d4e551613de6508c34f137f835934c34731e6dcbb18e69a20b51d421a
3
+ metadata.gz: b5fa880828d3804a98b06e439b6ea10c6f0784102ac00d5ba686b3ff2e27ced6
4
+ data.tar.gz: 52650dc243f073826a2f47cbe69939a2c8af4e2dd8acf3f1843b0acf3dab4063
5
5
  SHA512:
6
- metadata.gz: 179e73dd5c1186e82ff0265cb7eeb36f1a86daee9b2fe915d9cb3fe855ae62420601d2f7ca3adb153d70ffaadaa492be3086ecf129ed17b9435441d8727ac2e1
7
- data.tar.gz: 8918cf5f6376226d4cecd99a70dbadd59d3a7ba2d029517a06849e3f89a9e94b0ea5a76ce46edb60847ceb64b2dcf0af0724a86530541231cf0ae22fa2d2c593
6
+ metadata.gz: b782ea88258329a25f04d308d7f419328a931e2d8ed9d757da44bc7ce54fc37351635cea13d1d990de6d5a399ba6793c2aeecf5ed65f374dfb4d51a2fded2308
7
+ data.tar.gz: e7883bbd668c0eb608b2ad4dc31191f41f8e0837a4648003d2313a0fc13d425778f0f803a46c1343d25dcd25317c27d8ba2d6fc671be846b7bedeb9b60df0beb
@@ -30,7 +30,6 @@ module HammerCLIKatello
30
30
  require 'hammer_cli_katello/id_name_options_validator'
31
31
  require 'hammer_cli_katello/local_helper'
32
32
  require 'hammer_cli_katello/apipie_helper'
33
- require 'hammer_cli_katello/cv_import_export_helper'
34
33
  require 'hammer_cli_katello/content_export_helper'
35
34
 
36
35
  # commands
@@ -156,6 +155,11 @@ module HammerCLIKatello
156
155
  'hammer_cli_katello/simple_content_access'
157
156
  )
158
157
 
158
+ HammerCLI::MainCommand.lazy_subcommand("docker", _("Manipulate docker content"),
159
+ 'HammerCLIKatello::DockerCommand',
160
+ 'hammer_cli_katello/docker'
161
+ )
162
+
159
163
  # subcommands to hammer_cli_foreman commands
160
164
  require 'hammer_cli_katello/host'
161
165
  require 'hammer_cli_katello/hostgroup'
@@ -13,7 +13,7 @@ module HammerCLIKatello
13
13
  :required => false
14
14
 
15
15
  base.build_options do |o|
16
- o.expand(:all).including(:content_views, :organizations).except(:metadata)
16
+ o.expand(:all).including(:organizations).except(:metadata)
17
17
  end
18
18
 
19
19
  base.validate_options do
@@ -58,6 +58,21 @@ module HammerCLIKatello
58
58
  include ContentImportCommon
59
59
  end
60
60
 
61
+ class ListCommand < HammerCLIKatello::ListCommand
62
+ desc "View content view import histories"
63
+ output do
64
+ field :id, _('ID')
65
+ field :path, _('Path')
66
+ field :type, _('Type')
67
+ field :content_view_version, _('Content View Version')
68
+ field :content_view_version_id, _('Content View Version ID')
69
+ field :created_at, _('Created at')
70
+ field :updated_at, _('Updated at'), Fields::Field, :hide_blank => true
71
+ end
72
+
73
+ build_options
74
+ end
75
+
61
76
  autoload_subcommands
62
77
  end
63
78
  end
@@ -271,267 +271,6 @@ module HammerCLIKatello
271
271
  end
272
272
  end
273
273
 
274
- class ExportDefaultCommand < HammerCLIForeman::Command
275
- include HammerCLIKatello::LocalHelper
276
- include HammerCLIKatello::ApipieHelper
277
-
278
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
279
-
280
- desc _('Export the library default content view')
281
-
282
- command_name "export-default"
283
-
284
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
285
-
286
- validate_options do
287
- option(:option_export_dir).required
288
- end
289
-
290
- build_options
291
-
292
- def execute
293
- export_dir = options['option_export_dir']
294
-
295
- Dir.mkdir(export_dir) unless Dir.exist?(export_dir)
296
- result = Kernel.system("rsync -aL #{PUBLISHED_REPOS_DIR} #{export_dir}")
297
- if result == true
298
- output.print_message _("Default content view export is available at #{export_dir}")
299
- HammerCLI::EX_OK
300
- else
301
- output.print_error _("Could not export the default content view at #{export_dir}")
302
- HammerCLI::EX_CANTCREAT
303
- end
304
- end
305
- end
306
-
307
- class LegacyExportCommand < HammerCLIKatello::SingleResourceCommand
308
- include HammerCLIForemanTasks::Async
309
- include LifecycleEnvironmentNameMapping
310
- desc _('Export a content view (legacy method)')
311
-
312
- action :export
313
- command_name "export-legacy"
314
-
315
- success_message _("Content view is being exported in task %{id}.")
316
- failure_message _("Could not export the content view")
317
-
318
- build_options do |o|
319
- o.expand(:all).including(:environments, :content_views, :organizations)
320
- end
321
-
322
- extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
323
- end
324
-
325
- class ExportCommand < HammerCLIForeman::Command
326
- include HammerCLIKatello::LocalHelper
327
- include HammerCLIKatello::ApipieHelper
328
- include HammerCLIKatello::CVImportExportHelper
329
-
330
- PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
331
-
332
- desc _('Export a content view version')
333
-
334
- command_name "export"
335
-
336
- success_message _("Content view export is available in %{directory}.")
337
- failure_message _("Could not export the content view")
338
-
339
- option "--id", "ID", _("Content View Version numeric identifier")
340
- option '--export-dir', 'EXPORT_DIR', _("Directory to put content view version export into.")
341
-
342
- validate_options do
343
- option(:option_export_dir).required
344
- option(:option_id).required
345
- end
346
-
347
- build_options
348
-
349
- def execute
350
- cvv = show(:content_view_versions, 'id' => options['option_id'])
351
- cv = show(:content_views, 'id' => cvv['content_view_id'])
352
-
353
- composite = cv["composite"]
354
-
355
- export_json_options = { :cvv => cvv }
356
-
357
- if composite
358
- components = cv['components']
359
- export_json_options[:component_cvvs] = components.collect do |component|
360
- component['name']
361
- end
362
- export_json_options[:repositories] = []
363
- else
364
- repositories = fetch_exportable_cvv_repositories(cvv)
365
- collect_packages(repositories)
366
-
367
- export_json_options[:repositories] = repositories
368
- end
369
-
370
- json = export_json(export_json_options)
371
- if repositories&.any? || cv['composite']
372
- create_tar(cv, cvv, repositories, json)
373
- else
374
- msg = <<~MSG
375
- Ensure the content view version '#{cvv['name']}' has at least one repository.
376
- MSG
377
- raise _(msg)
378
- end
379
- return HammerCLI::EX_OK
380
- end
381
-
382
- def create_tar(cv, cvv, repositories, json)
383
- export_prefix = "export-#{cv['label']}-#{cvv['major']}.#{cvv['minor']}"
384
- export_file = "#{export_prefix}.json"
385
- export_repos_tar = "#{export_prefix}-repos.tar"
386
- export_tar = "#{export_prefix}.tar"
387
- export_dir = File.expand_path(options['option_export_dir'].to_s)
388
-
389
- Dir.mkdir("#{export_dir}/#{export_prefix}")
390
-
391
- if repositories&.any?
392
-
393
- Dir.chdir(PUBLISHED_REPOS_DIR) do
394
- repo_tar = "#{export_dir}/#{export_prefix}/#{export_repos_tar}"
395
- repo_dirs = []
396
-
397
- repositories.each do |repo|
398
- repo_dirs.push(repo['relative_path'])
399
- end
400
-
401
- `tar cvfh #{repo_tar} #{repo_dirs.join(" ")}`
402
- end
403
- end
404
-
405
- Dir.chdir("#{export_dir}/#{export_prefix}") do
406
- File.open(export_file, 'w') do |file|
407
- file.write(JSON.pretty_generate(json))
408
- end
409
- end
410
-
411
- Dir.chdir(export_dir) do
412
- `tar cf #{export_tar} #{export_prefix}`
413
- FileUtils.rm_rf(export_prefix)
414
- end
415
- end
416
- end
417
-
418
- class ImportCommand < HammerCLIForeman::Command
419
- include HammerCLIForemanTasks::Async
420
- include HammerCLIKatello::LocalHelper
421
- include HammerCLIKatello::ApipieHelper
422
- include HammerCLIKatello::CVImportExportHelper
423
-
424
- attr_accessor :export_tar_dir, :export_tar_file, :export_tar_prefix
425
-
426
- desc _('Import a content view version')
427
-
428
- command_name "import"
429
-
430
- success_message _("Content view imported.")
431
- failure_message _("Could not import the content view")
432
-
433
- option "--organization-id", "ORGANIZATION_ID", _("Organization numeric identifier")
434
- option(
435
- '--export-tar', 'EXPORT_TAR',
436
- _("Location of export tar on disk")
437
- )
438
-
439
- validate_options do
440
- option(:option_export_tar).required
441
- option(:option_organization_id).required
442
- end
443
-
444
- build_options
445
-
446
- # rubocop:disable Metrics/AbcSize
447
- def execute
448
- unless File.exist?(options['option_export_tar'])
449
- raise _("Export tar #{options['option_export_tar']} does not exist.")
450
- end
451
-
452
- import_tar_params = obtain_export_params(options['option_export_tar'])
453
- untar_export(import_tar_params)
454
-
455
- export_json = read_json(import_tar_params)
456
- cv = content_view(export_json['name'], options['option_organization_id'])
457
- major = export_json['major'].to_s
458
- minor = export_json['minor'].to_s
459
- import_checks(export_json, cv, major, minor)
460
-
461
- if export_json['composite_components']
462
- composite_version_ids = export_json['composite_components'].map do |component|
463
- find_local_component_id(component)
464
- end
465
- update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids)
466
- publish(cv['id'], export_json['major'], export_json['minor'])
467
- else
468
- sync_repositories(export_json['repositories'], options['option_organization_id'],
469
- import_tar_params)
470
-
471
- unless cv['default']
472
- publish(
473
- cv['id'], export_json['major'],
474
- export_json['minor'], repos_units(export_json['repositories'])
475
- )
476
- end
477
- end
478
- return HammerCLI::EX_OK
479
- end
480
- # rubocop:enable Metrics/AbcSize
481
-
482
- def sync_repositories(repositories, organization_id, options)
483
- export_tar_dir = options[:dirname]
484
- export_tar_prefix = options[:prefix]
485
-
486
- repositories.each do |repo|
487
- library_repos = index(
488
- :repositories,
489
- 'organization_id' => organization_id,
490
- 'library' => true
491
- )
492
-
493
- library_repo = library_repos.select do |candidate_repo|
494
- candidate_repo['label'] == repo['label']
495
- end
496
-
497
- library_repo = library_repo.first
498
-
499
- if library_repo.nil?
500
- msg = _("Unable to sync repositories, no library repository found for %s")
501
- raise msg % repo['label']
502
- end
503
-
504
- synchronize(
505
- library_repo['id'],
506
- "file://#{export_tar_dir}/#{export_tar_prefix}/#{repo['relative_path']}"
507
- )
508
- end
509
- end
510
-
511
- def repos_units(repositories)
512
- repositories.collect do |repo|
513
- {
514
- 'label' => repo['label'],
515
- 'rpm_filenames' => repo['rpm_filenames']
516
- }
517
- end
518
- end
519
-
520
- def content_view(name, organization_id)
521
- index(:content_views, 'name' => name, 'organization_id' => organization_id).first
522
- end
523
-
524
- def synchronize(id, source_url)
525
- task_progress(call(:sync, :repositories, 'id' => id, 'source_url' => source_url))
526
- end
527
-
528
- def publish(id, major, minor, repos_units = nil)
529
- params = {'id' => id, 'major' => major, 'minor' => minor }
530
- params['repos_units'] = repos_units if repos_units
531
- task_progress(call(:publish, :content_views, params))
532
- end
533
- end
534
-
535
274
  autoload_subcommands
536
275
  end
537
276
  end
@@ -0,0 +1,13 @@
1
+ module HammerCLIKatello
2
+ class DockerCommand < HammerCLI::AbstractCommand
3
+ require 'hammer_cli_katello/docker_manifest'
4
+ subcommand 'manifest',
5
+ HammerCLIKatello::DockerManifestCommand.desc,
6
+ HammerCLIKatello::DockerManifestCommand
7
+
8
+ require 'hammer_cli_katello/docker_tag'
9
+ subcommand 'tag',
10
+ HammerCLIKatello::DockerTagCommand.desc,
11
+ HammerCLIKatello::DockerTagCommand
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ module HammerCLIKatello
2
+ class DockerManifestCommand < HammerCLIForeman::Command
3
+ resource :docker_manifests
4
+ command_name 'manifest'
5
+ desc _('Manage docker manifests')
6
+
7
+ class ListCommand < HammerCLIKatello::ListCommand
8
+ include HammerCLIKatello::LifecycleEnvironmentNameMapping
9
+
10
+ output do
11
+ field :id, _("ID")
12
+ field :name, _("Name")
13
+ field :schema_version, _("Schema Version")
14
+ field :digest, _("Digest")
15
+ field :downloaded, _("Downloaded"), Fields::Boolean
16
+ field :_tags, _("Tags")
17
+ end
18
+
19
+ def extend_data(manifest)
20
+ manifest['_tags'] = manifest['tags'].map { |e| e["name"] }.join(", ")
21
+ manifest
22
+ end
23
+
24
+ build_options do |o|
25
+ o.expand.including(:products, :organizations, :content_views)
26
+ end
27
+
28
+ extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
29
+ end
30
+
31
+ class InfoCommand < HammerCLIKatello::InfoCommand
32
+ output do
33
+ field :id, _("ID")
34
+ field :name, _("Name")
35
+ field :schema_version, _("Schema Version")
36
+ field :digest, _("Digest")
37
+ field :downloaded, _("Downloaded"), Fields::Boolean
38
+ collection :tags, _("Tags") do
39
+ field :name, _("Name")
40
+ end
41
+ end
42
+
43
+ def extend_data(manifest)
44
+ manifest['_tags'] = manifest['tags'].map { |e| { name: e["name"] } }.join(", ")
45
+ manifest
46
+ end
47
+
48
+ build_options
49
+ end
50
+
51
+ autoload_subcommands
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module HammerCLIKatello
2
+ class DockerTagCommand < HammerCLIForeman::Command
3
+ resource :docker_tags
4
+ command_name 'tag'
5
+ desc _('Manage docker tags')
6
+
7
+ class ListCommand < HammerCLIKatello::ListCommand
8
+ include HammerCLIKatello::LifecycleEnvironmentNameMapping
9
+
10
+ output do
11
+ field :id, _("ID")
12
+ field :name, _("Tag")
13
+ field :repository_id, _("Repository ID")
14
+ end
15
+
16
+ build_options do |o|
17
+ o.expand.including(:products, :organizations, :content_views)
18
+ end
19
+
20
+ extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
21
+ end
22
+
23
+ class InfoCommand < HammerCLIKatello::InfoCommand
24
+ output do
25
+ field :id, _("ID")
26
+ field :name, _("Tag")
27
+ field :repository_id, _("Repository ID")
28
+
29
+ from :manifest do
30
+ field :id, _("Docker Manifest ID")
31
+ field :name, _("Docker Manifest Name")
32
+ end
33
+ end
34
+
35
+ build_options
36
+ end
37
+
38
+ autoload_subcommands
39
+ end
40
+ end
@@ -28,7 +28,9 @@ module HammerCLIKatello
28
28
  :subscription => [s_name(_("Subscription name to search by"))],
29
29
  :sync_plan => [s_name(_("Sync plan name to search by"))],
30
30
  :task => [s_name(_("Task name to search by"))],
31
- :content_view_version => [s("version", _("Content view version number"))]
31
+ :content_view_version => [s("version", _("Content view version number"))],
32
+ :content_export => [],
33
+ :content_import => []
32
34
  }.freeze
33
35
 
34
36
  DEFAULT_SEARCHABLES = [s_name(_("Name to search by"))].freeze