diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-17 11:21:27 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-17 11:21:41 -0400 |
commit | 7c3368f78e7c5042932a4fb58cea4b2ac3130358 (patch) | |
tree | 39ea7d392fe118b91df702cce6bf0a0e3963c11e /tools | |
parent | 6683f2e8d48b1cbf8e4c1ad096c6b0c98eefe527 (diff) | |
download | bcfg2-7c3368f78e7c5042932a4fb58cea4b2ac3130358.tar.gz bcfg2-7c3368f78e7c5042932a4fb58cea4b2ac3130358.tar.bz2 bcfg2-7c3368f78e7c5042932a4fb58cea4b2ac3130358.zip |
added bcfg2_local.py, a tool to run bcfg2 against a local specification
Diffstat (limited to 'tools')
-rw-r--r-- | tools/README | 4 | ||||
-rwxr-xr-x | tools/bcfg2_local.py | 77 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tools/README b/tools/README index 7cae4409d..5b1fc0baf 100644 --- a/tools/README +++ b/tools/README @@ -20,6 +20,10 @@ bcfg2-import-config - Create tarball of changed files on a client for import into the specification +bcfg2_local.py + - Perform a full Bcfg2 run against a local repository instead of + against a remote server + bcfg2-profile-templates.py [<template>] - Benchmark template rendering times diff --git a/tools/bcfg2_local.py b/tools/bcfg2_local.py new file mode 100755 index 000000000..3ff623505 --- /dev/null +++ b/tools/bcfg2_local.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +""" This tool performs a full Bcfg2 run entirely against a local +repository, i.e., without a server. It starts up a local instance of +the server core, then uses that to get probes, run them, and so on.""" + +import sys +import socket +import Bcfg2.Options +from Bcfg2.Client.Client import Client +from Bcfg2.Server.Core import BaseCore + + +class LocalCore(BaseCore): + """ Local server core similar to the one started by bcfg2-info """ + + def __init__(self, setup): + saved = (setup['syslog'], setup['logging']) + setup['syslog'] = False + setup['logging'] = None + Bcfg2.Server.Core.BaseCore.__init__(self, setup=setup) + setup['syslog'], setup['logging'] = saved + self.fam.handle_events_in_interval(4) + + def _daemonize(self): + pass + + def _run(self): + pass + + def _block(self): + pass + + +class LocalProxy(object): + """ A local proxy (as opposed to XML-RPC) that proxies from the + Client object to the LocalCore object, adding a client address + pair to the argument list of each proxied call """ + + def __init__(self, core): + self.core = core + self.hostname = socket.gethostname() + self.ipaddr = socket.gethostbyname(self.hostname) + + def __getattr__(self, attr): + if hasattr(self.core, attr): + func = getattr(self.core, attr) + if func.exposed: + def inner(*args, **kwargs): + args = ((self.ipaddr, self.hostname), ) + args + return func(*args, **kwargs) + return inner + raise AttributeError(attr) + + +class LocalClient(Client): + """ A version of the Client class that uses LocalProxy instead of + an XML-RPC proxy to make its calls """ + + def __init__(self, setup, proxy): + Client.__init__(self, setup) + self._proxy = proxy + + +def main(): + optinfo = Bcfg2.Options.CLIENT_COMMON_OPTIONS + optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS) + setup = Bcfg2.Options.OptionParser(optinfo) + setup.parse(sys.argv[1:]) + + core = LocalCore(setup) + try: + LocalClient(setup, LocalProxy(core)).run() + finally: + core.shutdown() + +if __name__ == '__main__': + sys.exit(main()) |