def _get_data(request, env, roles, virt, group_by_host=False): """Returns processed repository data, filtering nodes based on given args """ roles = [role for role in roles.split(',') if role] data = { 'filter_env': env, 'filter_roles': roles, 'filter_virt': virt, 'show_list': SHOW_LIST_VIEW, 'show_virt': SHOW_VIRT_VIEW, 'show_graph': SHOW_GRAPH_VIEW, 'show_links': SHOW_LINKS, 'query_string': request.META['QUERY_STRING'] } data['roles'] = get_roles() roles_groups = get_role_groups(data['roles']) data['roles_groups'] = roles_groups data['virt_roles'] = ['host', 'guest'] # Get environments before we filter nodes data['nodes'] = get_nodes() data['nodes_extended'] = get_nodes_extended(data['nodes']) data['environments'] = get_environments(data['nodes_extended']) if group_by_host: data['nodes_extended'] = group_nodes_by_host(data['nodes_extended'], roles=data['filter_roles'], env=data['filter_env']) elif data['filter_env'] or data['filter_roles'] or data['filter_virt']: data['nodes_extended'] = filter_nodes(data['nodes_extended'], data['filter_env'], data['filter_roles'], data['filter_virt']) inject_plugin_data(data['nodes_extended']) if not data['nodes_extended']: add_message(request, WARNING, "There are no nodes that fit the supplied criteria.") return data
def _get_data(request, env, roles, virt, group_by_host=False): """Returns processed repository data, filtering nodes based on given args """ data = {'filter_env': env, 'filter_roles': roles, 'filter_virt': virt} data['roles'] = get_roles() roles_groups = get_role_groups(data['roles']) data['roles_groups'] = roles_groups data['virt_roles'] = ['host', 'guest'] # Get environments before we filter nodes data['nodes'] = get_nodes() data['nodes_extended'] = get_nodes_extended(data['nodes']) data['environments'] = get_environments(data['nodes_extended']) roles_to_filter = '' if group_by_host else data['filter_roles'] if data['filter_env'] or roles_to_filter or data['filter_virt']: data['nodes_extended'] = filter_nodes(data['nodes_extended'], data['filter_env'], roles_to_filter, data['filter_virt']) if group_by_host: data['nodes_extended'] = group_nodes_by_host( data['nodes_extended'], roles=data['filter_roles']) inject_plugin_data(data['nodes_extended']) if not data['nodes_extended']: add_message(request, WARNING, "There are no nodes that fit the supplied criteria.") return data
def plugins(request, name, method, plugin_type='list'): """Plugin interface view which either response with the page created by the plugin method, or returns a 404 HTTP Error """ try: plugin = PLUGINS[name] except KeyError: raise Http404("Requested plugin '{0}' not found".format(name)) try: func = getattr(plugin, method) except AttributeError: raise Http404("Plugin '{0}' has no method '{1}'".format(name, method)) if not getattr(func, '__is_view__', False): raise Http404("Plugin method '{0}.{1}' ""is not defined " "as a view".format(name, method)) nodes = get_nodes() nodes = get_nodes_extended(nodes) if plugin_type in ('v', 'virt'): if func.__p_type__ != 'virt': raise Http404("Plugin '{0}.{1}' has wrong " "type".format(name, method)) nodes = group_nodes_by_host(nodes, roles=None) elif func.__p_type__ != 'list': raise Http404("Plugin '{0}.{1}' has wrong type".format(name, method)) inject_plugin_data(nodes) try: result = func(request, nodes) except TypeError: raise Http404("Failed running plugin '{0}.{1}'".format(name, method)) if not isinstance(result, HttpResponse): raise Http404("Plugin '{0}.{1}' returned unexpected result: " "{2}".format(name, method, result)) else: return result
def test_inject_plugin_data(self): """Should add link data when plugin is applied""" chef.plugins = plugins.import_plugins(['monitoring']) node = { 'fqdn': 'testnode', 'kitchen': {'data': {'links': [{"foo": "bar"}], 'other': {}}} } chef.inject_plugin_data([node]) self.assertTrue('other' in node['kitchen']['data']) self.assertEqual(len(node['kitchen']['data']['links']), 2)