def index(request, cluster_name=None): # for cluster, value in CONF.cluster.database_map. database_map = CONF.cluster.database_map agent_clusters = database_map.keys() tasks = [] if len(agent_clusters) == 0: pass else: if cluster_name is None: cluster_name = agent_clusters[0] cluster_dburl = database_map.get(cluster_name) cluster_dbapi = dbapi.DBAPI(cluster_dburl) tasks = cluster_dbapi.get_all_tasks() agent_clusters = json.dumps(agent_clusters) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) json_tasks = [] for task in tasks: data = { 'owner': task.owner, 'method': task.method, 'status': task.status, 'target': task.target, 'json_arg': task.json_arg, 'msg': task.msg, 'updated_at': str(task.updated_at), 'created_at': str(task.created_at), } json_tasks.append(data) if request.GET.get('query') == 'get_tasks': data = { 'tasks': json_tasks, } return HttpResponse(json.dumps(data), content_type="application/json") tasks = json.dumps(json_tasks) context = { 'title': 'Agent: {0}'.format(cluster_name), 'cluster': cluster_name, 'tasks': tasks, 'agent_clusters': agent_clusters, 'comments': comments, } if request.META.get('HTTP_X_PJAX'): return render(request, 'task/content.html', context) return render(request, 'task/index.html', context)
def index(request, cluster_name=None): pdns = pdnsapi.PdnsAPI() domains = pdns.get_domains() if len(domains) == 0: pass else: if cluster_name is None: domain = domains[0] cluster_name = domains[0].name else: for d in domains: if d.name == cluster_name: domain = d break else: domain = domains[0] cluster_name = domains[0].name records = pdns.get_records(domain_id=domain.id) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) json_domains = [] json_records = [] for domain in domains: json_domains.append(domain.name) for record in records: data = { 'name': record.name, 'type': record.type, 'content': record.content, 'ttl': record.ttl, } json_records.append(data) if request.GET.get('query') == 'get_records': data = { 'records': json_records, } return HttpResponse(json.dumps(data), content_type="application/json") context = { 'title': 'Domain: {0}'.format(cluster_name), 'cluster': cluster_name, 'records': json.dumps(json_records), 'domains': json.dumps(json_domains), 'comments': comments, } if request.META.get('HTTP_X_PJAX'): return render(request, 'dns/content.html', context) return render(request, 'dns/index.html', context)
def index(request, cluster_name=None): # for cluster, value in CONF.cluster.database_map. database_map = CONF.cluster.database_map agent_clusters = database_map.keys() if len(agent_clusters) == 0: pass else: if cluster_name is None: cluster_name = agent_clusters[0] cluster_dburl = database_map.get(cluster_name) cluster_dbapi = dbapi.DBAPI(cluster_dburl) events = cluster_dbapi.get_events() node_cluster = {} fabscript_map = {} node_map = {} util.update_fabscript_map(fabscript_map) node_cluster = { '__status': { 'fabscript_map': fabscript_map, 'node_map': node_map, }, 'datamap': {}, } agent_clusters = json.dumps(agent_clusters) node_cluster = json.dumps(node_cluster) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) context = { 'title': 'Event: {0}'.format(cluster_name), 'cluster': cluster_name, 'events': events, 'node_cluster': node_cluster, 'agent_clusters': agent_clusters, 'comments': comments, } if request.META.get('HTTP_X_PJAX'): return render(request, 'event/content.html', context) return render(request, 'event/index.html', context)
def index(request, cluster_name='all'): cluster = get_cluster(cluster_name) comments = get_comments(cluster) try: user_cluster = UserCluster.objects.get(user=request.user, cluster=cluster) user_cluster.unread_comments_length = 0 user_cluster.save() except ObjectDoesNotExist: UserCluster.objects.create(user=request.user, cluster=cluster, unread_comments_length=0) context = { 'title': 'Chat: ' + cluster_name, 'comments': comments, 'cluster': cluster_name, } if request.META.get('HTTP_X_PJAX'): return render(request, 'chat/content.html', context) return render(request, 'chat/index.html', context)
def index(request, cluster_name=None): # for cluster, value in CONF.cluster.database_map. database_map = CONF.cluster.database_map agent_clusters = database_map.keys() tasks = [] if len(agent_clusters) == 0: pass else: if cluster_name is None: cluster_name = agent_clusters[0] cluster_dburl = database_map.get(cluster_name) cluster_dbapi = dbapi.DBAPI(cluster_dburl) tasks = cluster_dbapi.get_tasks() agent_clusters = json.dumps(agent_clusters) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) context = { 'title': 'Agent: {0}'.format(cluster_name), 'cluster': cluster_name, 'tasks': tasks, 'agent_clusters': agent_clusters, 'comments': comments, } if request.META.get('HTTP_X_PJAX'): return render(request, 'task/content.html', context) return render(request, 'task/index.html', context)
def index(request, cluster=None): node_clusters = [] for root, dirs, files in os.walk(CONF._node_dir): cluster_name = root.split(CONF._node_dir) cluster_yaml = os.path.join(root, '__cluster.yml') if os.path.exists(cluster_yaml): cluster_name = cluster_name[1][1:] node_clusters.append(cluster_name) node_clusters.sort() node_clusters.insert(0, 'recent') node_cluster = { '__status': { 'fabscript_map': {} } } datamap = {} readme_html = '' with open(CONF._node_meta_pickle) as f: node_meta = pickle.load(f) recent_clusters = node_meta['recent_clusters'] for index, cl in enumerate(recent_clusters): cl = cl.replace('/', '__') recent_node_cluster = 'recent/{0}__{1}'.format(index, cl) node_clusters.append(recent_node_cluster) if not cluster: cluster = 'recent/0' splited_cluster = cluster.split('/') if splited_cluster[0] == 'recent': if len(splited_cluster) == 1: index = 0 else: index = int(splited_cluster[1]) if len(recent_clusters) > 0: cluster = recent_clusters[index] else: context = { 'cluster': None, 'title': 'Node List: No Data', } return render(request, 'node/index.html', context) cluster_dir = os.path.join(CONF._node_dir, cluster) cluster_yaml = os.path.join(cluster_dir, '__cluster.yml') cluster_pickle = os.path.join(cluster_dir, '__cluster.pickle') datamap_dir = os.path.join(cluster_dir, 'datamap') if os.path.exists(cluster_pickle): with open(cluster_pickle) as f: node_cluster = pickle.load(f) elif os.path.exists(cluster_yaml): with open(cluster_yaml) as f: node_cluster = yaml.load(f) with open(cluster_pickle, 'w') as f: pickle.dump(node_cluster, f) if os.path.exists(datamap_dir): for root, dirs, files in os.walk(datamap_dir): for file in files: file = os.path.join(root, file) with open(file, 'r') as f: data = yaml.load(f) datamap[data['name']] = data readme = os.path.join(cluster_dir, 'README.md') if os.path.exists(readme): with open(readme) as f: readme_html = f.read() node_cluster['datamap'] = datamap fabscript_map = node_cluster['__status']['fabscript_map'] util.update_fabscript_map(fabscript_map) node_clusters = json.dumps(node_clusters) node_cluster = json.dumps(node_cluster) context = { 'cluster': cluster, 'title': 'Node: {0}'.format(cluster), 'node_clusters': node_clusters, 'node_cluster': node_cluster, 'datamap': datamap, 'readme_html': readme_html, 'comments': get_comments(get_cluster(cluster)), } if request.META.get('HTTP_X_PJAX'): return render(request, 'node/content.html', context) return render(request, 'node/index.html', context)
def index(request, cluster_name=None): # for cluster, value in CONF.cluster.database_map. database_map = CONF.cluster.database_map agent_clusters = database_map.keys() agents = [] if len(agent_clusters) == 0: pass else: if cluster_name is None: cluster_name = agent_clusters[0] cluster_dburl = database_map.get(cluster_name) cluster_dbapi = dbapi.DBAPI(cluster_dburl) agents = cluster_dbapi.get_agents() node_cluster = {} central_agents = [] fabscript_map = {} node_map = {} for agent in agents: agent_fabscript_map = {} if agent.agent_type == "central": central_agents.append(agent) elif agent.agent_type == "agent": tmp_fabscript_map = json.loads(agent.fabscript_map) for cluster in tmp_fabscript_map.values(): for fabscript_name, result in cluster["fabscript_map"].items(): agent_fabscript_map[fabscript_name] = result fabscript = fabscript_map.get(fabscript_name, {"status": 0, "task_status": 0}) fabscript["status"] += result["status"] fabscript["task_status"] += result["task_status"] fabscript_map[fabscript_name] = fabscript node_map[agent.host] = { "status": agent.status, "check_timestamp": str(agent.check_timestamp), "setup_timestamp": str(agent.setup_timestamp), "fabscript_map": agent_fabscript_map, } util.update_fabscript_map(fabscript_map) node_cluster = {"__status": {"fabscript_map": fabscript_map, "node_map": node_map}, "datamap": {}} agent_clusters = json.dumps(agent_clusters) node_cluster = json.dumps(node_cluster) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) context = { "title": "Agent: {0}".format(cluster_name), "cluster": cluster_name, "agents": agents, "central_agents": central_agents, "node_cluster": node_cluster, "agent_clusters": agent_clusters, "comments": comments, } if request.META.get("HTTP_X_PJAX"): return render(request, "agent/content.html", context) return render(request, "agent/index.html", context)
def index(request, cluster_name=None): # for cluster, value in CONF.cluster.database_map. database_map = CONF.cluster.database_map agent_clusters = database_map.keys() agents = [] if len(agent_clusters) == 0: pass else: if cluster_name is None: cluster_name = agent_clusters[0] cluster_dburl = database_map.get(cluster_name) cluster_dbapi = dbapi.DBAPI(cluster_dburl) agents = cluster_dbapi.get_agents() node_cluster = {} central_agents = [] fabscript_map = {} node_map = {} for agent in agents: agent_fabscript_map = {} if agent.agent_type == 'central': central_agents.append(agent) elif agent.agent_type == 'agent': tmp_fabscript_map = json.loads(agent.fabscript_map) for cluster in tmp_fabscript_map.values(): for fabscript_name, result in cluster['fabscript_map'].items(): agent_fabscript_map[fabscript_name] = result fabscript = fabscript_map.get(fabscript_name, { 'status': 0, 'task_status': 0, }) fabscript['status'] += result['status'] fabscript['task_status'] += result['task_status'] fabscript_map[fabscript_name] = fabscript node_map[agent.host] = { 'status': agent.status, 'check_timestamp': str(agent.check_timestamp), 'setup_timestamp': str(agent.setup_timestamp), 'fabscript_map': agent_fabscript_map, } util.update_fabscript_map(fabscript_map) node_cluster = { '__status': { 'fabscript_map': fabscript_map, 'node_map': node_map, }, 'datamap': {}, } agent_clusters = json.dumps(agent_clusters) node_cluster = json.dumps(node_cluster) if cluster_name is None: comments = [] else: comments = get_comments(get_cluster(cluster_name)) context = { 'title': 'Agent: {0}'.format(cluster_name), 'cluster': cluster_name, 'agents': agents, 'central_agents': central_agents, 'node_cluster': node_cluster, 'agent_clusters': agent_clusters, 'comments': comments, } if request.META.get('HTTP_X_PJAX'): return render(request, 'agent/content.html', context) return render(request, 'agent/index.html', context)
def index(request, cluster=None): node_clusters = [] for root, dirs, files in os.walk(CONF._node_dir): cluster_name = root.split(CONF._node_dir) cluster_yaml = os.path.join(root, '__cluster.yml') if os.path.exists(cluster_yaml): cluster_name = cluster_name[1][1:] node_clusters.append(cluster_name) node_clusters.sort() node_clusters.insert(0, 'recent') node_cluster = {'__status': {'fabscript_map': {}}} datamap = {} readme_html = '' with open(CONF._node_meta_pickle) as f: node_meta = pickle.load(f) recent_clusters = node_meta['recent_clusters'] for index, cl in enumerate(recent_clusters): cl = cl.replace('/', '__') recent_node_cluster = 'recent/{0}__{1}'.format(index, cl) node_clusters.append(recent_node_cluster) if not cluster: cluster = 'recent/0' splited_cluster = cluster.split('/') if splited_cluster[0] == 'recent': if len(splited_cluster) == 1: index = 0 else: index = int(splited_cluster[1]) if len(recent_clusters) > 0: cluster = recent_clusters[index] else: context = { 'cluster': None, 'title': 'Node List: No Data', } return render(request, 'node/index.html', context) cluster_dir = os.path.join(CONF._node_dir, cluster) cluster_yaml = os.path.join(cluster_dir, '__cluster.yml') cluster_pickle = os.path.join(cluster_dir, '__cluster.pickle') datamap_dir = os.path.join(cluster_dir, 'datamap') if os.path.exists(cluster_pickle): with open(cluster_pickle) as f: node_cluster = pickle.load(f) elif os.path.exists(cluster_yaml): with open(cluster_yaml) as f: node_cluster = yaml.load(f) with open(cluster_pickle, 'w') as f: pickle.dump(node_cluster, f) if os.path.exists(datamap_dir): for root, dirs, files in os.walk(datamap_dir): for file in files: file = os.path.join(root, file) with open(file, 'r') as f: data = yaml.load(f) datamap[data['name']] = data readme = os.path.join(cluster_dir, 'README.md') if os.path.exists(readme): with open(readme) as f: readme_html = f.read() node_cluster['datamap'] = datamap fabscript_map = node_cluster['__status']['fabscript_map'] util.update_fabscript_map(fabscript_map) node_clusters = json.dumps(node_clusters) node_cluster = json.dumps(node_cluster) context = { 'cluster': cluster, 'title': 'Node: {0}'.format(cluster), 'node_clusters': node_clusters, 'node_cluster': node_cluster, 'datamap': datamap, 'readme_html': readme_html, 'comments': get_comments(get_cluster(cluster)), } if request.META.get('HTTP_X_PJAX'): return render(request, 'node/content.html', context) return render(request, 'node/index.html', context)