Using new Node and Catalog fields available in pypuppetdb 0.2.1

Showing the Code ID field in the catalogs page. This is currently
unused in PuppetDB as of 3.2.2 but may be useful when it will be used

If available, using the latest_report_hash field of the node object
in the index and nodes templates for the link to the latest report
available for the node.

Updating the report_latest function in app.py to query the nodes
endpoint and redirecting using the latest_report_hash field if available.
If not query the reports endpoint for the node's latest report.
This commit is contained in:
Corey Hammerton
2015-12-28 16:07:43 -05:00
parent 40bd73415d
commit 43e37fdf64
5 changed files with 53 additions and 17 deletions

View File

@@ -516,26 +516,44 @@ def report_latest(env, node_name):
envs = environments()
check_env(env, envs)
if env == '*':
node_query = '["=", "certname", "{0}"]'.format(node_name)
else:
node_query = '["and",' \
'["=", "report_environment", "{0}"],' \
'["=", "certname", "{1}"]]'.format(env, node_name)
try:
node = next(get_or_abort(puppetdb.nodes,
query=node_query,
with_status=True))
except StopIteration:
abort(404)
if node.latest_report_hash is not None:
hash_ = node.latest_report_hash
else:
if env == '*':
query='["and",' \
'["=", "certname", "{0}"],' \
'["=", "latest_report?", true]]'.format(node_name)
'["=", "latest_report?", true]]'.format(node.name)
else:
query='["and",' \
'["=", "environment", "{0}"],' \
'["=", "certname", "{1}"],' \
'["=", "latest_report?", true]]'.format(
env,
node_name)
node.name)
reports = get_or_abort(puppetdb.reports, query=query)
try:
report = next(reports)
hash_ = report.hash_
except StopIteration:
abort(404)
return redirect(
url_for('report', env=env, node_name=node_name, report_id=report.hash_))
url_for('report', env=env, node_name=node_name, report_id=hash_))
@app.route('/report/<node_name>/<report_id>', defaults={'env': app.config['DEFAULT_ENVIRONMENT']})

View File

@@ -10,6 +10,7 @@
<th>Hostname</th>
<th>Version</th>
<th>Transaction UUID</th>
<th>Code ID</th>
</tr>
</thead>
<tbody>
@@ -17,6 +18,7 @@
<td><a href="{{url_for('node', env=current_env, node_name=catalog.node)}}">{{catalog.node}}</a></td>
<td>{{catalog.version}}</td>
<td>{{catalog.transaction_uuid}}</td>
<td>{{catalog.code_id}}</td>
</tr>
</tbody>
</table>

View File

@@ -79,14 +79,22 @@
{% if node.status != 'unchanged' %}
<tr>
<td>
{% if node.latest_report_hash %}
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}}
{% else %}
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}}
{% endif %}
</td>
<td>
<a href="{{url_for('node', env=current_env, node_name=node.name)}}">{{ node.name }}</a>
</td>
<td>
{% if node.report_timestamp %}
{% if node.latest_report_hash %}
<a href="{{url_for('report', env=current_env, node_name=node.name, report_id=node.latest_report_hash)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
{% else %}
<a href="{{url_for('report_latest', env=current_env, node_name=node.name)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
{% endif %}
{% else %}
<i class="large ban circle icon"></i>
{% endif %}

View File

@@ -18,13 +18,21 @@
{% for node in nodes %}
<tr>
<td>
{% if node.latest_report_hash %}
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}}
{% else %}
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}}
{% endif %}
</td>
<td><a href="{{url_for('node', env=current_env, node_name=node.name)}}">{{node.name}}</a></td>
<td><a rel="utctimestamp" href="{{url_for('catalog_node', env=current_env, node_name=node.name)}}">{{node.catalog_timestamp}}</a></td>
<td>
{% if node.report_timestamp %}
{% if node.latest_report_hash %}
<a href="{{url_for('report', env=current_env, node_name=node.name, report_id=node.latest_report_hash)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
{% else %}
<a href="{{url_for('report_latest', env=current_env, node_name=node.name)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
{% endif %}
{% else %}
<i class="large ban circle icon"></i>
{% endif %}

View File

@@ -32,7 +32,7 @@ setup(
"Flask >= 0.10.1",
"Flask-WTF >= 0.9.4, <= 0.9.5",
"WTForms < 2.0",
"pypuppetdb >= 0.2.0, < 0.3.0",
"pypuppetdb >= 0.2.1, < 0.3.0",
],
keywords="puppet puppetdb puppetboard",
classifiers=[