Commit aac0cd83 authored by Vincent Le gallic's avatar Vincent Le gallic

Trucs non commités : bcfg2

parent b29face3
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,
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()
for client in clist:
profile = self.metadata.clients[client]
gdata = [grp for grp in self.metadata.groups[profile][1]]
if searchgroup in gdata:
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)
loop = searchCore(setup['repo'], setup['plugins'], setup['structures'],
setup['generators'], setup['password'], '',
# On cherche les clients
clients = loop.do_search('backup-client')
# On génère un truc qui va bien pour ces clients
#!/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
subgraph cluster_1 {
node [style=filled];
""", file=out)
for elem in childGroups(groups):
if elem.hasAttribute('profile'):
print('"%s";' % elem.getAttribute('name'), file=out)
label = "process #2";
""", 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)
label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s";
}""" % str(date())[0:-1], file=out)
neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/bcfg2/groups.svg")
find /var/lib/bcfg2 -name "*.COMPILED" -exec rm -f '{}' \;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment