summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Admin/Client.py9
-rw-r--r--src/lib/Server/Admin/Compare.py4
-rw-r--r--src/lib/Server/Admin/Init.py6
-rw-r--r--src/lib/Server/Admin/Pull.py4
-rw-r--r--src/lib/Server/Admin/Tidy.py9
-rw-r--r--src/lib/Server/Admin/Viz.py6
-rw-r--r--src/lib/Server/Admin/__init__.py25
-rwxr-xr-xsrc/sbin/bcfg2-admin7
8 files changed, 31 insertions, 39 deletions
diff --git a/src/lib/Server/Admin/Client.py b/src/lib/Server/Admin/Client.py
index 677e38c2c..d08ff1283 100644
--- a/src/lib/Server/Admin/Client.py
+++ b/src/lib/Server/Admin/Client.py
@@ -5,15 +5,14 @@ import Bcfg2.Server.Admin
class Client(Bcfg2.Server.Admin.Mode):
__shorthelp__ = 'bcfg2-admin client add <client> attr1=val1 attr2=val2\nbcfg2-admin client del <client>'
__longhelp__ = __shorthelp__ + '\n\tCreate or delete client entries'
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
- self.tree = lxml.etree.parse(self.get_repo_path() + \
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
+ self.tree = lxml.etree.parse(self.repo_path + \
'/Metadata/clients.xml')
self.root = self.tree.getroot()
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
- repopath = self.get_repo_path()
if args[0] == 'add':
attr_d = {}
for i in args[1:]:
@@ -29,7 +28,7 @@ class Client(Bcfg2.Server.Admin.Mode):
else:
print "No command specified"
raise SystemExit(1)
- self.tree.write(repopath + '/Metadata/clients.xml')
+ self.tree.write(self.repopath + '/Metadata/clients.xml')
def AddClient(self, client, attrs):
'''add a new client'''
diff --git a/src/lib/Server/Admin/Compare.py b/src/lib/Server/Admin/Compare.py
index 962e54606..8d4dda352 100644
--- a/src/lib/Server/Admin/Compare.py
+++ b/src/lib/Server/Admin/Compare.py
@@ -6,8 +6,8 @@ class Compare(Bcfg2.Server.Admin.Mode):
__shorthelp__ = "bcfg2-admin compare <file1> <file2>\nbcfg2-admin compare -r <dir1> <dir2>"
__longhelp__ = __shorthelp__ + '''\n\tCompare mode determines differences between directories of client specification instances'''
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.important = {'Package':['name', 'version'],
'Service':['name', 'status'],
'Directory':['name', 'owner', 'group', 'perms'],
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index 01bede88e..5131cfb7a 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -1,6 +1,8 @@
import os, socket
import Bcfg2.Server.Admin
+from Bcfg2.Settings import settings
+
config = '''
[server]
repository = %s
@@ -91,9 +93,9 @@ class Init(Bcfg2.Server.Admin.Mode):
def initializeRepo(self, repo, server_uri, password, os_selection):
'''Setup a new repo'''
- keypath = os.path.dirname(os.path.abspath(self.configfile))
+ keypath = os.path.dirname(os.path.abspath(settings.CONFIG_FILE))
confdata = config % ( repo, password, keypath, server_uri )
- open(self.configfile,"w").write(confdata)
+ open(settings.CONFIG_FILE,"w").write(confdata)
# FIXME automate ssl key generation
os.popen('openssl req -x509 -nodes -days 1000 -newkey rsa:1024 -out %s/bcfg2.key -keyout %s/bcfg2.key' % (keypath, keypath))
try:
diff --git a/src/lib/Server/Admin/Pull.py b/src/lib/Server/Admin/Pull.py
index ab334dbf9..1071b5100 100644
--- a/src/lib/Server/Admin/Pull.py
+++ b/src/lib/Server/Admin/Pull.py
@@ -6,8 +6,8 @@ class Pull(Bcfg2.Server.Admin.Mode):
'''Pull mode retrieves entries from clients and integrates the information into the repository'''
__shorthelp__ = 'bcfg2-admin pull <client> <entry type> <entry name>'
__longhelp__ = __shorthelp__ + '\n\tIntegrate configuration information from clients into the server repository'
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
diff --git a/src/lib/Server/Admin/Tidy.py b/src/lib/Server/Admin/Tidy.py
index 80307df80..3cbe778b8 100644
--- a/src/lib/Server/Admin/Tidy.py
+++ b/src/lib/Server/Admin/Tidy.py
@@ -25,13 +25,12 @@ class Tidy(Bcfg2.Server.Admin.Mode):
def buildTidyList(self):
'''Clean up unused or unusable files from the repository'''
hostmatcher = re.compile('.*\.H_(\S+)$')
- repo = self.get_repo_path()
to_remove = []
good = []
bad = []
# clean up unresolvable hosts in SSHbase
- for name in os.listdir("%s/SSHbase" % (repo)):
+ for name in os.listdir("%s/SSHbase" % (self.repo_path)):
if hostmatcher.match(name):
hostname = hostmatcher.match(name).group(1)
if hostname in good + bad:
@@ -41,12 +40,12 @@ class Tidy(Bcfg2.Server.Admin.Mode):
good.append(hostname)
except:
bad.append(hostname)
- for name in os.listdir("%s/SSHbase" % (repo)):
+ for name in os.listdir("%s/SSHbase" % (self.repo_path)):
if not hostmatcher.match(name):
- to_remove.append("%s/SSHbase/%s" % (repo, name))
+ to_remove.append("%s/SSHbase/%s" % (self.repo_path, name))
else:
if hostmatcher.match(name).group(1) in bad:
- to_remove.append("%s/SSHbase/%s" % (repo, name))
+ to_remove.append("%s/SSHbase/%s" % (self.repo_path, name))
# clean up file~
# clean up files without parsable names in Cfg
return to_remove
diff --git a/src/lib/Server/Admin/Viz.py b/src/lib/Server/Admin/Viz.py
index bc2d8665c..3ebe25f92 100644
--- a/src/lib/Server/Admin/Viz.py
+++ b/src/lib/Server/Admin/Viz.py
@@ -5,8 +5,8 @@ import Bcfg2.Server.Admin
class Viz(Bcfg2.Server.Admin.Mode):
__shorthelp__ = '''bcfg2-admin viz [--includehosts] [--includebundles] [--includekey] [-o output.png] [--raw]'''
__longhelp__ = __shorthelp__ + '\n\tProduce graphviz diagrams of metadata structures'
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.colors = ['steelblue1', 'chartreuse', 'gold', 'magenta',
'indianred1', 'limegreen', 'orange1', 'lightblue2',
'green1', 'blue1', 'yellow1', 'darkturquoise', 'gray66']
@@ -38,7 +38,7 @@ class Viz(Bcfg2.Server.Admin.Mode):
kset = True
elif opt in ("-o", "--outfile"):
outputfile = arg
- repopath = self.get_repo_path()
+ repopath = self.repo_path
data = self.Visualize(repopath, rset, hset, bset, kset)
if outputfile:
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index 57b9d2a86..dcab5876f 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -4,40 +4,27 @@ __all__ = ['Mode', 'Client', 'Compare', 'Fingerprint', 'Init', 'Minestruct',
'Pull', 'Tidy', 'Viz']
import ConfigParser, lxml.etree, logging
+from Bcfg2.Settings import settings
class Mode(object):
'''Help message has not yet been added for mode'''
__shorthelp__ = 'Shorthelp not defined yet'
__longhelp__ = 'Longhelp not defined yet'
__args__ = []
- def __init__(self, configfile):
- self.configfile = configfile
- self.__cfp = False
- self.log = logging.getLogger('Bcfg2.Server.Admin.Mode')
-
- def getCFP(self):
- if not self.__cfp:
- self.__cfp = ConfigParser.ConfigParser()
- self.__cfp.read(self.configfile)
- return self.__cfp
- cfp = property(getCFP)
+ def __init__(self):
+ self.log = logging.getLogger('Bcfg2.Server.Admin.Mode')
+ self.repo_path = settings.SERVER_REPOSITORY
def __call__(self, args):
- if args[0] == 'help':
- print self.__longhelp__
- raise SystemExit(0)
+ return
def errExit(self, emsg):
print emsg
raise SystemExit(1)
- def get_repo_path(self):
- '''return repository path'''
- return self.cfp.get('server', 'repository')
-
def load_stats(self, client):
- stats = lxml.etree.parse("%s/etc/statistics.xml" % (self.get_repo_path()))
+ stats = lxml.etree.parse("%s/etc/statistics.xml" % (self.repo_path))
hostent = stats.xpath('//Node[@name="%s"]' % client)
if not hostent:
self.errExit("Could not find stats for client %s" % (client))
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index fb9a58c7d..152edc62d 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -3,6 +3,7 @@
import getopt, difflib, logging, lxml.etree, os, popen2, re, socket, sys, ConfigParser
import Bcfg2.Server.Core, Bcfg2.Logging
+from Bcfg2.Settings import settings
log = logging.getLogger('bcfg-admin')
@@ -36,6 +37,9 @@ if __name__ == '__main__':
if opt in ("-C", "--configfile"):
configfile = arg
+ # override default settings
+ settings.read_config_file(configfile)
+
modes = [x.lower() for x in Bcfg2.Server.Admin.__all__]
modes.remove('mode')
@@ -52,7 +56,8 @@ if __name__ == '__main__':
mode_cls = mode_import(modname)
except ImportError, e:
log.error("Failed to load admin mod %s: %s" % (modname, e))
- mode = mode_cls(configfile)
+ raise SystemExit(0)
+ mode = mode_cls()
mode(args[1:])
else:
print "unknown mode %s" % args[0]