aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README43
-rwxr-xr-xexmachina.py80
-rwxr-xr-xtest.py25
3 files changed, 148 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..a4a387b
--- /dev/null
+++ b/README
@@ -0,0 +1,43 @@
+ _ _
+ _____ ___ __ ___ __ _ ___| |__ (_)_ __ __ _
+ / _ \ \/ / '_ ` _ \ / _` |/ __| '_ \| | '_ \ / _` |
+ | __/> <| | | | | | (_| | (__| | | | | | | | (_| |
+ \___/_/\_\_| |_| |_|\__,_|\___|_| |_|_|_| |_|\__,_|
+
+ by the hand of root
+
+### Status
+
+Just a first commit...
+
+TODO:
+* export python-augeas API calls in server
+* add /etc/init.d start/stop/status/reset API methods
+* re-implement python-augeas methods using API client-side
+* use /var/lib/exmachina/<something> as socket instead of /tmp/exmachina.sock?
+* check to make sure server is running as root
+* check/set permissions on socket after server opens it
+* tests and demonstrations
+* fix/remove logging
+
+### Dependancies (server)
+
+* augeas configuration editing library
+* python-augeas wrapper for augeas
+* bjsonrpc python library
+
+On debian (wheezy) try:
+
+ $ sudo apt-get install augeas-tools python-bjsonrpc python-augeas
+
+### Dependancies (client)
+
+* bjsonrpc
+
+On debian (wheezy) try:
+
+ $ sudo apt-get install bjsonrpc
+
+### License
+
+exmachina.py is GPLv3
diff --git a/exmachina.py b/exmachina.py
new file mode 100755
index 0000000..fca499e
--- /dev/null
+++ b/exmachina.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+# Author: bnewbold <bnewbold@robocracy.org>
+# Date: July 2012
+# License: GPLv3 (see http://www.gnu.org/licenses/gpl-3.0.html)
+
+import os
+import sys
+import optparse
+import logging
+import socket
+
+import bjsonrpc
+import bjsonrpc.handlers
+import bjsonrpc.server
+import augeas
+
+import time # TODO
+
+log = logging.getLogger(__name__)
+
+
+class ExMachinaHandler(bjsonrpc.handlers.BaseHandler):
+ def whattime(self):
+ print "hup!"
+ return time.time()
+
+ def listfiles(self):
+ a = augeas.Augeas()
+ return a.match("/files/etc/*")
+
+class ExMachinaClient():
+ pass #TODO
+
+def run_server(socket_path="/tmp/exmachina.sock"):
+ # TODO: check for root permissions, warn if not root
+ log.info('This is an INFO level message.')
+ log.debug('This is a DEBUG level message.')
+ log.warn('This is a WARN level message.')
+
+ # TODO: if socket file exists, try to delete it
+
+ if os.path.exists(socket_path):
+ os.unlink(socket_path)
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.bind(socket_path)
+ sock.listen(1)
+
+ serv = bjsonrpc.server.Server(sock, handler_factory=ExMachinaHandler)
+ serv.serve()
+
+# =============================================================================
+# Command line handling
+def main():
+
+ global log
+ parser = optparse.OptionParser(usage=
+ "usage: %prog [options]\n"
+ "%prog --help for more info."
+ )
+ parser.add_option("-v", "--verbose",
+ default=False,
+ help="Show more debugging statements",
+ action="store_true")
+
+ (options, args) = parser.parse_args()
+
+ if len(args) != 0:
+ parser.error("Incorrect number of arguments")
+
+ log = logging.getLogger()
+ if options.verbose:
+ log.setLevel(logging.DEBUG)
+ else:
+ log.setLevel(logging.INFO)
+
+ run_server()
+
+if __name__ == '__main__':
+ main()
diff --git a/test.py b/test.py
new file mode 100755
index 0000000..f6c4de1
--- /dev/null
+++ b/test.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import sys
+import optparse
+import logging
+import socket
+
+import bjsonrpc
+import bjsonrpc.connection
+import augeas
+
+# =============================================================================
+# Command line handling
+def main():
+
+ socket_path="/tmp/exmachina.sock"
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(socket_path)
+
+ c = bjsonrpc.connection.Connection(sock)
+ print c.call.whattime()
+ print c.call.listfiles()
+
+if __name__ == '__main__':
+ main()