summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Admin
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
commit46a47b4120b3d892b8149a5e181e4d976ad87f99 (patch)
treef2697f233fc7f5ad5022864222a5ca87715a651b /src/lib/Bcfg2/Server/Admin
parente1f99d1d5045e0511db42debb30aa97da2018796 (diff)
parent3d06f311274d6b942ee89d8cdb13b2ecc99af1b0 (diff)
downloadbcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.gz
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.bz2
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.zip
Merge branch '1.4.x'
Conflicts: debian/bcfg2-server.install doc/server/plugins/grouping/metadata.txt src/lib/Bcfg2/Client/Client.py src/lib/Bcfg2/Client/Tools/Portage.py src/lib/Bcfg2/Client/Tools/RcUpdate.py src/lib/Bcfg2/Client/Tools/YUM24.py src/lib/Bcfg2/Client/Tools/__init__.py src/lib/Bcfg2/Client/Tools/launchd.py src/lib/Bcfg2/Options.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/Plugin/helpers.py src/lib/Bcfg2/Server/Plugins/Metadata.py src/lib/Bcfg2/Server/models.py src/lib/Bcfg2/Utils.py src/sbin/bcfg2-info src/sbin/bcfg2-test testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py testsuite/Testsrc/test_code_checks.py
Diffstat (limited to 'src/lib/Bcfg2/Server/Admin')
-rw-r--r--src/lib/Bcfg2/Server/Admin/Compare.py13
-rw-r--r--src/lib/Bcfg2/Server/Admin/Init.py62
-rw-r--r--src/lib/Bcfg2/Server/Admin/Perf.py38
-rw-r--r--src/lib/Bcfg2/Server/Admin/Pull.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Reports.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Snapshots.py163
-rw-r--r--src/lib/Bcfg2/Server/Admin/Syncdb.py10
-rw-r--r--src/lib/Bcfg2/Server/Admin/Viz.py61
-rw-r--r--src/lib/Bcfg2/Server/Admin/Xcmd.py49
-rw-r--r--src/lib/Bcfg2/Server/Admin/__init__.py21
10 files changed, 127 insertions, 298 deletions
diff --git a/src/lib/Bcfg2/Server/Admin/Compare.py b/src/lib/Bcfg2/Server/Admin/Compare.py
index c56dd0a8f..d0831362c 100644
--- a/src/lib/Bcfg2/Server/Admin/Compare.py
+++ b/src/lib/Bcfg2/Server/Admin/Compare.py
@@ -9,8 +9,8 @@ class Compare(Bcfg2.Server.Admin.Mode):
__usage__ = ("<old> <new>\n\n"
" -r\trecursive")
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.important = {'Path': ['name', 'type', 'owner', 'group', 'mode',
'important', 'paranoid', 'sensitive',
'dev_type', 'major', 'minor', 'prune',
@@ -22,15 +22,14 @@ class Compare(Bcfg2.Server.Admin.Mode):
'Service': ['name', 'type', 'status', 'mode',
'target', 'sequence', 'parameters'],
'Action': ['name', 'timing', 'when', 'status',
- 'command'],
- 'PostInstall': ['name']
+ 'command']
}
def compareStructures(self, new, old):
- if new.tag == 'Independent':
- bundle = 'Base'
- else:
+ if new.get("name"):
bundle = new.get('name')
+ else:
+ bundle = 'Independent'
identical = True
diff --git a/src/lib/Bcfg2/Server/Admin/Init.py b/src/lib/Bcfg2/Server/Admin/Init.py
index 4b8d65597..884405786 100644
--- a/src/lib/Bcfg2/Server/Admin/Init.py
+++ b/src/lib/Bcfg2/Server/Admin/Init.py
@@ -8,8 +8,7 @@ import random
import socket
import string
import getpass
-import subprocess
-
+from Bcfg2.Utils import Executor
import Bcfg2.Server.Admin
import Bcfg2.Server.Plugin
import Bcfg2.Options
@@ -104,23 +103,26 @@ def gen_password(length):
def create_key(hostname, keypath, certpath, country, state, location):
"""Creates a bcfg2.key at the directory specifed by keypath."""
- kcstr = ("openssl req -batch -x509 -nodes -subj '/C=%s/ST=%s/L=%s/CN=%s' "
- "-days 1000 -newkey rsa:2048 -keyout %s -noout" % (country,
- state,
- location,
- hostname,
- keypath))
- subprocess.call((kcstr), shell=True)
- ccstr = ("openssl req -batch -new -subj '/C=%s/ST=%s/L=%s/CN=%s' -key %s "
- "| openssl x509 -req -days 1000 -signkey %s -out %s" % (country,
- state,
- location,
- hostname,
- keypath,
- keypath,
- certpath))
- subprocess.call((ccstr), shell=True)
+ cmd = Executor(timeout=120)
+ subject = "/C=%s/ST=%s/L=%s/CN=%s'" % (country, state, location, hostname)
+ key = cmd.run(["openssl", "req", "-batch", "-x509", "-nodes",
+ "-subj", subject, "-days", "1000", "-newkey", "rsa:2048",
+ "-keyout", keypath, "-noout"])
+ if not key.success:
+ print("Error generating key: %s" % key.error)
+ return
os.chmod(keypath, stat.S_IRUSR | stat.S_IWUSR) # 0600
+ csr = cmd.run(["openssl", "req", "-batch", "-new", "-subj", subject,
+ "-key", keypath])
+ if not csr.success:
+ print("Error generating certificate signing request: %s" % csr.error)
+ return
+ cert = cmd.run(["openssl", "x509", "-req", "-days", "1000",
+ "-signkey", keypath, "-out", certpath],
+ inputdata=csr.stdout)
+ if not cert.success:
+ print("Error signing certificate: %s" % cert.error)
+ return
def create_conf(confpath, confdata):
@@ -144,14 +146,9 @@ def create_conf(confpath, confdata):
class Init(Bcfg2.Server.Admin.Mode):
"""Interactively initialize a new repository."""
- options = {'configfile': Bcfg2.Options.CFILE,
- 'plugins': Bcfg2.Options.SERVER_PLUGINS,
- 'proto': Bcfg2.Options.SERVER_PROTOCOL,
- 'repo': Bcfg2.Options.SERVER_REPOSITORY,
- 'sendmail': Bcfg2.Options.SENDMAIL_PATH}
-
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.data = dict()
self.plugins = Bcfg2.Options.SERVER_PLUGINS.default
@@ -176,9 +173,16 @@ class Init(Bcfg2.Server.Admin.Mode):
def __call__(self, args):
# Parse options
- opts = Bcfg2.Options.OptionParser(self.options)
- opts.parse(args)
- self._set_defaults(opts)
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(configfile=Bcfg2.Options.CFILE,
+ plugins=Bcfg2.Options.SERVER_PLUGINS,
+ proto=Bcfg2.Options.SERVER_PROTOCOL,
+ repo=Bcfg2.Options.SERVER_REPOSITORY,
+ sendmail=Bcfg2.Options.SENDMAIL_PATH))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
+ self._set_defaults(setup)
# Prompt the user for input
self._prompt_config()
diff --git a/src/lib/Bcfg2/Server/Admin/Perf.py b/src/lib/Bcfg2/Server/Admin/Perf.py
index 86eb6810d..a7e67c956 100644
--- a/src/lib/Bcfg2/Server/Admin/Perf.py
+++ b/src/lib/Bcfg2/Server/Admin/Perf.py
@@ -2,7 +2,7 @@
import sys
import Bcfg2.Options
-import Bcfg2.Proxy
+import Bcfg2.Client.Proxy
import Bcfg2.Server.Admin
@@ -11,24 +11,24 @@ class Perf(Bcfg2.Server.Admin.Mode):
def __call__(self, args):
output = [('Name', 'Min', 'Max', 'Mean', 'Count')]
- optinfo = {
- 'ca': Bcfg2.Options.CLIENT_CA,
- 'certificate': Bcfg2.Options.CLIENT_CERT,
- 'key': Bcfg2.Options.SERVER_KEY,
- 'password': Bcfg2.Options.SERVER_PASSWORD,
- 'server': Bcfg2.Options.SERVER_LOCATION,
- 'user': Bcfg2.Options.CLIENT_USER,
- 'timeout': Bcfg2.Options.CLIENT_TIMEOUT,
- }
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
- proxy = Bcfg2.Proxy.ComponentProxy(setup['server'],
- setup['user'],
- setup['password'],
- key=setup['key'],
- cert=setup['certificate'],
- ca=setup['ca'],
- timeout=setup['timeout'])
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(ca=Bcfg2.Options.CLIENT_CA,
+ certificate=Bcfg2.Options.CLIENT_CERT,
+ key=Bcfg2.Options.SERVER_KEY,
+ password=Bcfg2.Options.SERVER_PASSWORD,
+ server=Bcfg2.Options.SERVER_LOCATION,
+ user=Bcfg2.Options.CLIENT_USER,
+ timeout=Bcfg2.Options.CLIENT_TIMEOUT))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
+ proxy = Bcfg2.Client.Proxy.ComponentProxy(setup['server'],
+ setup['user'],
+ setup['password'],
+ key=setup['key'],
+ cert=setup['certificate'],
+ ca=setup['ca'],
+ timeout=setup['timeout'])
data = proxy.get_statistics()
for key in sorted(data.keys()):
output.append((key, ) +
diff --git a/src/lib/Bcfg2/Server/Admin/Pull.py b/src/lib/Bcfg2/Server/Admin/Pull.py
index 130e85b67..1905fac3c 100644
--- a/src/lib/Bcfg2/Server/Admin/Pull.py
+++ b/src/lib/Bcfg2/Server/Admin/Pull.py
@@ -22,8 +22,8 @@ class Pull(Bcfg2.Server.Admin.MetadataCore):
"-I", "interactive",
"-s", "stdin"))
- def __init__(self, setup):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.MetadataCore.__init__(self)
self.log = False
self.mode = 'interactive'
diff --git a/src/lib/Bcfg2/Server/Admin/Reports.py b/src/lib/Bcfg2/Server/Admin/Reports.py
index 6e313e84b..bb5ee352b 100644
--- a/src/lib/Bcfg2/Server/Admin/Reports.py
+++ b/src/lib/Bcfg2/Server/Admin/Reports.py
@@ -69,8 +69,8 @@ class Reports(Bcfg2.Server.Admin.Mode):
" Django commands:\n " \
+ "\n ".join(django_commands))
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
try:
import south
except ImportError:
diff --git a/src/lib/Bcfg2/Server/Admin/Snapshots.py b/src/lib/Bcfg2/Server/Admin/Snapshots.py
deleted file mode 100644
index c2d279391..000000000
--- a/src/lib/Bcfg2/Server/Admin/Snapshots.py
+++ /dev/null
@@ -1,163 +0,0 @@
-from datetime import date
-import sys
-
-# Prereq issues can be signaled with ImportError, so no try needed
-import sqlalchemy, sqlalchemy.orm
-import Bcfg2.Server.Admin
-import Bcfg2.Server.Snapshots
-import Bcfg2.Server.Snapshots.model
-from Bcfg2.Server.Snapshots.model import Snapshot, Client, Metadata, Base, \
- File, Group, Package, Service
-# Compatibility import
-from Bcfg2.Compat import u_str
-
-class Snapshots(Bcfg2.Server.Admin.Mode):
- """ Interact with the Snapshots system """
- __usage__ = "[init|query qtype]"
-
- q_dispatch = {'client': Client,
- 'group': Group,
- 'metadata': Metadata,
- 'package': Package,
- 'snapshot': Snapshot}
-
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
- self.session = Bcfg2.Server.Snapshots.setup_session(self.configfile)
- self.cfile = self.configfile
-
- def __call__(self, args):
- Bcfg2.Server.Admin.Mode.__call__(self, args)
- if len(args) == 0 or args[0] == '-h':
- print(self.__usage__)
- raise SystemExit(0)
-
- if args[0] == 'query':
- if args[1] in self.q_dispatch:
- q_obj = self.q_dispatch[args[1]]
- if q_obj == Client:
- rows = []
- labels = ('Client', 'Active')
- for host in \
- self.session.query(q_obj).filter(q_obj.active == False):
- rows.append([host.name, 'No'])
- for host in \
- self.session.query(q_obj).filter(q_obj.active == True):
- rows.append([host.name, 'Yes'])
- self.print_table([labels]+rows,
- justify='left',
- hdr=True,
- vdelim=" ",
- padding=1)
- elif q_obj == Group:
- print("Groups:")
- for group in self.session.query(q_obj).all():
- print(" %s" % group.name)
- else:
- results = self.session.query(q_obj).all()
- else:
- print('error')
- raise SystemExit(1)
- elif args[0] == 'init':
- # Initialize the Snapshots database
- dbpath = Bcfg2.Server.Snapshots.db_from_config(self.cfile)
- engine = sqlalchemy.create_engine(dbpath, echo=True)
- metadata = Base.metadata
- metadata.create_all(engine)
- Session = sqlalchemy.orm.sessionmaker()
- Session.configure(bind=engine)
- session = Session()
- session.commit()
- elif args[0] == 'dump':
- client = args[1]
- snap = Snapshot.get_current(self.session, u_str(client))
- if not snap:
- print("Current snapshot for %s not found" % client)
- sys.exit(1)
- print("Client %s last run at %s" % (client, snap.timestamp))
- for pkg in snap.packages:
- print("C:", pkg.correct, 'M:', pkg.modified)
- print("start", pkg.start.name, pkg.start.version)
- print("end", pkg.end.name, pkg.end.version)
- elif args[0] == 'reports':
- # bcfg2-admin reporting interface for Snapshots
- if '-a' in args[1:]:
- # Query all hosts for Name, Status, Revision, Timestamp
- q = self.session.query(Client.name,
- Snapshot.correct,
- Snapshot.revision,
- Snapshot.timestamp)\
- .filter(Client.id==Snapshot.client_id)\
- .group_by(Client.id)
- rows = []
- labels = ('Client', 'Correct', 'Revision', 'Time')
- for item in q.all():
- cli, cor, time, rev = item
- rows.append([cli, cor, time, rev])
- self.print_table([labels]+rows,
- justify='left',
- hdr=True, vdelim=" ",
- padding=1)
- elif '-b' in args[1:]:
- # Query a single host for bad entries
- if len(args) < 3:
- print("Usage: bcfg2-admin snapshots -b <client>")
- return
- client = args[2]
- snap = Snapshot.get_current(self.session, u_str(client))
- if not snap:
- print("Current snapshot for %s not found" % client)
- sys.exit(1)
- print("Bad entries:")
- bad_pkgs = [self.session.query(Package)
- .filter(Package.id==p.start_id).one().name \
- for p in snap.packages if p.correct == False]
- for p in bad_pkgs:
- print(" Package:%s" % p)
- bad_files = [self.session.query(File)
- .filter(File.id==f.start_id).one().name \
- for f in snap.files if f.correct == False]
- for filename in bad_files:
- print(" File:%s" % filename)
- bad_svcs = [self.session.query(Service)
- .filter(Service.id==s.start_id).one().name \
- for s in snap.services if s.correct == False]
- for svc in bad_svcs:
- print(" Service:%s" % svc)
- elif '-e' in args[1:]:
- # Query a single host for extra entries
- client = args[2]
- snap = Snapshot.get_current(self.session, u_str(client))
- if not snap:
- print("Current snapshot for %s not found" % client)
- sys.exit(1)
- print("Extra entries:")
- for pkg in snap.extra_packages:
- print(" Package:%s" % pkg.name)
- # FIXME: Do we know about extra files yet?
- for f in snap.extra_files:
- print(" File:%s" % f.name)
- for svc in snap.extra_services:
- print(" Service:%s" % svc.name)
- elif '--date' in args[1:]:
- year, month, day = args[2:]
- timestamp = date(int(year), int(month), int(day))
- snaps = []
- for client in self.session.query(Client).filter(Client.active == True):
- snaps.append(Snapshot.get_by_date(self.session,
- client.name,
- timestamp))
- rows = []
- labels = ('Client', 'Correct', 'Revision', 'Time')
- for snap in snaps:
- rows.append([snap.client.name,
- snap.correct,
- snap.revision,
- snap.timestamp])
- self.print_table([labels]+rows,
- justify='left',
- hdr=True,
- vdelim=" ",
- padding=1)
- else:
- print("Unknown options: ", args[1:])
diff --git a/src/lib/Bcfg2/Server/Admin/Syncdb.py b/src/lib/Bcfg2/Server/Admin/Syncdb.py
index 4ba840b86..84ad93ae0 100644
--- a/src/lib/Bcfg2/Server/Admin/Syncdb.py
+++ b/src/lib/Bcfg2/Server/Admin/Syncdb.py
@@ -8,15 +8,17 @@ from django.core.management import setup_environ, call_command
class Syncdb(Bcfg2.Server.Admin.Mode):
""" Sync the Django ORM with the configured database """
- options = {'configfile': Bcfg2.Options.WEB_CFILE}
def __call__(self, args):
# Parse options
- opts = Bcfg2.Options.OptionParser(self.options)
- opts.parse(args)
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_option("web_configfile", Bcfg2.Options.WEB_CFILE)
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
setup_environ(Bcfg2.settings)
- Bcfg2.Server.models.load_models(cfile=opts['configfile'])
+ Bcfg2.Server.models.load_models(cfile=setup['web_configfile'])
try:
call_command("syncdb", interactive=False, verbosity=0)
diff --git a/src/lib/Bcfg2/Server/Admin/Viz.py b/src/lib/Bcfg2/Server/Admin/Viz.py
index 1d9d25f16..cdd8fd0cb 100644
--- a/src/lib/Bcfg2/Server/Admin/Viz.py
+++ b/src/lib/Bcfg2/Server/Admin/Viz.py
@@ -1,10 +1,8 @@
""" Produce graphviz diagrams of metadata structures """
import getopt
-from subprocess import Popen, PIPE
-import pipes
import Bcfg2.Server.Admin
-
+from Bcfg2.Utils import Executor
class Viz(Bcfg2.Server.Admin.MetadataCore):
""" Produce graphviz diagrams of metadata structures """
@@ -29,10 +27,9 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
'indianred1', 'limegreen', 'orange1', 'lightblue2',
'green1', 'blue1', 'yellow1', 'darkturquoise', 'gray66']
- __plugin_blacklist__ = ['DBStats', 'Snapshots', 'Cfg', 'Pkgmgr',
- 'Packages', 'Rules', 'Account', 'Decisions',
- 'Deps', 'Git', 'Svn', 'Fossil', 'Bzr', 'Bundler',
- 'TGenshi', 'Base']
+ __plugin_blacklist__ = ['DBStats', 'Cfg', 'Pkgmgr',
+ 'Packages', 'Rules', 'Decisions',
+ 'Deps', 'Git', 'Svn', 'Fossil', 'Bzr', 'Bundler']
def __call__(self, args):
# First get options to the 'viz' subcommand
@@ -73,40 +70,34 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
else:
fmt = 'png'
+ exc = Executor()
cmd = ["dot", "-T", fmt]
if output:
cmd.extend(["-o", output])
+ idata = ["digraph groups {",
+ '\trankdir="LR";',
+ self.metadata.viz(hosts, bundles,
+ key, only_client, self.colors)]
+ if key:
+ idata.extend([
+ "\tsubgraph cluster_key {",
+ '\tstyle="filled";',
+ '\tcolor="lightblue";',
+ '\tBundle [ shape="septagon" ];',
+ '\tGroup [shape="ellipse"];',
+ '\tProfile [style="bold", shape="ellipse"];',
+ '\tHblock [label="Host1|Host2|Host3",shape="record"];',
+ '\tlabel="Key";',
+ "\t}"])
+ idata.append("}")
try:
- dotpipe = Popen(cmd, stdin=PIPE, stdout=PIPE, close_fds=True)
+ result = exc.run(cmd, inputdata=idata)
except OSError:
# on some systems (RHEL 6), you cannot run dot with
# shell=True. on others (Gentoo with Python 2.7), you
# must. In yet others (RHEL 5), either way works. I have
# no idea what the difference is, but it's kind of a PITA.
- cmd = ["dot", "-T", pipes.quote(fmt)]
- if output:
- cmd.extend(["-o", pipes.quote(output)])
- dotpipe = Popen(cmd, shell=True,
- stdin=PIPE, stdout=PIPE, close_fds=True)
- try:
- dotpipe.stdin.write("digraph groups {\n")
- except:
- print("write to dot process failed. Is graphviz installed?")
- raise SystemExit(1)
- dotpipe.stdin.write('\trankdir="LR";\n')
- dotpipe.stdin.write(self.metadata.viz(hosts, bundles,
- key, only_client, self.colors))
- if key:
- dotpipe.stdin.write("\tsubgraph cluster_key {\n")
- dotpipe.stdin.write('\tstyle="filled";\n')
- dotpipe.stdin.write('\tcolor="lightblue";\n')
- dotpipe.stdin.write('\tBundle [ shape="septagon" ];\n')
- dotpipe.stdin.write('\tGroup [shape="ellipse"];\n')
- dotpipe.stdin.write('\tProfile [style="bold", shape="ellipse"];\n')
- dotpipe.stdin.write('\tHblock [label="Host1|Host2|Host3", '
- 'shape="record"];\n')
- dotpipe.stdin.write('\tlabel="Key";\n')
- dotpipe.stdin.write("\t}\n")
- dotpipe.stdin.write("}\n")
- dotpipe.stdin.close()
- return dotpipe.stdout.read()
+ result = exc.run(cmd, shell=True, inputdata=idata)
+ if not result.success:
+ print("Error running %s: %s" % (cmd, result.error))
+ raise SystemExit(result.retval)
diff --git a/src/lib/Bcfg2/Server/Admin/Xcmd.py b/src/lib/Bcfg2/Server/Admin/Xcmd.py
index 79eeebc7c..6f411c2e4 100644
--- a/src/lib/Bcfg2/Server/Admin/Xcmd.py
+++ b/src/lib/Bcfg2/Server/Admin/Xcmd.py
@@ -2,7 +2,7 @@
import sys
import Bcfg2.Options
-import Bcfg2.Proxy
+import Bcfg2.Client.Proxy
import Bcfg2.Server.Admin
from Bcfg2.Compat import xmlrpclib
@@ -12,34 +12,31 @@ class Xcmd(Bcfg2.Server.Admin.Mode):
__usage__ = "<command>"
def __call__(self, args):
- optinfo = {
- 'server': Bcfg2.Options.SERVER_LOCATION,
- 'user': Bcfg2.Options.CLIENT_USER,
- 'password': Bcfg2.Options.SERVER_PASSWORD,
- 'key': Bcfg2.Options.SERVER_KEY,
- 'certificate': Bcfg2.Options.CLIENT_CERT,
- 'ca': Bcfg2.Options.CLIENT_CA,
- 'timeout': Bcfg2.Options.CLIENT_TIMEOUT,
- }
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(args)
- Bcfg2.Proxy.RetryMethod.max_retries = 1
- proxy = Bcfg2.Proxy.ComponentProxy(setup['server'],
- setup['user'],
- setup['password'],
- key=setup['key'],
- cert=setup['certificate'],
- ca=setup['ca'],
- timeout=setup['timeout'])
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(ca=Bcfg2.Options.CLIENT_CA,
+ certificate=Bcfg2.Options.CLIENT_CERT,
+ key=Bcfg2.Options.SERVER_KEY,
+ password=Bcfg2.Options.SERVER_PASSWORD,
+ server=Bcfg2.Options.SERVER_LOCATION,
+ user=Bcfg2.Options.CLIENT_USER,
+ timeout=Bcfg2.Options.CLIENT_TIMEOUT))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
+ Bcfg2.Client.Proxy.RetryMethod.max_retries = 1
+ proxy = Bcfg2.Client.Proxy.ComponentProxy(setup['server'],
+ setup['user'],
+ setup['password'],
+ key=setup['key'],
+ cert=setup['certificate'],
+ ca=setup['ca'],
+ timeout=setup['timeout'])
if len(setup['args']) == 0:
print("Usage: xcmd <xmlrpc method> <optional arguments>")
return
- cmd = setup['args'][0]
- args = ()
- if len(setup['args']) > 1:
- args = tuple(setup['args'][1:])
+ cmd = args[0]
try:
- data = getattr(proxy, cmd)(*args)
+ data = getattr(proxy, cmd)(*args[1:])
except xmlrpclib.Fault:
flt = sys.exc_info()[1]
if flt.faultCode == 7:
@@ -49,7 +46,7 @@ class Xcmd(Bcfg2.Server.Admin.Mode):
return
else:
raise
- except Bcfg2.Proxy.ProxyError:
+ except Bcfg2.Client.Proxy.ProxyError:
err = sys.exc_info()[1]
print("Proxy Error: %s" % err)
return
diff --git a/src/lib/Bcfg2/Server/Admin/__init__.py b/src/lib/Bcfg2/Server/Admin/__init__.py
index 19175533f..0c4764642 100644
--- a/src/lib/Bcfg2/Server/Admin/__init__.py
+++ b/src/lib/Bcfg2/Server/Admin/__init__.py
@@ -12,7 +12,6 @@ __all__ = [
'Pull',
'Query',
'Reports',
- 'Snapshots',
'Syncdb',
'Tidy',
'Viz',
@@ -35,15 +34,15 @@ class Mode(object):
__usage__ = None
__args__ = []
- def __init__(self, setup):
- self.setup = setup
- self.configfile = setup['configfile']
+ def __init__(self):
+ self.setup = Bcfg2.Options.get_option_parser()
+ self.configfile = self.setup['configfile']
self.__cfp = False
self.log = logging.getLogger('Bcfg2.Server.Admin.Mode')
usage = "bcfg2-admin %s" % self.__class__.__name__.lower()
if self.__usage__ is not None:
usage += " " + self.__usage__
- setup.hm = usage
+ self.setup.hm = usage
def getCFP(self):
""" get a config parser for the Bcfg2 config file """
@@ -129,19 +128,19 @@ class MetadataCore(Mode):
__plugin_whitelist__ = None
__plugin_blacklist__ = None
- def __init__(self, setup):
- Mode.__init__(self, setup)
+ def __init__(self):
+ Mode.__init__(self)
if self.__plugin_whitelist__ is not None:
- setup['plugins'] = [p for p in setup['plugins']
+ self.setup['plugins'] = [p for p in self.setup['plugins']
if p in self.__plugin_whitelist__]
elif self.__plugin_blacklist__ is not None:
- setup['plugins'] = [p for p in setup['plugins']
+ self.setup['plugins'] = [p for p in self.setup['plugins']
if p not in self.__plugin_blacklist__]
# admin modes don't need to watch for changes. one shot is fine here.
- setup['filemonitor'] = 'pseudo'
+ self.setup['filemonitor'] = 'pseudo'
try:
- self.bcore = Bcfg2.Server.Core.BaseCore(setup)
+ self.bcore = Bcfg2.Server.Core.BaseCore()
except Bcfg2.Server.Core.CoreInitError:
msg = sys.exc_info()[1]
self.errExit("Core load failed: %s" % msg)