本文整理汇总了Python中puppetboard.utils.yield_or_stop函数的典型用法代码示例。如果您正苦于以下问题:Python yield_or_stop函数的具体用法?Python yield_or_stop怎么用?Python yield_or_stop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yield_or_stop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: node
def node(env, node_name):
"""Display a dashboard for a node showing as much data as we have on that
node. This includes facts and reports but not Resources as that is too
heavy to do within a single request.
:param env: Ensure that the node, facts and reports are in this environment
:type env: :obj:`string`
"""
envs = environments()
check_env(env, envs)
if env == '*':
query = '["=", "certname", "{0}"]]'.format(node_name)
else:
query='["and", ["=", "environment", "{0}"],' \
'["=", "certname", "{1}"]]'.format(env, node_name),
node = get_or_abort(puppetdb.node, node_name)
facts = node.facts()
reports = get_or_abort(puppetdb.reports,
query=query,
limit=app.config['REPORTS_COUNT'],
order_by='[{"field": "start_time", "order": "desc"}]')
reports, reports_events = tee(reports)
report_event_counts = {}
for report in reports_events:
report_event_counts[report.hash_] = {}
for event in report.events():
if event.status == 'success':
try:
report_event_counts[report.hash_]['successes'] += 1
except KeyError:
report_event_counts[report.hash_]['successes'] = 1
elif event.status == 'failure':
try:
report_event_counts[report.hash_]['failures'] += 1
except KeyError:
report_event_counts[report.hash_]['failures'] = 1
elif event.status == 'noop':
try:
report_event_counts[report.hash_]['noops'] += 1
except KeyError:
report_event_counts[report.hash_]['noops'] = 1
elif event.status == 'skipped':
try:
report_event_counts[report.hash_]['skips'] += 1
except KeyError:
report_event_counts[report.hash_]['skips'] = 1
return render_template(
'node.html',
node=node,
facts=yield_or_stop(facts),
reports=yield_or_stop(reports),
reports_count=app.config['REPORTS_COUNT'],
report_event_counts=report_event_counts,
envs=envs,
current_env=env)
开发者ID:octomike,项目名称:puppetboard,代码行数:59,代码来源:app.py
示例2: node
def node(node_name):
"""Display a dashboard for a node showing as much data as we have on that
node. This includes facts and reports but not Resources as that is too
heavy to do within a single request.
"""
node = get_or_abort(puppetdb.node, node_name)
facts = node.facts()
reports = ten_reports(node.reports())
return render_template(
'node.html',
node=node,
facts=yield_or_stop(facts),
reports=yield_or_stop(reports))
开发者ID:denmat,项目名称:puppetboard,代码行数:13,代码来源:app.py
示例3: node
def node(node_name):
"""Display a dashboard for a node showing as much data as we have on that
node. This includes facts and reports but not Resources as that is too
heavy to do within a single request.
"""
node = get_or_abort(puppetdb.node, node_name)
facts = node.facts()
reports = limit_reports(node.reports(), app.config["REPORTS_COUNT"])
return render_template(
"node.html",
node=node,
facts=yield_or_stop(facts),
reports=yield_or_stop(reports),
reports_count=app.config["REPORTS_COUNT"],
)
开发者ID:erikanderson,项目名称:puppetboard,代码行数:15,代码来源:app.py
示例4: fact
def fact(env, fact):
"""Fetches the specific fact from PuppetDB and displays its value per
node for which this fact is known.
:param env: Searches for facts in this environment
:type env: :obj:`string`
:param fact: Find all facts with this name
:type fact: :obj:`string`
"""
envs = environments()
check_env(env, envs)
# we can only consume the generator once, lists can be doubly consumed
# om nom nom
render_graph = False
if fact in graph_facts:
render_graph = True
if env == "*":
query = None
else:
query = EqualsOperator("environment", env)
localfacts = [f for f in yield_or_stop(puppetdb.facts(name=fact, query=query))]
return Response(
stream_with_context(
stream_template(
"fact.html", name=fact, render_graph=render_graph, facts=localfacts, envs=envs, current_env=env
)
)
)
开发者ID:nikolaik,项目名称:puppetboard,代码行数:31,代码来源:app.py
示例5: fact_value
def fact_value(env, fact, value):
"""On asking for fact/value get all nodes with that fact.
:param env: Searches for facts in this environment
:type env: :obj:`string`
:param fact: Find all facts with this name
:type fact: :obj:`string`
:param value: Filter facts whose value is equal to this
:type value: :obj:`string`
"""
check_env(env)
if env == '*':
query = None
else:
query = '["=", "environment", "{0}"]'.format(env)
facts = get_or_abort(puppetdb.facts,
name=fact,
value=value,
query=query)
localfacts = [f for f in yield_or_stop(facts)]
return render_template(
'fact.html',
name=fact,
value=value,
facts=localfacts,
envs=envs,
current_env=env)
开发者ID:tjayl,项目名称:puppetboard,代码行数:28,代码来源:app.py
示例6: nodes
def nodes(env):
"""Fetch all (active) nodes from PuppetDB and stream a table displaying
those nodes.
Downside of the streaming aproach is that since we've already sent our
headers we can't abort the request if we detect an error. Because of this
we'll end up with an empty table instead because of how yield_or_stop
works. Once pagination is in place we can change this but we'll need to
provide a search feature instead.
:param env: Search for nodes in this (Catalog and Fact) environment
:type env: :obj:`string`
"""
envs = environments()
check_env(env, envs)
if env == "*":
query = None
else:
query = AndOperator()
query.add(EqualsOperator("catalog_environment", env))
query.add(EqualsOperator("facts_environment", env))
status_arg = request.args.get("status", "")
nodelist = puppetdb.nodes(query=query, unreported=app.config["UNRESPONSIVE_HOURS"], with_status=True)
nodes = []
for node in yield_or_stop(nodelist):
if status_arg:
if node.status == status_arg:
nodes.append(node)
else:
nodes.append(node)
return Response(stream_with_context(stream_template("nodes.html", nodes=nodes, envs=envs, current_env=env)))
开发者ID:nikolaik,项目名称:puppetboard,代码行数:33,代码来源:app.py
示例7: nodes
def nodes(env):
"""Fetch all (active) nodes from PuppetDB and stream a table displaying
those nodes.
Downside of the streaming aproach is that since we've already sent our
headers we can't abort the request if we detect an error. Because of this
we'll end up with an empty table instead because of how yield_or_stop
works. Once pagination is in place we can change this but we'll need to
provide a search feature instead.
:param env: Search for nodes in this (Catalog and Fact) environment
:type env: :obj:`string`
"""
check_env(env)
status_arg = request.args.get('status', '')
nodelist = puppetdb.nodes(
query='["and", {0}]'.format(
", ".join('["=", "{0}", "{1}"]'.format(field, env)
for field in ['catalog_environment', 'facts_environment'])),
unreported=app.config['UNRESPONSIVE_HOURS'],
with_status=True)
nodes = []
for node in yield_or_stop(nodelist):
if status_arg:
if node.status == status_arg:
nodes.append(node)
else:
nodes.append(node)
return Response(stream_with_context(
stream_template('nodes.html',
nodes=nodes,
envs=envs,
current_env=env)))
开发者ID:ghakfoort,项目名称:puppetboard,代码行数:34,代码来源:app.py
示例8: mwapps
def mwapps():
localfacts = [f for f in yield_or_stop(puppetdb.facts(name='mwapps'))]
funfacts = []
for fact in localfacts:
if fact.value == "false": continue
for appl in fact.value.split(";"):
if ":" in appl:
(appn, instnr) = appl.split(":")
node = puppetdb.node(fact.node)
mwapp_factname = "mwapp_" + appn + "_" + instnr + "_version"
try:
applver = node.fact(mwapp_factname).value
except:
applver = "Err"
pass
tmphash = { "node" : fact.node, "application" : appn, "instance" : instnr, "version" : applver }
funfacts.append(tmphash)
else:
tmphash = { "node" : fact.node, "application" : appl, "instance" : "NA", "version" : applver}
funfacts.append(tmphash)
return Response(stream_with_context(stream_template(
'mwapps.html',
name='Meltwater Apps',
facts=funfacts)))
开发者ID:meltwater,项目名称:puppetboard,代码行数:26,代码来源:app.py
示例9: nodes
def nodes():
"""Fetch all (active) nodes from PuppetDB and stream a table displaying
those nodes.
Downside of the streaming aproach is that since we've already sent our
headers we can't abort the request if we detect an error. Because of this
we'll end up with an empty table instead because of how yield_or_stop
works. Once pagination is in place we can change this but we'll need to
provide a search feature instead.
"""
status_arg = request.args.get('status', '')
nodelist = puppetdb.nodes(
unreported=app.config['UNRESPONSIVE_HOURS'],
with_status=True)
node_facts = puppetdb.facts(name="operatingsystem")
osfacts = {}
for f in node_facts:
if not osfacts.has_key(f.node):
osfacts[f.node] = f.value.lower()
nodes = []
for node in yield_or_stop(nodelist):
if osfacts.has_key(node.name):
node.os = osfacts[node.name]
if status_arg:
if node.status == status_arg:
nodes.append(node)
else:
nodes.append(node)
return Response(stream_with_context(
stream_template('nodes.html', nodes=nodes)))
开发者ID:amwilson,项目名称:puppetboard,代码行数:33,代码来源:app.py
示例10: node
def node(env, node_name):
"""Display a dashboard for a node showing as much data as we have on that
node. This includes facts and reports but not Resources as that is too
heavy to do within a single request.
:param env: Ensure that the node, facts and reports are in this environment
:type env: :obj:`string`
"""
envs = environments()
check_env(env, envs)
query = AndOperator()
if env != '*':
query.add(EqualsOperator("environment", env))
query.add(EqualsOperator("certname", node_name))
node = get_or_abort(puppetdb.node, node_name)
facts = node.facts()
return render_template(
'node.html',
node=node,
facts=yield_or_stop(facts),
envs=envs,
current_env=env,
columns=REPORTS_COLUMNS[:2])
开发者ID:stoyansbg,项目名称:puppetboard,代码行数:26,代码来源:app.py
示例11: fact
def fact(fact):
"""Fetches the specific fact from PuppetDB and displays its value per
node for which this fact is known."""
# we can only consume the generator once, lists can be doubly consumed
# om nom nom
localfacts = [f for f in yield_or_stop(puppetdb.facts(name=fact))]
return Response(stream_with_context(stream_template("fact.html", name=fact, facts=localfacts)))
开发者ID:johan-open-future,项目名称:puppetboard,代码行数:7,代码来源:app.py
示例12: test_stop_http_error
def test_stop_http_error():
def my_generator():
yield 1
raise HTTPError
yield 2
gen = utils.yield_or_stop(my_generator())
for val in gen:
assert 1 == val
开发者ID:bootc,项目名称:puppetboard,代码行数:8,代码来源:test_utils.py
示例13: test_stop_conn_error
def test_stop_conn_error():
def my_generator():
yield 1
raise ConnectionError
yield 2
gen = utils.yield_or_stop(my_generator())
for val in gen:
assert 1 == val
开发者ID:bootc,项目名称:puppetboard,代码行数:8,代码来源:test_utils.py
示例14: reports
def reports(env, page):
"""Displays a list of reports and status from all nodes, retreived using the
reports endpoint, sorted by start_time.
:param env: Search for all reports in this environment
:type env: :obj:`string`
:param page: Calculates the offset of the query based on the report count
and this value
:type page: :obj:`int`
"""
envs = environments()
check_env(env, envs)
if env == '*':
reports_query = None
total_query = '["extract", [["function", "count"]], ["~", "certname", ""]]'
else:
reports_query = '["=", "environment", "{0}"]'.format(env)
total_query = '["extract", [["function", "count"]],'\
'["and", ["=", "environment", "{0}"]]]'.format(env)
reports = get_or_abort(puppetdb.reports,
query=reports_query,
limit=app.config['REPORTS_COUNT'],
offset=(page-1) * app.config['REPORTS_COUNT'],
order_by='[{"field": "start_time", "order": "desc"}]')
total = get_or_abort(puppetdb._query,
'reports',
query=total_query)
total = total[0]['count']
reports, reports_events = tee(reports)
report_event_counts = {}
if total == 0 and page != 1:
abort(404)
for report in reports_events:
counts = get_or_abort(puppetdb.event_counts,
query='["and",' \
'["=", "environment", "{0}"],' \
'["=", "certname", "{1}"],' \
'["=", "report", "{2}"]]'.format(
env,
report.node,
report.hash_),
summarize_by="certname")
try:
report_event_counts[report.hash_] = counts[0]
except IndexError:
report_event_counts[report.hash_] = {}
return Response(stream_with_context(stream_template(
'reports.html',
reports=yield_or_stop(reports),
reports_count=app.config['REPORTS_COUNT'],
report_event_counts=report_event_counts,
pagination=Pagination(page, app.config['REPORTS_COUNT'], total),
envs=envs,
current_env=env)))
开发者ID:m4ce,项目名称:puppetboard,代码行数:58,代码来源:app.py
示例15: test_stop_empty
def test_stop_empty():
def my_generator():
yield 1
raise EmptyResponseError
yield 2
gen = utils.yield_or_stop(my_generator())
for val in gen:
assert 1 == val
开发者ID:bootc,项目名称:puppetboard,代码行数:9,代码来源:test_utils.py
示例16: reports_node
def reports_node(node):
"""Fetches all reports for a node and processes them eventually rendering
a table displaying those reports."""
reports = ten_reports(yield_or_stop(
puppetdb.reports('["=", "certname", "{0}"]'.format(node))))
return render_template(
'reports_node.html',
reports=reports,
nodename=node)
开发者ID:denmat,项目名称:puppetboard,代码行数:9,代码来源:app.py
示例17: reports_node
def reports_node(node):
"""Fetches all reports for a node and processes them eventually rendering
a table displaying those reports."""
if app.config["PUPPETDB_EXPERIMENTAL"]:
reports = ten_reports(yield_or_stop(puppetdb.reports('["=", "certname", "{0}"]'.format(node))))
else:
log.warn("Access to experimental endpoint not allowed.")
abort(412)
return render_template("reports_node.html", reports=reports, nodename=node)
开发者ID:hunner,项目名称:puppetboard,代码行数:9,代码来源:app.py
示例18: reports_node
def reports_node(node_name):
"""Fetches all reports for a node and processes them eventually rendering
a table displaying those reports."""
reports = limit_reports(
yield_or_stop(puppetdb.reports(query='["=", "certname", "{0}"]'.format(node_name))), app.config["REPORTS_COUNT"]
)
return render_template(
"reports_node.html", reports=reports, nodename=node_name, reports_count=app.config["REPORTS_COUNT"]
)
开发者ID:erikanderson,项目名称:puppetboard,代码行数:9,代码来源:app.py
示例19: node
def node(node_name):
"""Display a dashboard for a node showing as much data as we have on that
node. This includes facts and reports but not Resources as that is too
heavy to do within a single request.
"""
node = get_or_abort(puppetdb.node, node_name)
facts = [f for f in yield_or_stop(node.facts())]
for fact in facts:
if fact.name == 'operatingsystem':
node.os = fact.value.lower()
reports = node.reports(order_by='[{"field": "receive-time", "order": "desc"}]', limit=app.config['REPORTS_COUNT'])
return render_template(
'node.html',
node=node,
facts=facts,
reports=yield_or_stop(reports),
reports_count=app.config['REPORTS_COUNT'])
开发者ID:amwilson,项目名称:puppetboard,代码行数:18,代码来源:app.py
示例20: reports_node
def reports_node(node):
"""Fetches all reports for a node and processes them eventually rendering
a table displaying those reports."""
if app.config["PUPPETDB_API"] > 2:
reports = ten_reports(yield_or_stop(puppetdb.reports('["=", "certname", "{0}"]'.format(node))))
else:
log.warn("PuppetDB API prior to v3 cannot access reports.")
abort(412)
return render_template("reports_node.html", reports=reports, nodename=node)
开发者ID:heykumaran,项目名称:puppetboard,代码行数:9,代码来源:app.py
注:本文中的puppetboard.utils.yield_or_stop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论