def catalog_submit(env): """Receives the submitted form data from the catalogs page and directs the users to the comparison page. Directs users back to the catalogs page if no form submission data is found. :param env: This parameter only directs the response page to the right environment. If this environment does not exist return the use to the catalogs page with the right environment. :type env: :obj:`string` """ envs = environments() check_env(env, envs) if app.config['ENABLE_CATALOG']: form = CatalogForm(request.form) form.against.choices = [(form.against.data, form.against.data)] if form.validate_on_submit(): compare = form.compare.data against = form.against.data return redirect( url_for('catalog_compare', env=env, compare=compare, against=against)) return redirect(url_for('catalogs', env=env)) else: log.warn('Access to catalog interface disabled by administrator') abort(403)
def catalogs(env): """Lists all nodes with a compiled catalog. :param env: Find the nodes with this catalog_environment value :type env: :obj:`string` """ envs = environments() check_env(env, envs) if app.config['ENABLE_CATALOG']: nodenames = [] catalog_list = [] query = AndOperator() if env != '*': query.add(EqualsOperator("catalog_environment", env)) query.add(NullOperator("catalog_timestamp", False)) order_by_str = '[{"field": "certname", "order": "asc"}]' nodes = get_or_abort(puppetdb.nodes, query=query, with_status=False, order_by=order_by_str) nodes, temp = tee(nodes) for node in temp: nodenames.append(node.name) for node in nodes: table_row = { 'name': node.name, 'catalog_timestamp': node.catalog_timestamp } if len(nodenames) > 1: form = CatalogForm() form.compare.data = node.name form.against.choices = [(x, x) for x in nodenames if x != node.name] table_row['form'] = form else: table_row['form'] = None catalog_list.append(table_row) return render_template('catalogs.html', nodes=catalog_list, envs=envs, current_env=env) else: log.warn('Access to catalog interface disabled by administrator') abort(403)