def publish(self, domain='yourdomainhere'): c.title = "Nodetraq -- DNS - Publish" c.selected_page = "dns" c.subpage = "publish" c.domain = domain prod = NodetraqCotendo() prod.GrabDNS(domain, 1) staging = NodetraqCotendo() staging.GrabDNS(domain, 1) results = ch.get_view('dns', 'configs') for r in results.rows: if r.value['environment'] == 'staging': staging.ImportDNS(r.value["config"], r.value["token"]) break staging_config = staging.dns.config.splitlines(1) prod_config = prod.dns.config.splitlines(1) diff = ''.join(difflib.unified_diff( prod_config, staging_config, 'production', 'staging')) c.diff = diff return render('/dns/publish.mako')
def index(self, domain='yourdomainhere'): c.title = "Nodetraq -- DNS" c.selected_page = "dns" c.subpage = "list" c.domain = domain cotendo = NodetraqCotendo() cotendo.GrabDNS(domain, 1) ch.select("nodetraq") # Sync views ch.sync_view('nodetraq/model/views') # Update CouchDB to have a copy of the latest dns entries. results = ch.get_view('dns', 'configs') doc = None for r in results.rows: if r.value['environment'] == 'staging': doc = couchdb.Document(r.value) cotendo.ImportDNS(r.value["config"], r.value['token']) if doc: if doc["config"] != cotendo.dns.config: doc["config"] = cotendo.dns.config doc["token"] = cotendo.dns.token ch.save(doc) if not doc: doc = couchdb.Document({"doc_type": "dns", "domain": domain, "environment": "staging", "token": cotendo.dns.token, "config": cotendo.dns.config }) ch.save(doc) c.records = cotendo.dns._entries return render('dns/list.mako')
def index(self): c.title = 'Nodetraq -- Graphs' c.selected_page = 'graphs' c.subpage = 'index' c.graphs = Session.query(Graph).all() return render('/graphs/index.mako')
def edit(self, account=None): c.title = "Nodetraq -- Edit Users" c.selected_page = "users" c.subpage = "edit" dh = DirectoryHelper( directoryCN, directoryPassword, directoryDomain) try: c.user = dh.ldap.findUser(account, Attrs=[ 'cn', 'uid', 'mail', 'loginShell', 'nsAccountLock', 'uidNumber', 'title', 'manager', 'departmentNumber', 'roomNumber', 'deploycode', 'orgchartmanager', 'utilityaccount' ])[1] fix_keys = ['uidNumber', 'nsAccountLock', 'mail', 'loginShell'] for key in fix_keys: if not c.user.has_key(key): c.user[key] = [''] except: c.user = None groups = dh.getAllGroups() c.group_membership = dh.getUserGroups(account) c.group_membership.sort() c.available_groups = list(set(groups) - set(c.group_membership)) c.available_groups.sort() return render('/users/edit.mako')
def show(self, pool): c.title = 'Nodetraq - Loadbalancer - Show' c.selected_page = 'loadbalancer' c.subpage = 'show' lb = LoadBalancer(ip='your_lb_ip') c.members = self.get_members_status(Session, [pool])[0] return render('/loadbalancer/show.mako')
def edit_record(self, domain='yourdomainhere', type=None, host=''): c.title = "Nodetraq -- DNS - Edit Record" c.selected_page = "dns" c.subpage = "edit_record" c.domain = domain cotendo = NodetraqCotendo() cotendo.GrabDNS(domain, 1) # check if record exists, if it does, update it otherwise results = ch.get_view('dns', 'configs') doc = None for r in results.rows: if r.value['environment'] == 'staging': cotendo.ImportDNS(r.value["config"], r.value['token']) doc = couchdb.Document(r.value) break c.record = cotendo.dns.get_record(type, host) if not c.record: session['flash'] = "Not a valid record" session.save() return redirect(url(controller="dns", action="index", domain=domain)) return render('/dns/edit_record.mako')
def index(self): c.page = int(request.params['page'])\ if 'page' in request.params else 1 c.title = 'Nodetraq - Groups' c.selected_page = 'groups' c.subpage = 'list' c.heading = "Groups" c.filters = [ { 'name': 'group', 'label': 'Group', 'type': 'text' } ] query, c.search_fields = get_fields_and_query(Session, Group, request.params) c.request_url = request.environ.get('PATH_INFO') if request.environ.get('QUERY_STRING'): c.request_url += '?' + request.environ['QUERY_STRING'] c.group_count = query.count() c.link_append = '&' + urlencode(\ [p for p in request.params.items()\ if p[0] != 'page']) if c.link_append == '&': c.link_append = None if 'show_all' in request.params: c.total_pages = 1 c.current_page_count = 1 c.groups = query.order_by('name').all() else: c.total_pages = (c.group_count+25-1)/25 c.current_page_count = (c.page-1)*25 c.groups = query.order_by('name')\ [c.current_page_count: c.current_page_count+25] c.all_groups, c.tag_sizes = self.get_tag_info() return render('/groups/list.mako')
def index(self): c.title = 'Nodetraq - Dashboard' c.selected_page = 'dashboard' c.subpage = 'index' c.sync_issues = self.get_sync_issues()['issues'] return render('/dashboard/index.mako')
def edit_studio(self, id): c.studio = Session.query(Studio).filter(Studio.id == id).first() c.title = "Nodetraq -- Edit Studio" c.header = c.studio.name c.selected_page = "nodes" c.subpage = "edit_studio" return render('/nodes/studios/edit.mako')
def add(self): c.group = Session.query(Group).filter(Group.id == id).first() c.title = 'Nodetraq - Group - Add' c.selected_page = 'groups' c.subpage = 'add' return render('/groups/add.mako')
def get_new_record(self): json_data = json.loads(request.params.keys()[0]) c.record_type = json_data['record_type'] c.count = json_data['count'] if not c.count: c.count = 0 return render('/dns/new_record.mako')
def add_record(self, domain='yourdomainhere'): c.title = "Nodetraq -- DNS - Add Record" c.selected_page = "dns" c.subpage = "add_record" c.domain = domain return render('dns/add_record.mako')
def publish(self, domain='yourdomainhere'): c.title = "Nodetraq -- DNS - Publish" c.selected_page = "dns" c.subpage = "publish" c.domain = domain prod = NodetraqCotendo() prod.GrabDNS(domain, 1) staging = NodetraqCotendo() staging.GrabDNS(domain, 1) results = ch.get_view('dns', 'configs') for r in results.rows: if r.value['environment'] == 'staging': staging.ImportDNS(r.value["config"], r.value["token"]) break staging_config = staging.dns.config.splitlines(1) prod_config = prod.dns.config.splitlines(1) diff = ''.join( difflib.unified_diff(prod_config, staging_config, 'production', 'staging')) c.diff = diff return render('/dns/publish.mako')
def edit_record(self, domain='yourdomainhere', type=None, host=''): c.title = "Nodetraq -- DNS - Edit Record" c.selected_page = "dns" c.subpage = "edit_record" c.domain = domain cotendo = NodetraqCotendo() cotendo.GrabDNS(domain, 1) # check if record exists, if it does, update it otherwise results = ch.get_view('dns', 'configs') doc = None for r in results.rows: if r.value['environment'] == 'staging': cotendo.ImportDNS(r.value["config"], r.value['token']) doc = couchdb.Document(r.value) break c.record = cotendo.dns.get_record(type, host) if not c.record: session['flash'] = "Not a valid record" session.save() return redirect( url(controller="dns", action="index", domain=domain)) return render('/dns/edit_record.mako')
def index(self): c.title = 'Nodetraq - LoadBalancer' c.selected_page = 'loadbalancer' c.subpage = 'index' lb = LoadBalancer(ip='lb_iphere') pools = lb.get_pools() pools.sort() c.pool_count = len(pools) c.link_append = '&' + urlencode( [p for p in request.params.items()\ if p[0] != 'page']) if c.link_append == '&': c.link_append = None if 'show_all' in request.params: c.page = 1 c.total_pages = 1 c.current_page_count = 1 c.members = self.get_members_status(Session, pools) else: c.page = int(request.params['page'])\ if 'page' in request.params else 1 c.total_pages = (c.pool_count + 25 - 1) / 25 c.current_page_count = (c.page - 1) * 25 c.members = self.get_members_status( Session, pools[c.current_page_count:c.current_page_count + 25]) return render('/loadbalancer/index.mako')
def index(self): c.title = 'Nodetraq - Network' c.selected_page = 'network' c.subpage = 'index' c.network_devices = Session.query(NetworkDevice).all() return render('/network/index.mako')
def index(self): c.title = 'Nodetraq - LoadBalancer' c.selected_page = 'loadbalancer' c.subpage = 'index' lb = LoadBalancer(ip='lb_iphere') pools = lb.get_pools() pools.sort() c.pool_count = len(pools) c.link_append = '&' + urlencode( [p for p in request.params.items()\ if p[0] != 'page']) if c.link_append == '&': c.link_append = None if 'show_all' in request.params: c.page = 1 c.total_pages = 1 c.current_page_count = 1 c.members = self.get_members_status(Session, pools) else: c.page = int(request.params['page'])\ if 'page' in request.params else 1 c.total_pages = (c.pool_count+25-1)/25 c.current_page_count = (c.page-1)*25 c.members = self.get_members_status(Session, pools[c.current_page_count:c.current_page_count+25]) return render('/loadbalancer/index.mako')
def show_dbbackups(self): c.title = "Nodetraq -- Show Database Backups" c.selected_page = "nodes" c.subpage = "database" sort = None c.dbbackups = Session.query(NodeDatabaseBackup).all() if not 'sort' in request.params: sort = 'server' else: sort = request.params['sort'] if sort == 'server': c.dbbackups = sorted( c.dbbackups, key=lambda backup: backup.server.hostname) elif sort == 'storage': c.dbbackups = sorted( c.dbbackups, key=lambda backup: backup.storage.hostname) elif sort == 'directory': c.dbbackups = sorted( c.dbbackups, key=lambda backup: backup.directory) elif sort == 'enabled': c.dbbackups = sorted( c.dbbackups, key=lambda backup: backup.enabled) c.sort = sort return render('/nodes/show_dbbackups.mako')
def namelist(self, format='mako'): c.nodes = Session.query(Node.hostname).all() if format == 'json': response.content_type = 'application/json' elif format == 'xml': response.content_type = 'application/xml' return render('/nodes/namelist/list.' + format)
def rrd_file(self, id): response.content_type = 'text/plain' if id.isdigit(): graph_data = Session.query(Graph)\ .filter(Graph.id == int(id)).first() else: graph_data = Session.query(Graph)\ .filter(Graph.name == id).first() c.graph = graph_data.filename[1:] hostnames = [n.hostname for n in graph_data.get_hosts()] c.datasource = generate_rrd_sequence_map( hostnames, graph_data.get_rrds()) c.title = graph_data.name if len(c.datasource) == 2: c.colors = ['Lime', 'Red'] c.brmod = 2 else: c.colors = ['Lime', 'Teal', 'Maroon'] c.brmod = 3 return render('/graphs/graph.mako')
def index(self): c.page = int(request.params['page'])\ if 'page' in request.params else 1 c.title = 'Nodetraq - Groups' c.selected_page = 'groups' c.subpage = 'list' c.heading = "Groups" c.filters = [{'name': 'group', 'label': 'Group', 'type': 'text'}] query, c.search_fields = get_fields_and_query(Session, Group, request.params) c.request_url = request.environ.get('PATH_INFO') if request.environ.get('QUERY_STRING'): c.request_url += '?' + request.environ['QUERY_STRING'] c.group_count = query.count() c.link_append = '&' + urlencode(\ [p for p in request.params.items()\ if p[0] != 'page']) if c.link_append == '&': c.link_append = None if 'show_all' in request.params: c.total_pages = 1 c.current_page_count = 1 c.groups = query.order_by('name').all() else: c.total_pages = (c.group_count + 25 - 1) / 25 c.current_page_count = (c.page - 1) * 25 c.groups = query.order_by('name')\ [c.current_page_count: c.current_page_count+25] c.all_groups, c.tag_sizes = self.get_tag_info() return render('/groups/list.mako')
def search(self): c.title = "Nodetraq -- Search" c.selected_page = "users" c.subpage = "search" c.search_type = 'users' return render('/users/search.mako')
def show_game(self, id): c.game = Session.query(Game).filter(Game.id == id).first() c.title = "Nodetraq -- Game: %s" % c.game.name c.header = c.game.name c.selected_page = "nodes" c.subpage = "show_game" c.groups = [ {'name': 'PE-1950', 'nodes': []}, {'name': 'PE-2950', 'nodes': []}, {'name': 'PE-R410', 'nodes': []}, {'name': 'PE-R610', 'nodes': []}, {'name': 'PE-R710', 'nodes': []}, {'name': 'vm', 'nodes': []}, {'name': 'unknown', 'nodes': []} ] group_list = lambda groups: [g.name for g in groups] for node in c.game.nodes: grouped = False for group in c.groups: if group['name'] in group_list(node.groups): group['nodes'].append(node) grouped = True if not grouped: c.groups[len(c.groups)-1]['nodes'].append(node) return render('/nodes/games/show.mako')
def show_dbbackups(self): c.title = "Nodetraq -- Show Database Backups" c.selected_page = "nodes" c.subpage = "database" sort = None c.dbbackups = Session.query(NodeDatabaseBackup).all() if not 'sort' in request.params: sort = 'server' else: sort = request.params['sort'] if sort == 'server': c.dbbackups = sorted(c.dbbackups, key=lambda backup: backup.server.hostname) elif sort == 'storage': c.dbbackups = sorted(c.dbbackups, key=lambda backup: backup.storage.hostname) elif sort == 'directory': c.dbbackups = sorted(c.dbbackups, key=lambda backup: backup.directory) elif sort == 'enabled': c.dbbackups = sorted(c.dbbackups, key=lambda backup: backup.enabled) c.sort = sort return render('/nodes/show_dbbackups.mako')
def show(self, id, vhostid=None): c.title = 'Nodetraq - Vhost - Edit' c.selected_page = 'nodes' c.subpage = 'vhost' c.header = 'Show Vhost' c.vhostid = vhostid c.node_id = id return render('/nodes/vhosts/show.mako')
def new(self, id): c.title = 'Nodetraq - vhosts' c.selected_page = 'nodes' c.subpage = 'vhosts' c.header = 'Nodes:vhosts' c.node_id = id return render('/nodes/vhosts/new.mako')
def show(self, id): c.title = 'Nodetraq - Network Devices' c.selected_page = 'network' c.subpage = 'show' c.network_device = Session.query(NetworkDevice).filter( id == NetworkDevice.id).first() return render('/network/show.mako')
def get_new_record(self): json_data = json.loads( request.params.keys()[0]) c.record_type = json_data['record_type'] c.count = json_data['count'] if not c.count: c.count = 0 return render('/dns/new_record.mako')
def info(self, id): c.title = "Nodetraq - Activity - Info" c.selected_page = "activity" c.subpage = "info" c.activity = Session.query(Activity).filter(Activity.id == id).first() c.Session = Session return render("/activity/info.mako")
def info(self, id): c.title = 'Nodetraq - Activity - Info' c.selected_page = 'activity' c.subpage = 'info' c.activity = Session.query(Activity)\ .filter(Activity.id == id).first() c.Session = Session return render('/activity/info.mako')
def atom(self): yesterday = now()- datetime.timedelta(hours=18) c.activity = Session.query(Activity)\ .filter(Activity.created_at < now())\ .filter(Activity.created_at > yesterday)\ .order_by(desc(Activity.created_at))\ .filter(Activity.parent == None)\ .all() return render('/activity/atom.mako')
def edit_comment(self, id, commentid): c.title = 'Nodetraq : Comments' c.selected_page = 'nodes' c.subpage = 'editcomment' c.comment = Session.query(NodeComment)\ .filter(NodeComment.id == commentid).first() c.node_id = id return render('/nodes/comments/edit.mako')
def edit_bulk_dbbackups(self): c.title = "Nodetraq -- Edit Database Backups" c.selected_page = "nodes" c.subpage = "database" c.dbbackups = Session.query(NodeDatabaseBackup).all() c.dbbackups = sorted(c.dbbackups, key=lambda backup: backup.server.hostname) return render('/nodes/edit_bulk_dbbackups.mako')
def create_game(self): c.title = "Nodetraq -- Create Game" c.header = "Create Game" c.selected_page = "nodes" c.subpage = "create_game" c.studios = [('', '')] for studio in Session.query(Studio).all(): c.studios.append((studio.id, studio.name)) return render('/nodes/games/create.mako')
def index(self, id): c.title = 'Nodetraq - vhosts' c.selected_page = 'nodes' c.subpage = 'vhosts' c.header = 'Nodes : vhosts' c.node = Session.query(Node).filter(Node.id == id).first() c.node_id = c.node.id return render('/nodes/vhosts/index.mako')
def create_game(self): c.title = "Nodetraq -- Create Game" c.header = "Create Game" c.selected_page = "nodes" c.subpage = "create_game" c.studios = [ ('', '') ] for studio in Session.query(Studio).all(): c.studios.append((studio.id, studio.name)) return render('/nodes/games/create.mako')
def edit_bulk_dbbackups(self): c.title = "Nodetraq -- Edit Database Backups" c.selected_page = "nodes" c.subpage = "database" c.dbbackups = Session.query(NodeDatabaseBackup).all() c.dbbackups = sorted( c.dbbackups, key=lambda backup: backup.server.hostname) return render('/nodes/edit_bulk_dbbackups.mako')
def show(self, id, format='html'): id = unicode(id) if id.isdigit(): c.group = Session.query(Group).filter(Group.id == int(id)).first() else: c.group = Session.query(Group).filter(Group.name == id).first() c.group_list = [g[0] for g in Session.query(Group.name)] c.title = 'Nodetraq - Group - %s' % c.group.name c.selected_page = 'groups' c.subpage = 'show' c.header = 'Groups : %s' % c.group.name c.page = int(request.params['page'])\ if 'page' in request.params else 1 c.current_page_count = (c.page - 1) * 25 c.node_count = len(c.group.nodes) c.filters = [{'name': 'group', 'label': 'Group', 'type': 'text'}] c.link_append = None is_sorted = False if 'sort' in request.params: sortkey, sortorder = request.params['sort'].split(':') is_sorted = True c.sort_order = sortorder else: c.sort_order = None if is_sorted: if sortorder == 'asc': c.nodes = c.group.nodes\ [c.current_page_count:c.current_page_count+25] c.nodes = sorted(c.nodes, key=attrgetter(sortkey), reverse=False) else: c.nodes = c.group.nodes\ [c.current_page_count:c.current_page_count+25] c.nodes = sorted(c.nodes, key=attrgetter(sortkey), reverse=True) else: c.nodes = c.group.nodes[c.current_page_count:c.current_page_count + 25] c.all_groups, c.tag_sizes = self.get_tag_info() c.total_pages = (c.node_count + 25 - 1) / 25 c.request_url = request.environ.get('PATH_INFO') if request.environ.get('QUERY_STRING'): c.request_url += '?' + request.environ['QUERY_STRING'] if format == 'html': return render('/nodes/list.mako') elif format == 'json': return c.group.__json__() elif format == 'xml': return c.group.__xml__()
def edit(self, id, vhostid=None): c.title = 'Nodetraq - Vhost - Edit' c.selected_page = 'nodes' c.subpage = 'vhost' c.header = 'Edit Vhost' c.vhostid = vhostid c.node_id = id c.vhost = Session.query(NodeVhost)\ .filter(NodeVhost.id == vhostid).first() return render('/nodes/vhosts/edit.mako')
def groups(self): c.title = "Nodetraq -- Ldap Search" c.selected_page = "users" c.subpage = "list" dh = DirectoryHelper( directoryCN, directoryPassword, directoryDomain) data = dh.ldap.search_groups() data = [d for d in data if d[0]] c.users = data sort_type = 'cn' if request.params.has_key('sort'): sort_type = request.params['sort'] sort_order = 'asc' if request.params.has_key('order'): sort_order = request.params['order'] c.sort_type = sort_type c.sort_order = sort_order if sort_order == 'asc': sort_order = False else: sort_order = True c.search_type = None if request.params.has_key('search_type'): c.search_type = request.params['search_type'] dh = DirectoryHelper( directoryCN, directoryPassword, directoryDomain) if 'search_field' in request.params: if request.params['search_field']: fltr = \ '(&(objectClass=groupofuniquenames)(cn=*%s*))' % \ request.params['search_field'] else: fltr = '(&(objectClass=groupofuniquenames))' data = dh.ldap.search_groups( Filter=fltr, Attrs=['cn', 'description']) else: data = dh.ldap.search_groups(Attrs=['cn', 'description']) for item in data: if not item[1].has_key('description'): item[1]['description'] = [''] c.groups = data c.groups = sorted(c.groups, key=lambda group: group[1][sort_type], reverse=sort_order) return render('/users/groups.mako')
def edit(self, id): id = unicode(id) if id.isdigit(): c.group = Session.query(Group).filter(Group.id == id).first() else: c.group = Session.query(Group).filter(Group.name == id).first() c.title = 'Nodetraq - Edit group %s' % c.group.name c.selected_page = 'groups' c.subpage = 'edit' return render('/groups/edit.mako')
def atom(self): yesterday = now() - datetime.timedelta(hours=18) c.activity = ( Session.query(Activity) .filter(Activity.created_at < now()) .filter(Activity.created_at > yesterday) .order_by(desc(Activity.created_at)) .filter(Activity.parent == None) .all() ) return render("/activity/atom.mako")
def new(self, id): c.title = 'Nodetraq - dbbackups' c.selected_page = 'nodes' c.subpage = 'dbbackups' c.header = 'Nodes : Db backups' c.node_id = id c.backup_type_list = [(t.id, t.name) for t in Session.query(BackupType).all()] return render('/nodes/dbbackups/new.mako')
def show_groups(groups, is_nodehash=False): response.content_type = "text/plain" c.groups = groups c.nagios = None if 'nagios' in request.params: if request.params['nagios']: c.nagios = request.params['nagios'] for group in c.groups: c.groups[group].sort(key=lambda node: node.hostname) return render('/hosts/dumplist.mako')