Module: HammerCLIKatello::ContentExportHelper
- Includes:
- ApipieHelper
- Included in:
- HammerCLIKatello::ContentExport::GenerateMetadataCommand, HammerCLIKatello::ContentExportComplete::LibraryCommand, HammerCLIKatello::ContentExportComplete::VersionCommand, HammerCLIKatello::ContentExportIncremental::LibraryCommand, HammerCLIKatello::ContentExportIncremental::VersionCommand
- Defined in:
- lib/hammer_cli_katello/content_export_helper.rb
Class Method Summary collapse
- .included(base) ⇒ Object
- .setup_library(base) ⇒ Object
- .setup_version(base) ⇒ Object
- .setup_version_options(base) ⇒ Object
Instance Method Summary collapse
- #execute ⇒ Object
- #fetch_export_history(export_history_id) ⇒ Object
- #fetch_export_history_from_task(task) ⇒ Object
- #fetch_repositories ⇒ Object
- #generate_metadata_json(export_history) ⇒ Object
- #reload_task(task) ⇒ Object
- #send_request ⇒ Object
- #version_command? ⇒ Boolean
- #warn_unexportable_repositories ⇒ Object
Methods included from ApipieHelper
#call, #destroy, #index, #show, #update
Class Method Details
.included(base) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 114 def self.included(base) if base.command_name.first.to_sym == :version setup_version(base) elsif base.command_name.first.to_sym == :library setup_library(base) end end |
.setup_library(base) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 122 def self.setup_library(base) base.action(:library) base. _("Library environment is being exported in task %{id}.") base. _("Could not export the library") base.option "--fail-on-missing-content", :flag, _("Fails if any of the repositories belonging"\ " to this organization are unexportable.") base. do |o| o.(:all).including(:organizations) end end |
.setup_version(base) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 135 def self.setup_version(base) base.action(:version) (base) base. _("Content view version is being exported in task %{id}.") base. _("Could not export the content view version") base.extend_with( HammerCLIKatello::CommandExtensions::LifecycleEnvironments.new(only: :option_sources) ) base.include(LifecycleEnvironmentNameMapping) base.class_eval do def request_params super.tap do |opts| opts["id"] = resolver.content_view_version_id() end end end end |
.setup_version_options(base) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 155 def self.(base) base.option "--fail-on-missing-content", :flag, _("Fails if any of the repositories belonging"\ " to this version are unexportable.") base.option "--version", "VERSION", _("Filter versions by version number."), :attribute_name => :option_version, :required => false base. do |o| o.(:all).including(:content_views, :organizations, :lifecycle_environments) o.without(:environment_ids, :environment_id) end base. do unless option(:option_id).exist? any(:option_id, :option_content_view_name, :option_content_view_id).required any( :option_version, :option_lifecycle_environment_id, :option_lifecycle_environment_name ).required unless option(:option_content_view_id).exist? any(:option_organization_id, :option_organization_name, \ :option_organization_label).required end end end end |
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 7 def execute warn_unexportable_repositories response = super if option_async? output. _("Once the task completes the export metadata must be generated "\ + "with the command:") output.(" hammer content-export generate-metadata --task-id #{@task['id']}") HammerCLI::EX_OK elsif response != HammerCLI::EX_OK response else export_history = fetch_export_history_from_task(reload_task(@task)) if export_history (export_history) HammerCLI::EX_OK else output.print_error _("Could not fetch the export history") HammerCLI::EX_CANTCREAT end end end |
#fetch_export_history(export_history_id) ⇒ Object
42 43 44 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 42 def fetch_export_history(export_history_id) index(:content_exports, :id => export_history_id).first if export_history_id end |
#fetch_export_history_from_task(task) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 46 def fetch_export_history_from_task(task) # checking this here implies the task object was loaded recently if %w(error warning).include?(task['result']) raise _("Can not fetch export history from an unfinished task") end export_history_id = task.dig('output', 'export_history_id') fetch_export_history(export_history_id) end |
#fetch_repositories ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 75 def fetch_repositories = { library: true, content_type: 'yum', search: 'download_policy != immediate' } if version_command? [:content_view_version_id] = resolver.content_view_version_id() else [:organization_id] = ["option_organization_id"] end index(:repositories, ) end |
#generate_metadata_json(export_history) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 56 def (export_history) = export_history["metadata"].to_json begin = "#{export_history['path']}/metadata.json" File.write(, ) output. _("Generated #{}") rescue SystemCallError filename = "metadata-#{export_history['id']}.json" File.write(filename, ) output. _("Unable to access/write to '#{export_history['path']}'. "\ "Generated '#{Dir.pwd}/#{filename}' instead. "\ "This file is necessary to perform an import.") end end |
#reload_task(task) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 33 def reload_task(task) task_id = if task.is_a? Hash task['id'] else task end show(:foreman_tasks, id: task_id) end |
#send_request ⇒ Object
29 30 31 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 29 def send_request @task = super end |
#version_command? ⇒ Boolean
71 72 73 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 71 def version_command? self.class.command_name.first.to_sym == :version end |
#warn_unexportable_repositories ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hammer_cli_katello/content_export_helper.rb', line 89 def warn_unexportable_repositories repos = fetch_repositories unless repos.empty? if version_command? output. _("NOTE: Unable to fully export this version because"\ " it contains repositories without the 'immediate' download policy."\ " Update the download policy and sync affected repositories."\ " Once synced republish the content view"\ " and export the generated version.") else output. _("NOTE: Unable to fully export this organization's library because"\ " it contains repositories without the 'immediate' download policy."\ " Update the download policy and sync affected"\ " repositories to include them in the export.") end output. _("Use the following command to update the "\ "download policy of these repositories.") output. "hammer repository update --id=<REPOSITORY_ID> "\ "--download-policy='immediate'" output. "" print_record(::HammerCLIKatello::Repository::ListCommand.output_definition, repos) exit(HammerCLI::EX_SOFTWARE) if option_fail_on_missing_content? end end |