From aac0cd83571515ff5fb738abbd90340cc6d3c13f Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 8 Feb 2013 01:47:16 +0100 Subject: [PATCH] =?UTF-8?q?Trucs=20non=20commit=C3=A9s=20:=20bcfg2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bcfg2/backup.py | 57 +++++++++++++++++++++++++++++++++++++++++ bcfg2/bcfg2-graph.py | 51 ++++++++++++++++++++++++++++++++++++ bcfg2/clean_dotcompiled | 3 +++ 3 files changed, 111 insertions(+) create mode 100755 bcfg2/backup.py create mode 100755 bcfg2/bcfg2-graph.py create mode 100755 bcfg2/clean_dotcompiled diff --git a/bcfg2/backup.py b/bcfg2/backup.py new file mode 100755 index 00000000..b9686ed7 --- /dev/null +++ b/bcfg2/backup.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +import os, sys, time +import Bcfg2.Logger, Bcfg2.Server.Core, Bcfg2.Options +import Bcfg2.Server.Plugins.Metadata, Bcfg2.Server.Plugin + +class searchCore(Bcfg2.Server.Core.Core): + # On définit une classe parce qu'il faut mettre quelque chose au-dessus + # de la classe Core si on veut récupérer les informations ... + # C'est nul. + + def __init__(self, repo, plgs, struct, gens, passwd, svn, + encoding): + try: + Bcfg2.Server.Core.Core.__init__(self, repo, plgs, struct, gens, + passwd, svn, encoding) + except Bcfg2.Server.Core.CoreInitError, msg: + print "Core load failed because %s" % msg + raise SystemExit(1) + i = 0 + while self.fam.Service() or i < 5: + i += 1 + + def do_search(self, searchgroup): + """Search for clients belonging to a group""" + clients = [] + clist = self.metadata.clients.keys() + clist.sort() + for client in clist: + profile = self.metadata.clients[client] + gdata = [grp for grp in self.metadata.groups[profile][1]] + if searchgroup in gdata: + clients.append(client) + return clients + +if __name__ == '__main__': + # Bon ça ce sont les trucs recopiés de bcfg2-info + optinfo = { + 'configfile': Bcfg2.Options.CFILE, + 'help': Bcfg2.Options.HELP, + } + optinfo.update({'repo': Bcfg2.Options.SERVER_REPOSITORY, + 'svn': Bcfg2.Options.SERVER_SVN, + 'plugins': Bcfg2.Options.SERVER_PLUGINS, + 'structures': Bcfg2.Options.SERVER_STRUCTURES, + 'generators': Bcfg2.Options.SERVER_GENERATORS, + 'password': Bcfg2.Options.SERVER_PASSWORD, + 'event debug': Bcfg2.Options.DEBUG, + 'encoding': Bcfg2.Options.ENCODING}) + setup = Bcfg2.Options.OptionParser(optinfo) + setup.parse([]) + loop = searchCore(setup['repo'], setup['plugins'], setup['structures'], + setup['generators'], setup['password'], '', + setup['encoding']) + # On cherche les clients + clients = loop.do_search('backup-client') + # On génère un truc qui va bien pour ces clients + diff --git a/bcfg2/bcfg2-graph.py b/bcfg2/bcfg2-graph.py new file mode 100755 index 00000000..ce8d6fd8 --- /dev/null +++ b/bcfg2/bcfg2-graph.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from __future__ import print_function +import xml.dom.minidom + +tmp_file = '/tmp/graph.gv' + +out = file(tmp_file,'w') + +from sh import neato +from sh import date + +groups = xml.dom.minidom.parse(file('/var/lib/bcfg2/Metadata/groups.xml','r')).documentElement + +print("""digraph G { +edge [len=4.50, ratio=fill] +""", file=out) + +def childGroups(parent): + return [ x for x in parent.childNodes if \ + x.nodeType == x.ELEMENT_NODE and x.tagName == u'Group'] + +# Les clients +print(""" +subgraph cluster_1 { + node [style=filled]; +""", file=out) +for elem in childGroups(groups): + if elem.hasAttribute('profile'): + print('"%s";' % elem.getAttribute('name'), file=out) +print(""" + label = "process #2"; + color=blue + } +""", file=out) +# Le reste + +for elem in childGroups(groups): + print('"%s" -> {%s};' % \ + ( elem.getAttribute('name'), + " ".join( [ '"%s"' % x.getAttribute('name') + for x in childGroups(elem) ]), + ), file=out) + +print(""" +label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s"; +}""" % str(date())[0:-1], file=out) + +out.close() + +neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/bcfg2/groups.svg") diff --git a/bcfg2/clean_dotcompiled b/bcfg2/clean_dotcompiled new file mode 100755 index 00000000..e2b4fc09 --- /dev/null +++ b/bcfg2/clean_dotcompiled @@ -0,0 +1,3 @@ +#!/bin/bash + +find /var/lib/bcfg2 -name "*.COMPILED" -exec rm -f '{}' \;