Module: PulpHelper::Repo
- Included in:
- Lita::Handlers::Pulp
- Defined in:
- lib/pulphelper/repo.rb
Constant Summary collapse
- REPO_TYPE_RPM =
"rpm-repo"
- REPO_TYPE_PUPPET =
"puppet-repo"
Instance Method Summary collapse
-
#copy_puppet_between_repo!(from_repo, to_repo, author, name, version, delete_new = false, auto_publish = true) ⇒ Object
function.
-
#copy_rpm_between_repo!(from_repo, to_repo, name, version, release, arch, delete_new = false, auto_publish = true) ⇒ Object
delete_rpm_newer.
-
#delete_puppet_newer!(forge_id, author, name, version, auto_publish = false) ⇒ Object
copy_rpm_between_repo.
-
#delete_rpm_newer!(forge_id, name, version, release, arch, auto_publish = false) ⇒ Object
publish_repo.
-
#get_repo(repo_id) ⇒ Object
puppet repo distributors: distributor_type_id: “puppet_distributor” auto_publish: last_publish config : importers: importer_type_id: “puppet_importer”.
- #list_repo(type) ⇒ Object
-
#publish_repo!(forge_id) ⇒ Object
list_repo_details.
Instance Method Details
#copy_puppet_between_repo!(from_repo, to_repo, author, name, version, delete_new = false, auto_publish = true) ⇒ Object
function
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/pulphelper/repo.rb', line 226 def copy_puppet_between_repo!(from_repo, to_repo, ,name, version, delete_new=false, auto_publish=true) search_params = get_puppet_search_params(, name, version) begin puts "search_params :#{search_params}" unit_search_response=client.resources.unit.search("puppet_module", search_params[:criteria], search_params[:optional]) if unit_search_response.code !=200 raise "Exception: unit search faild with code #{unit_search_response.code}" end puts "search_response : #{unit_search_response.to_json}" found_units=JSON.parse(unit_search_response.to_json) unit_id=found_units.first['_id'] unless unit_id && unit_id.length >0 raise "No puppet module found to copy" end copy_unit_ids= { :ids => [unit_id] } copy_response=client.extensions.puppet_module.copy(from_repo, to_repo, copy_unit_ids) if copy_response.code !=200 && copy_response.code !=202 raise "Exception: unit copy failed with code #{copy_response.code}" end if(delete_new) delete_puppet_newer!(to_repo,, name, version, auto_publish ) end rescue StandardError => e raise "Error copy module between repo: #{e.to_s}" end end |
#copy_rpm_between_repo!(from_repo, to_repo, name, version, release, arch, delete_new = false, auto_publish = true) ⇒ Object
delete_rpm_newer
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/pulphelper/repo.rb', line 174 def copy_rpm_between_repo!(from_repo, to_repo, name, version, release, arch, delete_new=false, auto_publish=true) search_params=get_rpm_search_params(name, version, release, arch) begin unit_search_response=client.resources.unit.search('rpm', search_params[:criteria], search_params[:optional]) if unit_search_response.code !=200 raise "Exception: Cannot find unit" end found_units=JSON.parse(unit_search_response.to_json) unit_id=found_units.first['_id'] copy_unit_ids= { :ids => [unit_id] } copy_response=client.extensions.rpm.copy(from_repo, to_repo, copy_unit_ids) if copy_response.code !=200 && copy_response.code !=202 raise "Exception: unit copy failed with code #{copy_response.code}" end if(delete_new) delete_rpm_newer!(to_repo, name, version, release, arch, auto_publish) end rescue StandardError => e raise "Exception: Error copy module between repo: #{e.to_s}" end end |
#delete_puppet_newer!(forge_id, author, name, version, auto_publish = false) ⇒ Object
copy_rpm_between_repo
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/pulphelper/repo.rb', line 201 def delete_puppet_newer!(forge_id, , name, version, auto_publish=false) #/pulp/api/v2/repositories/<repo_id>/actions/unassociate/ criteria = get_puppet_unit_assoc_criteria(, name, version) begin unassociate_response=client.resources.repository.unassociate_units(forge_id, criteria) #pulp api documented response code if unassociate_response.code !=202 raise "Exception: cannot unassociate unit, response code: #{unassociate_response.code}" end if auto_publish publish_response=client.extensions.repository.publish_all(forge_id) presponse=JSON.parse(publish_response.to_json) if presponse.nil? || presponse[0]["spawned_tasks"].length<1 raise "Exception: repo publish requeste failed, response : #{publish_response}" end # if publish_response.code !=202 && !"#{publish_response.code}".start_with?("20") # raise "Exception: repo publish requeste failed, response code : #{publish_response.code}" # end end rescue StandardError => e raise "Exception: Error delete module newer than #{}-#{name}-#{version} from repo #{forge_id}: #{e.}" end end |
#delete_rpm_newer!(forge_id, name, version, release, arch, auto_publish = false) ⇒ Object
publish_repo
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/pulphelper/repo.rb', line 150 def delete_rpm_newer!(forge_id, name, version, release, arch, auto_publish=false) criteria = get_rpm_unit_ass_criteria(name, version, release, arch) begin unassociate_response=client.resources.repository.unassociate_units(forge_id, criteria) #pulp api documented response code if unassociate_response.code !=202 raise "Exception: cannot unassociate unit, response code: #{unassociate_response.code}" end if auto_publish publish_response=client.extensions.repository.publish_all(forge_id) presponse=JSON.parse(publish_response.to_json) if presponse.nil? || presponse[0]["spawned_tasks"].length<1 raise "Exception: repo publish requeste failed, response : #{publish_response}" end # if publish_response.code !=202 && !"#{publish_response.code}".start_with?("20") # raise "Exception: repo publish requeste failed, response code : #{publish_response.code}" # end end rescue StandardError => e raise "Error delete rpm pakcage older than #{name}-#{version}-#{release} from repo #{forge_id}: #{e.}" end end |
#get_repo(repo_id) ⇒ Object
puppet repo distributors:
distributor_type_id: "puppet_distributor"
auto_publish:
last_publish
config :
importers:
importer_type_id: "puppet_importer"
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pulphelper/repo.rb', line 64 def get_repo(repo_id) response=client.extensions.repository.retrieve_with_details(repo_id) code=response.code body=response.body case code when 200 repo=JSON.parse(body.to_json) type = repo["notes"]["_repo-type"] #puts repos repo_data=nil case type when REPO_TYPE_RPM yum_distributor = repo["distributors"].select{ |d| d["distributor_type_id"] == 'yum_distributor'}[0] yum_importer = repo["distributors"].select{ |d| d["distributor_type_id"] == 'yum_importer'}[0] distributor = nil if yum_distributor distributor = { :auto_publish => yum_distributor["auto_publish"], :last_publish => yum_distributor["last_publish"], :config => yum_distributor["config"] } end importer = nil if yum_importer importer = { :last_sync => yum_importer["last_sync"], :config => yum_importer["config"] } end repo_data={ :id => repo["id"], :name => repo["display_name"], :description => repo["description"], :content_unit_counts => repo["content_unit_counts"], :type => REPO_TYPE_RPM, :last_unit_removed => repo["last_unit_removed"], :last_unit_added => repo["last_unit_added"], :distributor => distributor, :importer => importer, } #puts repos when REPO_TYPE_PUPPET puppet_distributor = repo["distributors"].select{ |d| d["distributor_type_id"] == 'puppet_distributor'}[0] distributor =nil if puppet_distributor distributor = { :auto_publish => puppet_distributor["auto_publish"], :last_publish => puppet_distributor["last_publish"], :config => puppet_distributor["config"] } end repo_data={ :id => repo["id"], :name => repo["display_name"], :description => repo["description"], :content_unit_counts => repo["content_unit_counts"], :type => REPO_TYPE_PUPPET, :last_unit_removed => repo["last_unit_removed"], :last_unit_added => repo["last_unit_added"], :distributor => distributor } else end repo_data else raise "Exception: cannot get repository detail: response code :#{code}" end end |
#list_repo(type) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pulphelper/repo.rb', line 9 def list_repo(type) criteria = { "filters" => { "notes._repo-type" => { "$in" => [type] } } } #puts "criteria:#{criteria}" response=client.resources.repository.search(criteria) code=response.code body=response.body result=[] case code when 200 repos=JSON.parse(body.to_json) #puts repos repos.each do |repo| repo_data={ :id => repo["id"], :name => repo["display_name"], :description => repo["description"] } #puts repos result << repo_data end else raise "Exception: cannot list repository: response code :#{code}" end return result end |
#publish_repo!(forge_id) ⇒ Object
list_repo_details
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/pulphelper/repo.rb', line 134 def publish_repo!(forge_id) = "Publish #{forge_id} submitted successfully" begin publish_response=client.extensions.repository.publish_all(forge_id) ## ## Runcilbe does not proper include respone code ## if publish_response.code !=202 && !"#{publish_response.code}".start_with?("20") raise "Publish #{forge_id} failed with http response code: #{publish_response.code}" end rescue StandardError => e raise "Excpetion: Failed to publish, #{e.}" end end |