[Pulp-list] Querying the set of RPMs in a repository via the API

Richard Grainger grainger at gmail.com
Thu May 11 09:35:20 UTC 2017


One thing I find useful when working with the API, is to run the
pulp-admin client
with '-vv':


pulp-admin -vv rpm repo content rpm --fields=created --repo-id=foo


This will display the exact API calls and responses. In this case, I got
the error:

Invalid properties: ['Field: <created> does not exist on objects in the
<units_rpm> collection']


I think this is because the "created" field is actually part of "repodata",
so you need to do:


pulp-admin -vv rpm repo content rpm --fields=repodata --repo-id=foo


...and then extract the "created" field from the resulting data using your
client code.

Best
Rchard.

On Thu, May 11, 2017 at 10:07 AM, Paul Urwin <register at paulurwin.com> wrote:

> Hello Pulp community,
>
> I've been banging my head against this. I'm trying to get a list of RPMs
> in a repository, which I've done by structuring the URL, but I can't seem
> to get any filters or field limits to work...
>
> Here's my call that works, and returns all fields associated with the
> first unit:
> search = {
>   "criteria": {},
>   "limit":1
> }
> response = requests.post(API_URL + '/repositories/test_repo/search/units/'.
> cert=blah, data=json.dumps(search))
>
> Similarly it works in get format too:
>
> response = requests.get(API_URL + '/repositories/test_repo/search/units/?limit=1'.
> cert=blah))
>
> Now, if I try to specify the "field" argument to only retrieve a specific
> field ("created") I get a trackback from the call:
>
> response = requests.get(API_URL + '/repositories/test_repo/
> search/units/?field=created&limit=1'. cert=blah))
>
> {
>     "_href": "/pulp/api/v2/repositories/test_repo/search/units/?limit=
> 1&field=created",
>     "error_message": "pop() takes at most 1 argument (2 given)",
>     "exception": [
>         "TypeError: pop() takes at most 1 argument (2 given)\n"
>     ],
>     "http_request_method": "GET",
>     "http_status": 500,
>     "traceback": [
>         "  File \"/usr/lib/python2.7/site-packages/django/core/handlers/base.py\",
> line 112, in get_response\n    response = wrapped_callback(request,
> *callback_args, **callback_kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/django/views/generic/base.py\",
> line 69, in view\n    return self.dispatch(request, *args, **kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/django/views/generic/base.py\",
> line 87, in dispatch\n    return handler(request, *args, **kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/pulp/server/
> webservices/views/decorators.py\", line 241, in _auth_decorator\n
>  return _verify_auth(self, operation, super_user_only, method, *args,
> **kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/pulp/server/
> webservices/views/decorators.py\", line 195, in _verify_auth\n    value =
> method(self, *args, **kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/pulp/server/webservices/views/search.py\",
> line 108, in get\n    return self._generate_response(query, options, *args,
> **kwargs)\n",
>         "  File \"/usr/lib/python2.7/site-packages/pulp/server/
> webservices/views/repositories.py\", line 285, in _generate_response\n
>  criteria = UnitAssociationCriteria.from_client_input(query)\n",
>         "  File \"/usr/lib/python2.7/site-packages/pulp/server/db/model/criteria.py\",
> line 286, in from_client_input\n    association_fields =
> _validate_fields(fields.pop('association', None))\n"
>     ]
> }
>
> I also can't work out how to get it to accept a filter to restrict the
> results by a field value:
>
> e.g.
> search = {
>   "criteria": { "filters": {"created": { "gt": {"$date":
> "2015-01-01T00:00:00Z"}}}},
>   "limit":1
> }
> response = requests.post(API_URL + '/repositories/test_repo/search/units/'.
> cert=blah, data=json.dumps(search))
>
> Result: 400 error with description: "Invalid properties: ['created']
>
> or even simpler:
>
> search = {
>   "criteria": { "filters": {"repo_id": "test_repo"}},
>   "limit":1
> }
> response = requests.post(API_URL + '/repositories/test_repo/search/units/'.
> cert=blah, data=json.dumps(search))
>
> Result: 400 error with description: "Invalid properties: ['repo_id']
>
> (obviously I wouldn't actually try to limit by repo_id given it's already
> limited by that in the URL)
>
> Clearly I'm doing something wrong, any help is appreciated!
>
> Thanks
>
> Paul
>
> _______________________________________________
> Pulp-list mailing list
> Pulp-list at redhat.com
> https://www.redhat.com/mailman/listinfo/pulp-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/pulp-list/attachments/20170511/5d552ece/attachment.htm>


More information about the Pulp-list mailing list