Class: HammerCLIKatello::ContentViewVersion::ImportCommand
- Inherits:
-
HammerCLIForeman::Command
- Object
- HammerCLIForeman::Command
- HammerCLIKatello::ContentViewVersion::ImportCommand
- Includes:
- HammerCLIForemanTasks::Async, ApipieHelper, HammerCLIKatello::CVImportExportHelper, LocalHelper
- Defined in:
- lib/hammer_cli_katello/content_view_version.rb
Constant Summary
Constants included from HammerCLIKatello::CVImportExportHelper
HammerCLIKatello::CVImportExportHelper::PUBLISHED_REPOS_DIR
Instance Attribute Summary collapse
-
#export_tar_dir ⇒ Object
Returns the value of attribute export_tar_dir.
-
#export_tar_file ⇒ Object
Returns the value of attribute export_tar_file.
-
#export_tar_prefix ⇒ Object
Returns the value of attribute export_tar_prefix.
Instance Method Summary collapse
- #content_view(name, organization_id) ⇒ Object
-
#execute ⇒ Object
rubocop:disable Metrics/AbcSize.
- #publish(id, major, minor, repos_units = nil) ⇒ Object
- #repos_units(repositories) ⇒ Object
-
#sync_repositories(repositories, organization_id, options) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #synchronize(id, source_url) ⇒ Object
Methods included from HammerCLIKatello::CVImportExportHelper
#collect_packages, #export_json, #fetch_exportable_cvv_repositories, #find_local_component_id, #import_checks, #obtain_export_params, #read_json, #untar_export, #warn_repo_download_policy
Methods included from ApipieHelper
#call, #destroy, #index, #show, #update
Methods included from LocalHelper
Instance Attribute Details
#export_tar_dir ⇒ Object
Returns the value of attribute export_tar_dir.
424 425 426 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 424 def export_tar_dir @export_tar_dir end |
#export_tar_file ⇒ Object
Returns the value of attribute export_tar_file.
424 425 426 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 424 def export_tar_file @export_tar_file end |
#export_tar_prefix ⇒ Object
Returns the value of attribute export_tar_prefix.
424 425 426 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 424 def export_tar_prefix @export_tar_prefix end |
Instance Method Details
#content_view(name, organization_id) ⇒ Object
520 521 522 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 520 def content_view(name, organization_id) index(:content_views, 'name' => name, 'organization_id' => organization_id).first end |
#execute ⇒ Object
rubocop:disable Metrics/AbcSize
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 447 def execute unless File.exist?(['option_export_tar']) raise _("Export tar #{['option_export_tar']} does not exist.") end import_tar_params = obtain_export_params(['option_export_tar']) untar_export(import_tar_params) export_json = read_json(import_tar_params) cv = content_view(export_json['name'], ['option_organization_id']) major = export_json['major'].to_s minor = export_json['minor'].to_s import_checks(export_json, cv, major, minor) if export_json['composite_components'] composite_version_ids = export_json['composite_components'].map do |component| find_local_component_id(component) end update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids) publish(cv['id'], export_json['major'], export_json['minor']) else sync_repositories(export_json['repositories'], ['option_organization_id'], import_tar_params) unless cv['default'] publish( cv['id'], export_json['major'], export_json['minor'], repos_units(export_json['repositories']) ) end end return HammerCLI::EX_OK end |
#publish(id, major, minor, repos_units = nil) ⇒ Object
528 529 530 531 532 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 528 def publish(id, major, minor, repos_units = nil) params = {'id' => id, 'major' => major, 'minor' => minor } params['repos_units'] = repos_units if repos_units task_progress(call(:publish, :content_views, params)) end |
#repos_units(repositories) ⇒ Object
511 512 513 514 515 516 517 518 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 511 def repos_units(repositories) repositories.collect do |repo| { 'label' => repo['label'], 'rpm_filenames' => repo['rpm_filenames'] } end end |
#sync_repositories(repositories, organization_id, options) ⇒ Object
rubocop:enable Metrics/AbcSize
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 482 def sync_repositories(repositories, organization_id, ) export_tar_dir = [:dirname] export_tar_prefix = [:prefix] repositories.each do |repo| library_repos = index( :repositories, 'organization_id' => organization_id, 'library' => true ) library_repo = library_repos.select do |candidate_repo| candidate_repo['label'] == repo['label'] end library_repo = library_repo.first if library_repo.nil? msg = _("Unable to sync repositories, no library repository found for %s") raise msg % repo['label'] end synchronize( library_repo['id'], "file://#{export_tar_dir}/#{export_tar_prefix}/#{repo['relative_path']}" ) end end |
#synchronize(id, source_url) ⇒ Object
524 525 526 |
# File 'lib/hammer_cli_katello/content_view_version.rb', line 524 def synchronize(id, source_url) task_progress(call(:sync, :repositories, 'id' => id, 'source_url' => source_url)) end |