本文整理汇总了Python中pypuppetdb.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main(hostname, to=None, num_days=7, cache_dir=None, dry_run=False):
"""
main entry point
:param hostname: PuppetDB hostname
:type hostname: string
:param to: list of addresses to send mail to
:type to: list
:param num_days: the number of days to report on, default 7
:type num_days: int
:param cache_dir: absolute path to where to cache data from PuppetDB
:type cache_dir: string
:param dry_run: whether to actually send, or just print what would be sent
:type dry_run: boolean
"""
pdb = connect(host=hostname)
# essentially figure out all these for yesterday, build the tables, serialize the result as JSON somewhere. then just keep the last ~7 days json files
date_data = {}
dates = [] # ordered
date_list = get_date_list(num_days)
localtz = tzlocal.get_localzone()
start_date = date_list[0]
end_date = date_list[-1] - datetime.timedelta(hours=23, minutes=59, seconds=59)
for query_date in date_list:
end = query_date
start = query_date - datetime.timedelta(days=1) + datetime.timedelta(seconds=1)
date_s = (query_date - datetime.timedelta(hours=1)).astimezone(localtz).strftime('%a %m/%d')
date_data[date_s] = get_data_for_timespan(hostname, pdb, start, end, cache_dir=cache_dir)
dates.append(date_s)
html = format_html(hostname, dates, date_data, start_date, end_date)
subject = 'daily puppet(db) run summary for {host}'.format(host=hostname)
send_mail(to, subject, html, dry_run=dry_run)
return True
开发者ID:bhughes4128,项目名称:pypuppetdb-daily-report,代码行数:34,代码来源:pypuppetdb_daily_report.py
示例2: get_host_list
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
开发者ID:aholen,项目名称:ansible-puppet-inventory,代码行数:8,代码来源:puppetdb.py
示例3: make_it_so
def make_it_so():
args = argparser()
db = pypuppetdb.connect(host=PUPPETDB_HOST, port=PUPPETDB_PORT)
if args.section == 'nodes':
nodes_query(db, args.query)
if args.section == 'facts':
fact_query(db, args.query)
开发者ID:daniellawrence,项目名称:nodefactinfo,代码行数:9,代码来源:nodefactinfo.py
示例4: get_host_list_based_on_environments
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
开发者ID:aholen,项目名称:ansible-puppet-inventory,代码行数:12,代码来源:puppetdb.py
示例5: read_callback
def read_callback():
puppetdb = connect(
api_version=3,
host=PUPPETDB_HOST,
port=PUPPETDB_PORT,
ssl_verify=PUPPETDB_SSL,
ssl_key=PUPPETDB_KEY,
ssl_cert=PUPPETDB_CERT,
timeout=PUPPETDB_TIMEOUT,
)
prefix = "com.puppetlabs.puppetdb.query.population"
num_nodes = puppetdb.metric("{0}{1}".format(prefix, ":type=default,name=num-nodes"))
num_resources = puppetdb.metric("{0}{1}".format(prefix, ":type=default,name=num-resources"))
avg_resources_node = puppetdb.metric("{0}{1}".format(prefix, ":type=default,name=avg-resources-per-node"))
# Ftech nodes
nodes = puppetdb.nodes(unreported=UNREPORTED_TIME, with_status=True)
# Init stats
stats = {"changed": 0, "unchanged": 0, "failed": 0, "unreported": 0, "noop": 0}
for node in nodes:
if node.status == "unreported":
stats["unreported"] += 1
elif node.status == "changed":
stats["changed"] += 1
elif node.status == "failed":
stats["failed"] += 1
elif node.status == "noop":
stats["noop"] += 1
else:
stats["unchanged"] += 1
log_verbose("population: %s\n" % num_nodes["Value"])
dispatch_value(num_nodes["Value"], "population", "gauge")
log_verbose("unreported: %s\n" % stats["unreported"])
dispatch_value(stats["unreported"], "unreported", "gauge")
log_verbose("changed: %s\n" % stats["changed"])
dispatch_value(stats["changed"], "changed", "gauge")
log_verbose("failed: %s\n" % stats["failed"])
dispatch_value(stats["failed"], "failed", "gauge")
log_verbose("noop: %s\n" % stats["noop"])
dispatch_value(stats["noop"], "noop", "gauge")
log_verbose("unchanged: %s\n" % stats["unchanged"])
dispatch_value(stats["unchanged"], "unchanged", "gauge")
开发者ID:Mavenhut,项目名称:collectd-python-extra,代码行数:51,代码来源:puppetdb.py
示例6: check_user
def check_user(username):
puppet_db = pypuppetdb.connect(host=settings.PUPPETDB_HOST,
port=settings.PUPPETDB_PORT,
ssl_verify=settings.PUPPETDB_SSL_VERIFY,
ssl_key=settings.PUPPETDB_KEY,
ssl_cert=settings.PUPPETDB_CERT)
try:
node = puppet_db.node(settings.PUPPETDB_NODE)
return next(node.resources(type_='User', title=username))
except ConnectionError:
return False
except StopIteration:
return None
开发者ID:nedap,项目名称:django-pypuppetdb,代码行数:14,代码来源:user_authentication.py
示例7: get_puppetdb
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'],)
PUPPETDB = puppetdb
return PUPPETDB
开发者ID:bootc,项目名称:puppetboard,代码行数:14,代码来源:core.py
示例8: __init__
def __init__(self, hostname, port, api_version, output_dir,
nodefacts=None, query=None, environment=None):
self.db = connect(host=hostname,
port=port,
api_version=api_version,
timeout=20)
self.db.resources = self.db.resources
self.output_dir = output_dir
self.environment = environment
if not nodefacts:
self.nodefacts = self.get_nodefacts()
else:
self.nodefacts = nodefacts
self.query = query
开发者ID:daniellawrence,项目名称:external_naginator,代码行数:14,代码来源:external_naginator.py
示例9: __init__
def __init__(self, hostname, port, api_version,
query=None, environment=None,
ssl_key=None, ssl_cert=None,
timeout=20):
from pypuppetdb import connect
self.db = connect(host=hostname,
port=port,
ssl_key=ssl_key,
ssl_cert=ssl_cert,
api_version=api_version,
timeout=timeout)
self.db.resources = self.db.resources
self.environment = environment
if query is None:
query = {}
self.query = query
开发者ID:jmamma,项目名称:hivemind_contrib,代码行数:16,代码来源:puppetdb.py
示例10: main
def main():
"""
Main function
"""
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")
parser.add_argument("--localsite", "-l", default="true")
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARN)
database = 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(database, resource_type, args.localsite, templates))
开发者ID:ckonstanski,项目名称:puppetdb-stencil,代码行数:19,代码来源:puppetdb_stencil.py
示例11: main
def main():
options = cmd()
if options.verify == 'yes':
ssl_verify = True
elif options.verify == 'no':
ssl_verify = False
else:
ssl_verify = options.verify
p = pypuppetdb.connect(host=options.server, port=options.port,
ssl_verify=ssl_verify, ssl_key=options.clientkey,
ssl_cert=options.clientcert,
timeout=options.timeout)
node = get_node(options.hostname, p)
if not node.report_timestamp:
print("UNKNOWN - This machine hasn't checked in with us yet")
sys.exit(3)
critical_seconds = 60 * 60 * options.critical
warning_seconds = 60 * 60 * options.warning
(delta, delta_seconds) = time_elapsed(node.report_timestamp)
status = node_status(options.hostname, p)
if status is not None and status['failures'] > 0:
print(('CRITICAL - We have {0} failure(s). Last report was '
'{1} ago'.format(status['failures'], delta)))
sys.exit(2)
elif delta_seconds < warning_seconds:
print('OK - Last run happened {0} ago'.format(delta))
sys.exit(0)
elif warning_seconds <= delta_seconds < critical_seconds:
print('WARNING - Last run happened {0} ago'.format(delta))
sys.exit(1)
elif delta_seconds >= critical_seconds:
print('CRITICAL - Last run happened {0} ago'.format(delta))
sys.exit(2)
else:
print("UNKNOWN - Something went wrong determining this node's state")
sys.exit(3)
开发者ID:cultuurnet,项目名称:check_puppetdb_node,代码行数:42,代码来源:check_puppetdb_node.py
示例12: __init__
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
开发者ID:adamancini,项目名称:ansible-inventory-puppetdb,代码行数:20,代码来源:puppetdb.py
示例13: main
def main():
"""
Main function
"""
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)
database = 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(database, resource_type, templates))
开发者ID:matthewfischer,项目名称:puppetdb-stencil,代码行数:21,代码来源:puppetdb_stencil.py
示例14: api2
def api2():
"""Set up a connection to PuppetDB with API version 2."""
puppetdb = connect(api_version=2)
return puppetdb
开发者ID:KlavsKlavsen,项目名称:pypuppetdb,代码行数:4,代码来源:conftest.py
示例15: api3
def api3():
"""Set up a connection to PuppetDB with API version 3."""
puppetdb = connect(api_version=3)
return puppetdb
开发者ID:KlavsKlavsen,项目名称:pypuppetdb,代码行数:4,代码来源:conftest.py
示例16: Flask
from pypuppetdb import connect
from puppetboard.forms import QueryForm
from puppetboard.utils import get_or_abort, yield_or_stop, ten_reports
app = Flask(__name__)
app.config.from_object("puppetboard.default_settings")
app.config.from_envvar("PUPPETBOARD_SETTINGS", silent=True)
app.secret_key = os.urandom(24)
puppetdb = connect(
api_version=app.config["PUPPETDB_API"],
host=app.config["PUPPETDB_HOST"],
port=app.config["PUPPETDB_PORT"],
ssl=app.config["PUPPETDB_SSL"],
ssl_key=app.config["PUPPETDB_KEY"],
ssl_cert=app.config["PUPPETDB_CERT"],
timeout=app.config["PUPPETDB_TIMEOUT"],
)
numeric_level = getattr(logging, app.config["LOGLEVEL"].upper(), None)
if not isinstance(numeric_level, int):
raise ValueError("Invalid log level: %s" % loglevel)
logging.basicConfig(level=numeric_level)
log = logging.getLogger(__name__)
def stream_template(template_name, **context):
app.update_template_context(context)
t = app.jinja_env.get_template(template_name)
开发者ID:heykumaran,项目名称:puppetboard,代码行数:31,代码来源:app.py
示例17: test_connect_api_v3
def test_connect_api_v3():
puppetdb = pypuppetdb.connect(api_version=3)
assert puppetdb.version == 'v3'
开发者ID:NeCTAR-RC,项目名称:pypuppetdb,代码行数:3,代码来源:test_connect.py
示例18: read_callback
def read_callback():
puppetdb = connect(
api_version=3,
host=PUPPETDB_HOST,
port=PUPPETDB_PORT,
ssl_verify=PUPPETDB_SSL,
ssl_key=PUPPETDB_KEY,
ssl_cert=PUPPETDB_CERT,
timeout=PUPPETDB_TIMEOUT,
)
prefix = 'com.puppetlabs.puppetdb.query.population'
num_nodes = puppetdb.metric(
"{0}{1}".format(prefix, ':type=default,name=num-nodes'))
num_resources = puppetdb.metric(
"{0}{1}".format(prefix, ':type=default,name=num-resources'))
avg_resources_node = puppetdb.metric(
"{0}{1}".format(prefix, ':type=default,name=avg-resources-per-node'))
# Fetch nodes
nodes = puppetdb.nodes(
unreported=UNREPORTED_TIME,
with_status=True)
# Init stats
stats = {
'changed': 0,
'unchanged': 0,
'failed': 0,
'unreported': 0,
'noop': 0,
}
for node in nodes:
if node.status == 'unreported':
stats['unreported'] += 1
elif node.status == 'changed':
stats['changed'] += 1
elif node.status == 'failed':
stats['failed'] += 1
elif node.status == 'noop':
stats['noop'] += 1
else:
stats['unchanged'] += 1
log_verbose('population: %s\n' % num_nodes['Value'])
dispatch_value(num_nodes['Value'], 'population', 'gauge')
log_verbose('resources: %s\n' % num_resources['Value'])
dispatch_value(num_resources['Value'], 'resources', 'gauge')
log_verbose('resources_per_node: %s\n' % avg_resources_node['Value'])
dispatch_value(avg_resources_node['Value'], 'resources_per_node', 'gauge')
log_verbose('unreported: %s\n' % stats['unreported'])
dispatch_value(stats['unreported'], 'unreported', 'gauge')
log_verbose('changed: %s\n' % stats['changed'])
dispatch_value(stats['changed'], 'changed', 'gauge')
log_verbose('failed: %s\n' % stats['failed'])
dispatch_value(stats['failed'], 'failed', 'gauge')
log_verbose('noop: %s\n' % stats['noop'])
dispatch_value(stats['noop'], 'noop', 'gauge')
log_verbose('unchanged: %s\n' % stats['unchanged'])
dispatch_value(stats['unchanged'], 'unchanged', 'gauge')
开发者ID:exoscale,项目名称:collectd-python-extra,代码行数:68,代码来源:puppetdb.py
示例19: puppetdb_connect
def puppetdb_connect():
"""Connects to PuppetDB using the parameters specified in the
application configuration."""
# Connect to PuppetDB
return pypuppetdb.connect(app.config['PUPPETDB_HOST'], port=app.config['PUPPETDB_PORT'], ssl_cert=app.config['PUPPETDB_SSL_CERT'], ssl_key=app.config['PUPPETDB_SSL_KEY'], ssl_verify=app.config['PUPPETDB_SSL_VERIFY'])
开发者ID:ahead-justinhensley,项目名称:cortex,代码行数:6,代码来源:puppet.py
示例20: Flask
from pypuppetdb.errors import ExperimentalDisabledError
from puppetboard.forms import QueryForm
from puppetboard.utils import get_or_abort, yield_or_stop, ten_reports
app = Flask(__name__)
app.config.from_object("puppetboard.default_settings")
app.config.from_envvar("PUPPETBOARD_SETTINGS", silent=True)
app.secret_key = os.urandom(24)
puppetdb = connect(
host=app.config["PUPPETDB_HOST"],
port=app.config["PUPPETDB_PORT"],
ssl=app.config["PUPPETDB_SSL"],
ssl_key=app.config["PUPPETDB_KEY"],
ssl_cert=app.config["PUPPETDB_CERT"],
timeout=app.config["PUPPETDB_TIMEOUT"],
experimental=app.config["PUPPETDB_EXPERIMENTAL"],
)
numeric_level = getattr(logging, app.config["LOGLEVEL"].upper(), None)
if not isinstance(numeric_level, int):
raise ValueError("Invalid log level: %s" % loglevel)
logging.basicConfig(level=numeric_level)
log = logging.getLogger(__name__)
def stream_template(template_name, **context):
app.update_template_context(context)
t = app.jinja_env.get_template(template_name)
开发者ID:hunner,项目名称:puppetboard,代码行数:31,代码来源:app.py
注:本文中的pypuppetdb.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论