Skip to main content

Python wrapper for puppetDB API

Project description

Puppetdb-api is python API around the puppetDB REST API.

QUERIES

Nodes, facts and resources can by queried by matching nodes, facts and resources with boolean operators or, and and not.

All the queries can be done as a raw queries, to obtain the raw JSON, that puppetDB returns.

NODES

>>> p = PuppetDB('https://puppetdb.example.com')
>>> p.nodes(Or(Fact('role', 'example', '='), Resource('Class', 'Klass_name', '=')))
[u'node1.example.com', u'node2.example.com']
>>> p.nodes_raw(Node('node1.example.com', '='))
[{u'deactivated': None, u'facts_timestamp': u'2014-08-25T19:45:00.707Z', u'name': u'node1.example.com', u'report_timestamp': u'2014-08-25T19:46:09.616Z', u'catalog_timestamp': u'2014-08-25T19:45:14.896Z'}]

FACTS

Values for multiple facts can be obtained by passing multiple facts names to facts argument.

>>> p = PuppetDB('https://puppetdb.example.com')
>>> p.facts(query=And(Fact('role', 'example', '='), Not(Resource('Class', 'Klass_name', '='))), facts=['role', 'hostname'])
{u'hostname': [u'hostname1'], u'role': [u'example']}
>>> p.facts_raw(Node('node1.example.com', '~'))
[{u'certname': u'node1.example.com', u'name': u'clientversion', u'value': u'3.8.7'}, {u'certname': u'node1.example.com', u'name': u'uptime_hours', u'value': u'656'}]

RESOURCES

Values for multiple resources can be obtained by passing multiple resources names to resources argument.

>>> p = PuppetDB('https://puppetdb.example.com')
>>> p.resources(query=And(Fact('role', 'example', '='), Not(Resource('Class', 'Klass_name', '='))), resources=['Some_resource'])
{u'Some_resource': [u'Resource_title']}
>>> p.resources_raw(query=Node('node1.example.com', '~'), resources=['Some_resource'])
[{u'certname': u'node1.example.com', u'resource': u'8df598f3923a05e543e884d247d74cac08087a45', u'parameters': {}, u'title': u'resource_title', u'tags': [u'tag1', u'tag2'], u'exported': False, u'file': u'/etc/puppet/environments/example/example.pp', u'line': 25, u'type': u'Some_resource'}]

INSTALL

$ pip install puppetdb_api

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

puppetdb_api-1.1.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file puppetdb_api-1.1.tar.gz.

File metadata

  • Download URL: puppetdb_api-1.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for puppetdb_api-1.1.tar.gz
Algorithm Hash digest
SHA256 a64b305a976d2256be40259e777c8d654f8cb29e83fc06597c54c028eb45e2c7
MD5 0310e4b877d4578e4ad74ae694a8cf0c
BLAKE2b-256 22c7d4562fb8bd57a165185db41fb6b0e293d88d61118fa568060fb62db1ee8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page