How to use the pypuppetdb.connect function in pypuppetdb

To help you get started, we’ve selected a few pypuppetdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github voxpupuli / pypuppetdb / tests / test_connect.py View on Github external
def test_connect_api():
    puppetdb = pypuppetdb.connect()
    assert puppetdb.version == 'v4'
github dmsimard / ansible-inventory-puppetdb / puppetdb.py View on Github external
def __init__(self, refresh):
        self.config = load_config()
        if not self.config:
            sys.exit('Error: Could not load any config files: {0}'
                     .format(', '.join(CONFIG_FILES)))

        puppetdb_config = {
            'host': self.config.get('host'),
            'port': self.config.get('port'),
            'timeout': self.config.get('timeout'),
            'ssl_verify': self.config.get('ssl_verify'),
            'ssl_key': self.config.get('ssl_key') or None,
            'ssl_cert': self.config.get('ssl_cert') or None
        }

        self.puppetdb = connect(**puppetdb_config)

        self.cache_file = self.config.get('cache_file')
        self.cache_duration = self.config.get('cache_duration')
        self.refresh = refresh
github bootc / pypuppetdbquery / examples / facts.py View on Github external
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Query for selected facts on matching nodes using :mod:`pypuppetdb`.
"""

import pypuppetdb
import pypuppetdbquery

pdb = pypuppetdb.connect()

node_facts = pypuppetdbquery.query_facts(
    pdb,
    '(processorcount=4 or processorcount=8) and kernel=Linux',
    ['/^lsb/', 'architecture'])

for node in node_facts:
    facts = node_facts[node]
    print(node, facts)
github southampton / cortex / corpus / puppetdb_connector.py View on Github external
def connect(self):
		self.db = pypuppetdb.connect(self.host, port=self.port, ssl_cert=self.ssl_cert, ssl_key=self.ssl_key, ssl_verify=self.ssl_verify)
github visibilityspots / ansible-puppet-inventory / puppetdb.py View on Github external
def get_host_list_based_on_environments(self):
        db = connect(api_version=4, host=self.puppetdb_server, port=self.puppetdb_server_port)
        json_data_toReturn = ''
        inv = {}
        for env in self.puppetdb_environments:
            inv.update( { env: [] })

            facts = db.facts('fqdn', environment=env)
            for fact in facts:
                inv[env].append(fact.value)

        return inv
github visibilityspots / ansible-puppet-inventory / puppetdb.py View on Github external
def get_host_list(self):
        db = connect(api_version=3, host=self.puppetdb_server, port=self.puppetdb_server_port)
        nodes = db.nodes()
        inv = { 'all': []}
        for node in nodes:
            inv['all'].append(node.name)

        return inv
github daenney / puppetdb-stencil / puppetdb_stencil.py View on Github external
return template.render(resource_type=resource_type,
            resources=resources, metaparams=METAPARAMS)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='puppetdb_stencil')
    parser.add_argument('resource_types', metavar='RESOURCE_TYPE', nargs='+')
    parser.add_argument('--templates', '-t', metavar='TEMPLATE', nargs='*')
    parser.add_argument('--debug', '-d', action='store_true')
    parser.add_argument('--host', '-H', default='localhost')
    parser.add_argument('--port', '-p', default='8080')

    args = parser.parse_args()
    logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARN)

    db = pypuppetdb.connect(host=args.host, port=args.port)

    for resource_type in args.resource_types:
        templates = ['{0}.jinja2'.format(resource_type)]
        if args.templates:
            templates += args.templates
        print(render_resources(db, resource_type, templates))
github voxpupuli / puppetboard / puppetboard / core.py View on Github external
def get_puppetdb():
    global PUPPETDB

    if PUPPETDB is None:
        app = get_app()
        puppetdb = connect(host=app.config['PUPPETDB_HOST'],
                           port=app.config['PUPPETDB_PORT'],
                           ssl_verify=app.config['PUPPETDB_SSL_VERIFY'],
                           ssl_key=app.config['PUPPETDB_KEY'],
                           ssl_cert=app.config['PUPPETDB_CERT'],
                           timeout=app.config['PUPPETDB_TIMEOUT'],
                           protocol=app.config['PUPPETDB_PROTO'],)
        PUPPETDB = puppetdb

    return PUPPETDB