summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-info
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbin/bcfg2-info')
-rwxr-xr-xsrc/sbin/bcfg2-info115
1 files changed, 62 insertions, 53 deletions
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index a6d236bc8..f78b3a7f4 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -5,7 +5,6 @@ __revision__ = '$Revision$'
from code import InteractiveConsole
import cmd
-import errno
import getopt
import logging
import lxml.etree
@@ -28,6 +27,42 @@ import Bcfg2.Server.Plugin
logger = logging.getLogger('bcfg2-info')
+USAGE = """Commands
+
+build <hostname> <filename> - Build config for hostname, writing to filename
+builddir <hostname> <dirname> - Build config for hostname, writing separate files to dirname
+buildall <directory> - Build configs for all clients in directory
+buildfile <filename> <hostname> - Build config file for hostname (not written to disk)
+bundles - Print out group/bundle information
+clients - Print out client/profile information
+config - Print out the configuration of the Bcfg2 server
+debug - Shell out to native python interpreter
+event_debug - Display filesystem events as they are processed
+generators - List current versions of generators
+groups - List groups
+help - Print this list of available commands
+mappings <type*> <name*> - Print generator mappings for optional type and name
+profile <command> <args> - Profile a single bcfg2-info command
+quit - Exit the bcfg2-info command line
+showentries <hostname> <type> - Show abstract configuration entries for a given host
+showclient <client1> <client2> - Show metadata for given hosts
+update - Process pending file events
+version - Print version of this tool"""
+
+BUILDDIR_USAGE = """Usage: builddir [-f] <hostname> <output dir>
+
+Generates a config for client <hostname> and writes the
+individual configuration files out separately in a tree
+under <output dir>. The <output dir> directory must be
+rooted under /tmp unless the -f argument is provided, in
+which case it can be located anywhere.
+
+NOTE: Currently only handles file entries and writes
+all content with the default owner and permissions. These
+could be much more permissive than would be created by the
+Bcfg2 client itself."""
+
+
class mockLog(object):
def error(self, *args, **kwargs):
pass
@@ -38,18 +73,22 @@ class mockLog(object):
def debug(self, *args, **kwargs):
pass
+
class dummyError(Exception):
"""This is just a dummy."""
pass
+
class FileNotBuilt(Exception):
"""Thrown when File entry contains no content."""
def __init__(self, value):
Exception.__init__(self)
self.value = value
+
def __str__(self):
return repr(self.value)
+
def printTabular(rows):
"""Print data in tabular format."""
cmax = tuple([max([len(str(row[index])) for row in rows]) + 1 \
@@ -61,11 +100,13 @@ def printTabular(rows):
for row in rows[1:]:
print(fstring % row)
+
def displayTrace(trace, num=80, sort=('time', 'calls')):
stats = pstats.Stats(trace)
stats.sort_stats('cumulative', 'calls', 'time')
stats.print_stats(200)
+
class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
"""Main class for bcfg2-info."""
def __init__(self, repo, plgs, passwd, encoding, event_debug):
@@ -106,7 +147,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
try:
opts, _ = getopt.getopt(args.split(), 'nf:')
except:
- print "Usage: debug [-n] [-f <command list>]"
+ print("Usage: debug [-n] [-f <command list>]")
return
self.cont = False
scriptmode = False
@@ -136,7 +177,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
Exit program.
Usage: [quit|exit]
"""
- for plugin in self.plugins.values():
+ for plugin in list(self.plugins.values()):
plugin.shutdown()
os._exit(0)
@@ -145,27 +186,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
def do_help(self, _):
"""Print out usage info."""
- print 'Commands:'
- print 'build <hostname> <filename> - Build config for hostname, writing to filename'
- print 'builddir <hostname> <dirname> - Build config for hostname, writing separate files to dirname'
- print 'buildall <directory> - Build configs for all clients in directory'
- print 'buildfile <filename> <hostname> - Build config file for hostname (not written to disk)'
- print 'bundles - Print out group/bundle information'
- print 'clients - Print out client/profile information'
- print 'config - Print out the configuration of the Bcfg2 server'
- print 'debug - Shell out to native python interpreter'
- print 'event_debug - Display filesystem events as they are processed'
- print 'generators - List current versions of generators'
- print 'groups - List groups'
- print 'help - Print this list of available commands'
- print 'mappings <type*> <name*> - Print generator mappings for optional type and name'
- print 'profile <command> <args> - Profile a single bcfg2-info command'
- print 'quit - Exit the bcfg2-info command line'
- print 'showentries <hostname> <type> - Show abstract configuration entries for a given host'
- print 'showclient <client1> <client2> - Show metadata for given hosts'
- print 'update - Process pending file events'
- print 'version - Print version of this tool'
-
+ print(USAGE)
def do_update(self, _):
"""Process pending filesystem events."""
@@ -198,18 +219,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
def help_builddir(self):
"""Display help for builddir command."""
- print('Usage: builddir [-f] <hostname> <output dir>')
- print('')
- print('Generates a config for client <hostname> and writes the')
- print('individual configuration files out separately in a tree')
- print('under <output dir>. The <output dir> directory must be')
- print('rooted under /tmp unless the -f argument is provided, in')
- print('which case it can be located anywhere.')
- print('')
- print('NOTE: Currently only handles file entries and writes')
- print('all content with the default owner and permissions. These')
- print('could be much more permissive than would be created by the')
- print('Bcfg2 client itself.')
+ print(BUILDDIR_USAGE)
def do_builddir(self, args):
"""Build client configuration as separate files within a dir."""
@@ -238,9 +248,9 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
p = Bcfg2.Client.Tools.POSIX.POSIX(log, setup, client_config)
states = dict()
p.Inventory(states)
- p.Install(states.keys(), states)
+ p.Install(list(states.keys()), states)
else:
- print('Error: Incorrect number of parameters.')
+ print("Error: Incorrect number of parameters.")
self.help_builddir()
def do_buildall(self, args):
@@ -262,7 +272,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
try:
metadata = self.build_metadata(client)
self.Bind(entry, metadata)
- print(lxml.etree.tostring(entry, encoding="UTF-8",
+ print(lxml.etree.tostring(entry, encoding="UTF-8",
xml_declaration=True))
except:
print("Failed to build entry %s for host %s" % (fname, client))
@@ -307,7 +317,6 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
]
printTabular(output)
-
def do_generators(self, _):
"""Print out generator info."""
for generator in self.generators:
@@ -371,22 +380,22 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
except:
print("Client %s not defined" % client)
continue
- print "Hostname:\t", client_meta.hostname
- print "Profile:\t", client_meta.profile
- print "Groups:\t\t", list(client_meta.groups)[0]
+ print("Hostname:\t", client_meta.hostname)
+ print("Profile:\t", client_meta.profile)
+ print("Groups:\t\t", list(client_meta.groups)[0])
for grp in list(client_meta.groups)[1:]:
- print '\t\t%s' % grp
+ print("\t\t%s" % grp)
if client_meta.bundles:
- print "Bundles:\t", list(client_meta.bundles)[0]
+ print("Bundles:\t", list(client_meta.bundles)[0])
for bnd in list(client_meta.bundles)[1:]:
- print '\t\t%s' % bnd
+ print("\t\t%s" % bnd)
if client_meta.connectors:
- print "Connector data"
- print "=" * 80
+ print("Connector data")
+ print("=" * 80)
for conn in client_meta.connectors:
if getattr(client_meta, conn):
- print "%s:\t" % (conn), getattr(client_meta, conn)
- print "=" * 80
+ print("%s:\t" % (conn), getattr(client_meta, conn))
+ print("=" * 80)
def do_mappings(self, args):
"""Print out mapping info."""
@@ -402,11 +411,11 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
interested = [(etype, [args.split()[1]])
for etype in etypes]
else:
- interested = [(etype, generator.Entries[etype])
- for etype in etypes
+ interested = [(etype, generator.Entries[etype])
+ for etype in etypes
if etype in generator.Entries]
for etype, names in interested:
- for name in [name for name in names if name in
+ for name in [name for name in names if name in
generator.Entries.get(etype, {})]:
data.append((generator.name, etype, name))
printTabular(data)