Module: PulpHelper::Unit
- Included in:
- Lita::Handlers::Pulp
- Defined in:
- lib/pulphelper/unit.rb
Instance Method Summary collapse
Instance Method Details
#search_puppet(author, name, repo) ⇒ Object
end search
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/pulphelper/unit.rb', line 46 def search_puppet(, name, repo) if .nil? criteria = { "fields" => ["author","name", "version"], "filters" => { "name" => { "$regex" => name } }, "sort" => [["author", "descending"],["name", "descending"],["version", "descending"]] } else criteria = { "fields" => ["author","name", "version"], "filters" => { "$and" => [ { "name" => { "$regex" => name } }, { "author" => } ] }, "sort" => [["author", "descending"],["name", "descending"],["version", "descending"]] } end #puts "search criteria #{criteria}" response = client.resources.unit.search("puppet_module", criteria, {"include_repos" => true}) code = response.code body = response.body #puts body results =[] case code when 200 units = JSON.parse(body.to_json) units.each do |unit| result ={ :name => unit["name"], :version => unit["version"], :author => unit["author"], :repos => unit["repository_memberships"] } results << result end else raise "Exception: search response code = #{code}" end #filter by repo if repo results =results.select {|r| r[:repos].include? repo } end #puts results results end |
#search_rpm(name, repo) ⇒ Object
4 5 6 7 8 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 40 41 42 43 44 45 |
# File 'lib/pulphelper/unit.rb', line 4 def search_rpm(name, repo) criteria = { "fields" => ["name", "version", "release", "epoch", "checksum"], "filters" => { "name" => { "$regex" => name } }, "sort" => [["epoch", "descending"], ["version", "descending"], ["release", "descending"]] } #puts "search criteria #{criteria} in repo : #{repo}" response = client.resources.unit.search("rpm", criteria, {"include_repos" => true}) code = response.code body = response.body #puts body results =[] case code when 200 units = JSON.parse(body.to_json) units.each do |unit| result = { :name => unit["name"], :epoch => unit["epoch"], :version => unit["version"], :release => unit["release"], :checksum => unit["checksum"], :repos => unit["repository_memberships"] } results << result end else raise "Excpetion:response code = #{code}" end #filter by repo if repo results =results.select {|r| r[:repos].include? repo } end #puts "result:#{results}" results end |