summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorAdrian Likins <alikins@grimlock.devel.redhat.com>2007-09-20 15:08:27 -0400
committerAdrian Likins <alikins@grimlock.devel.redhat.com>2007-09-20 15:08:27 -0400
commit733df2df42180487608688951acf1a83e079a86c (patch)
tree01917e26d60194ac294008a95394d18029522b32 /modules
parentd96d4b72aebee6dc1089dd260705c23cb1b9cd27 (diff)
downloadthird_party-func-733df2df42180487608688951acf1a83e079a86c.tar.gz
third_party-func-733df2df42180487608688951acf1a83e079a86c.tar.xz
third_party-func-733df2df42180487608688951acf1a83e079a86c.zip
initial code drop
module_loader from the virt-factory node server xmlrpc server from the virt-factory-server code and some test modules no ssl support yet, no init scripts, no packagin etc
Diffstat (limited to 'modules')
-rw-r--r--modules/__init__.py0
-rwxr-xr-xmodules/baseobj.py115
-rwxr-xr-xmodules/test.py26
-rwxr-xr-xmodules/web_svc.py53
4 files changed, 194 insertions, 0 deletions
diff --git a/modules/__init__.py b/modules/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/__init__.py
diff --git a/modules/baseobj.py b/modules/baseobj.py
new file mode 100755
index 0000000..702f0a7
--- /dev/null
+++ b/modules/baseobj.py
@@ -0,0 +1,115 @@
+"""
+Virt-factory backend code.
+
+Copyright 2006, Red Hat, Inc
+Michael DeHaan <mdehaan@redhat.com>
+Scott Seago <sseago@redhat.com>
+
+This software may be freely redistributed under the terms of the GNU
+general public license.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+
+import string
+import exceptions
+import os
+
+class BaseObject(object):
+
+ FIELDS = [] # subclasses should define a list of db column names here
+
+ def load(self,hash,key,default=None):
+ """
+ Access a hash element safely...
+ """
+ # FIXME: it would be cool if load starts with a copy of the hash
+ # and clears off entries as recieved, such that we can tell if any
+ # entries are not loaded. This should result in a warning in the return
+ # object.
+ assert hash is not None, "hash is None"
+ assert key is not None, "key is None"
+ if hash.has_key(key):
+ return hash[key]
+ else:
+ return default
+
+ def to_datastruct(self,to_caller=False):
+ """
+ Return a hash representation of this object.
+ Defers to self.to_datastruct_internal which subclasses must implement.
+ """
+ ds = self.to_datastruct_internal()
+ if to_caller:
+ # don't send NULLs
+ ds = self.remove_nulls(ds)
+ return ds
+
+ def to_datastruct_internal(self):
+ """
+ Subclasses: implement this.
+ """
+ raise exceptions.NotImplementedError
+
+ def deserialize(self, args):
+ for x in self.FIELDS:
+ if args.has_key(x):
+ setattr(self, x, args[x])
+ else:
+ setattr(self, x, None)
+
+ def serialize(self):
+ result = {}
+ for x in self.FIELDS:
+ result[x] = getattr(self, x, None)
+ return result
+
+ def remove_nulls(self, x):
+ """
+ If any entries are None in the datastructure, prune them.
+ XMLRPC can't marshall None and this is our workaround. Objects
+ that are None are removed from the hash -- including hash keys that
+ are not None and have None for the value. The WUI or other SW
+ should know how to deal with these returns.
+ """
+ assert x is not None, "datastructure is None"
+ if type(x) == list:
+ newx = []
+ for i in x:
+ if type(i) == list or type(i) == dict:
+ newx.append(self.remove_nulls(i))
+ elif i is not None:
+ newx.append(i)
+ x = newx
+ elif type(x) == dict:
+ newx = {}
+ for i,j in x.iteritems():
+ if type(j) == list or type(j) == dict:
+ newx[i] = self.remove_nulls(x)
+ elif j is not None:
+ newx[i] = j
+ x = newx
+ return x
+
+ # ========================
+ # random utility functions
+
+ def is_printable(self, stringy):
+ # FIXME: use regex package
+
+ if stringy == None:
+ return False
+ if type(stringy) != str:
+ stringy = "%s" % stringy
+ try:
+ for letter in stringy:
+ if letter not in string.printable:
+ return False
+ return True
+ except:
+ return False
+
+
+ \ No newline at end of file
diff --git a/modules/test.py b/modules/test.py
new file mode 100755
index 0000000..7783b4e
--- /dev/null
+++ b/modules/test.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+
+from codes import *
+from modules import web_svc
+
+
+
+class Test(web_svc.WebSvc):
+ def __init__(self):
+ self.methods = {
+ "test_add": self.add,
+ "test_blippy": self.blippy,
+ }
+ web_svc.WebSvc.__init__(self)
+
+ def add(self, numb1, numb2):
+ return success(int(numb1) + int(numb2))
+
+ def blippy(self, foo):
+ fh = open("/tmp/blippy","w+")
+ fh.close()
+ return success(foo)
+
+methods = Test()
+register_rpc = methods.register_rpc
diff --git a/modules/web_svc.py b/modules/web_svc.py
new file mode 100755
index 0000000..ed4ec19
--- /dev/null
+++ b/modules/web_svc.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+## Virt-factory backend code.
+##
+## Copyright 2006, Red Hat, Inc
+## Adrian Likins <alikins@redhat.com
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+
+from codes import *
+
+import baseobj
+from server import config_data
+from server import logger
+
+import os
+import threading
+import time
+import traceback
+
+
+class WebSvc(object):
+ def __init__(self):
+
+ config_obj = config_data.Config()
+ config_result = config_obj.get()
+ self.config = config_result
+ self.__init_log()
+
+ def __init_log(self):
+ # lets see what happens when we c&p the stuff from server.py
+ log = logger.Logger()
+ self.logger = log.logger
+
+ def register_rpc(self, handlers):
+ for meth in self.methods:
+ handlers[meth] = self.methods[meth]
+
+ def offset_and_limit(self, args):
+ return args.get('offset', 0), args.get('limit', 100000)
+
+
+class AuthWebSvc(WebSvc):
+ def __init__(self):
+ WebSvc.__init__(self)
+
+