dalen / puppet-puppetdbquery

Query functions for PuppetDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for API v4 with Puppet DB v2.x

riton opened this issue · comments

At our site we're still using Puppet DB v2.3.x as no Puppet 4 migration is yet possible for us.

When I try to use as this the code from the master branch I get an error with our Puppet DB v2.3.x. This error is due to the fact that all endpoints have been moved in v3.x.

I've created a quick work around that introduces a new parameter --puppetdb_version and now the code is using the good (old style) endpoint /v4/nodes/....

The next problem I got is with that simple query:

$ puppet query nodes 'Package[httpd]' --host puppetdb.example.net --port 8083 --debug --puppetdb_version 2
[...]
Debug: #<PuppetDB::Connection:0x00000001c90568>: PuppetDB query uri: /v4/nodes?query=[..same_information_as_above..]
Debug: #<PuppetDB::Connection:0x00000001c90568>: PuppetDB query: ["extract",["certname"],["in","certname",["extract","certname",["select_resources",["and",["=","type","Package"],["=","title","httpd"],["=","exported",false]]]]]]

Puppet DB just responds with this error

HTTP/1.1 400 Bad Request
[...]
Warning: v4 query API is experimental and may change without warning. For stability use the v3 api.

'path' is not a queryable object for null, known queryable objects are null
'value' is not a queryable object for null, known queryable objects are null

I know that in Puppet DB v2.x, API v4 is experimental but this seems the only way for us (at the moment) to have support for structured facts.

I don't really realize how difficult it would be to have support for both Puppet DB v2.x and Puppet DB v3.x but this would be very handy for us.

There are a lot of small changes between the v4 API in 2.3.x and 3.x apart from just new locations. For example all parameters and operators with underscores in 3.x have dashes in 2.x, so select-resources instead of select_resources.
Also the certname field on the nodes endpoint is called name in 2.x.
The extract thing is not supported on puppetdb 2.x, but that can just be removed as it is mostly an optimization thing. That was added in puppetdbquery 2.1.0, so if you use 2.0.3 as a base there would be less changes.

I don't really plan to add support for PuppetDB 2.x v4 API as there would be conditionals all over the place to support it. But if you created a version with support for that API I suppose we could release it as 1.99.0 or something.

I do not have a working version and will not have.

I totally understand your reason and we'll stick to version 1.x until we migrate to PuppetDB 3.x ;-)