[Pulp-list] v2 api retrieve rpms in repo? PLEASE! :)

Jay Dobies jason.dobies at redhat.com
Thu May 2 12:44:59 UTC 2013

I saw the bug you commented on about the missing docs. That's definitely 
a fault on our end; it got missed, it happens.

Try checking out 
http://www.pulpproject.org/2012/01/10/unit-associations/ It still should 
be in our formal docs, but that should help in the interim.

Another option is to use our CLI to do the query. The in and out bound 
REST calls are logged to ~/.pulp/server_calls.log, so you can see what 
the client generates in terms of the query.

> Seems like it should be a pretty simple API call, but I can't figure
> out how to do it for the life of me. I was able to get a response that
> includes the entire metadata for each rpm in a given repo. I don't
> need or want that, just a list of rpm filenames.
>>>> body = { 'criteria': { 'limit': 1, 'fields': { 'association' : []}}}

The RPM filename is part of the unit metadata, not the association. The 
association tracks the when and how of its addition to the database. The 
unit metadata is all the meaty stuff about the unit itself.

Doing what you're looking for in the CLI:

$ pulp-admin rpm repo content rpm --repo-id test --fields filename

Showed the criteria in server_calls.log as:

{"criteria": {"fields": {"unit": ["filename"]}, "type_ids": ["rpm"], 
"filters": {"unit": {}}}}

You can omit the "filters" section entirely. That'll still return the 
association information, but inside of the metadata field you'll only 
have filename. Here's a snippet from the returned result:

"metadata": {
   "_id": "dd52c734-ec59-4734-9bb4-fc10007c8663",
   "filename": "bear-4.1-1.noarch.rpm"

I'd have to look closer to see if you specify something like:

{"fields": {"unit": ["filename"], "association" : []}}

That might remove the association information as well. Either way, the 
structure will remain the same and you'll need to look into the metadata 
section to find the filename under that key.

I'll see what I can do about bumping up that docs bug, we have a pretty 
full plate for 2.2 already and while just a docs bug, still takes time 
to do correctly.

>>>> r = requests.post('https://pulp/pulp/api/v2/repositories/repo/search/units/', auth=('admin', 'removed'), verify=False, data=json.dumps(body))
>>>> pprint.pprint(r.json())[{u'_id': {u'$oid': u'51818a5aee95994a2d0000cd'},
>    u'metadata': {u'_content_type_id': u'rpm',
>                  u'_id': u'faa52d6a-1f5c-41e1-9ad8-c200aa3d3278',
>                  u'_ns': u'units_rpm',
>                  u'_storage_path':......REMOVED FOR BREVITY
> Please for the love of all that is holy can someone share with me how
> to retrieve a list of RPMs for a given repo? Possibly updating the
> pulp 2.1 API documentation with this example as I'm sure this is a
> pretty common ask.
> Please don't RTFM me, I've read:
> http://pulp-dev-guide.readthedocs.org/en/latest/integration/rest-api/repo/retrieval.html
> http://pulp-dev-guide.readthedocs.org/en/latest/conventions/criteria.html#search-api
> None the wiser after doing so. Tailing logs after running pulp-admin
> and those docs only got me this far.
> Thanks,
> Ryan
> _______________________________________________
> Pulp-list mailing list
> Pulp-list at redhat.com
> https://www.redhat.com/mailman/listinfo/pulp-list

Jay Dobies
Freenode: jdob @ #pulp

More information about the Pulp-list mailing list