[Dev OpenGP] [89] Added logging |
[ Thread Index |
Date Index
| More opengp.tuxfamily.org/development Archives
]
Revision: 89
Author: nicolaf
Date: 2009-03-25 16:41:51 +0100 (Wed, 25 Mar 2009)
Log Message:
-----------
Added logging
Modified Paths:
--------------
trunk/src/bin/ogpdaemon
trunk/src/lib/ogp/core/__init__.py
trunk/src/lib/ogp/core/ogpcore.py
trunk/src/lib/ogp/core/ogpldapconsts.py
trunk/src/lib/ogp/etree/__init__.py
trunk/src/lib/ogp/etree/elementmethods.py
trunk/src/lib/ogp/plugins/__init__.py
trunk/src/lib/ogp/plugins/motd/motd.py
trunk/src/lib/ogp/plugins/ogpdaemon/ogpdaemon.py
trunk/src/lib/ogp/plugins/plugin.py
trunk/src/lib/ogp/plugins/test/__init__.pyc
trunk/src/lib/ogp/plugins/test/test.pyc
Modified: trunk/src/bin/ogpdaemon
===================================================================
--- trunk/src/bin/ogpdaemon 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/bin/ogpdaemon 2009-03-25 15:41:51 UTC (rev 89)
@@ -3,12 +3,14 @@
from ogp.core import *
from ogp.plugins import *
+import logging
uri = "ldap://localhost:389"
userDn = "cn=admin,dc=ogp"
passwd = "toor"
dn='cn=mac1,ou=titi,ou=tutu,dc=ogp'
+logging.basicConfig(filename='/home/nico/log.log', level=logging.DEBUG,format='%(asctime)s %(levelname)-8s %(message)s')
# Connection
core = OgpCore(uri, userDn, passwd)
Modified: trunk/src/lib/ogp/core/__init__.py
===================================================================
--- trunk/src/lib/ogp/core/__init__.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/core/__init__.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -3,3 +3,6 @@
from ogpcore import *
from ogpldapconsts import *
+import logging
+
+logging.debug('Loaded ogp.core.')
Modified: trunk/src/lib/ogp/core/ogpcore.py
===================================================================
--- trunk/src/lib/ogp/core/ogpcore.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/core/ogpcore.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -7,6 +7,10 @@
from ogpldapconsts import *
from lxml.etree import *
from ogp.etree import *
+import logging
+import sys
+from hashlib import sha1
+from base64 import standard_b64encode
class OgpCore(object):
"""
@@ -25,18 +29,29 @@
"""
Creates singleton instance
"""
+ logging.debug('OgpCore.__init__(uri=' + repr(uri) + ', dn=' + repr(dn) + ', passwd=****, certs=[not implemented])')
# Check whether we already have an instance
if OgpCore.__instance is None:
# Create and remember instance
- OgpCore.__instance = OgpCore.__ogpcore(uri, dn, passwd, certs)
+ logging.info('OgpCore: connecting to ' + repr(uri) + ' with dn=' + repr(dn) + '...')
+ try:
+ OgpCore.__instance = OgpCore.__ogpcore(uri, dn, passwd, certs)
+ except:
+ logging.error('OgpCore: initialization failed with ' + repr(sys.exc_info()[1]) + '.')
+ OgpCore.__instance = None
+ raise
+ else:
+ logging.warning('OgpCore: already connected!')
# Store instance reference as the only member in the handle
self.__dict__['OgpCore__instance'] = OgpCore.__instance
def __getattr__(self, attr):
+ logging.debug('OgpCore.__getattr__(attr=' + repr(attr) + ')')
# Delegate access to implementation
return getattr(self.__instance, attr)
def __setattr__(self, attr, value):
+ logging.debug('OgpCore.__setattr__(attr=' + repr(attr) + ', value=' + repr(value) + ')')
# Delegate access to implementation
return setattr(self.__instance, attr, value)
@@ -44,6 +59,7 @@
"""
Returns the core unique instance
"""
+ logging.debug('OgpCore.getInstance()')
return OgpCore.__instance
getInstance = staticmethod(getInstance)
@@ -57,20 +73,28 @@
passwd: user password
certs: path to certs files (.pem)
"""
+ logging.debug('OgpCore.__ogpcore.__init__(uri=' + repr(uri) + ', dn=' + repr(dn) + ', passwd=****, certs=[not implemented])')
self.l = ldap.initialize(uri)
self.l.simple_bind_s(dn, passwd)
def __del__(self):
+ logging.debug('OgpCore.__ogpcore.__del__()')
#close LDAP connection before deleting the object
self.l.unbind_s()
- def createOU(self, dn, description=None):
+ def createOU(self, dn, description=None, others={}):
"""
Creates an oGPOrganizationalUnit LDAP object and initializes it.
dn: the distinguished name of the targeted object
description (optionnal): an optional description of the object
"""
- attrs = {}
+ logging.debug('OgpCore.__ogpcore.createOU(dn=' + repr(dn) + 'description=' + repr(description) + ', others=' + repr(others) + ')')
+ if description is not None:
+ logging.info('OgpCore: creating organizational unit ' + repr(dn) + '( ' + description + ')')
+ else:
+ logging.info('OgpCore: creating organizational unit ' + repr(dn) + '.')
+
+ attrs = others
attrs['objectclass'] = OgpLDAPConsts.OBJECTCLASS_OU
attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
if description is not None:
@@ -78,12 +102,20 @@
attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
self.__add(dn, attrs)
- def createMachine(self, dn, others={}):
+ def createMachine(self, dn, passwd, description=None, others={}):
"""
Creates an oGPComputer LDAP object and initializes it.
dn: the distinguished name of the targeted object
+ passwd: the cleartext password for the machine
+ description (optionnal): an optional description of the object
others (optionnal) : other LDAP attributes
"""
+ logging.debug('OgpCore.__ogpcore.createMachine(dn=' + repr(dn) + ', others=' + repr(others) + ')')
+ if description is not None:
+ logging.info('OgpCore: creating organizational unit ' + repr(dn) + '( ' + description + ')')
+ else:
+ logging.info('OgpCore: creating organizational unit ' + repr(dn) + '.')
+
attrs = others
attrs['objectClass'] = OgpLDAPConsts.OBJECTCLASS_MACHINE
attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
@@ -97,8 +129,14 @@
attrs[OgpLDAPConsts.ATTR_OBJECTSID]
except:
attrs[OgpLDAPConsts.ATTR_OBJECTSID] = OgpLDAPConsts.VALUE_OBJECTSID
+ s=sha1()
+ s.update(passwd)
+ attrs[OgpLDAPConsts.ATTR_USERPASSWORD] = "{SHA}" + standard_b64encode(s.digest())
attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
+ if description is not None:
+ attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
+
self.__add(dn, attrs)
def deleteDN(self, dn, fullTree=False):
@@ -107,6 +145,8 @@
dn: the distinguished name of the targeted object
fullTree: if set to True, deletion is recursive
"""
+ logging.debug('OgpCore.__ogpcore.deleteDn(dn=' + repr(dn), 'fullTree=' + repr(fullTree) + ')')
+ logging.info('OgpCore: deleting ' + repr(dn) + '(recursive: ' + repr(fullTree) + ').')
if fullTree: #recursively delete direct children before deleting dn itself
tree = self.l.search_s(dn, ldap.SCOPE_SUBTREE, '(objectclass=*)' ,[''])
for e in tree:
@@ -120,6 +160,7 @@
dn: the distinguished name of the targeted object
attrs: a list containing the requested attributes' names
"""
+ logging.debug('OgpCore.__ogpcore.pullAttributes(dn=' + repr(dn), 'attrs=' + repr(attrs) + ')')
return self.l.search_s(dn, ldap.SCOPE_BASE, attrlist=attrs)[0][1]
def pushDescription(self, dn, description):
@@ -128,9 +169,24 @@
dn: the distinguished name of the targeted object
description: the description
"""
+ logging.debug('OgpCore.__ogpcore.pushDescription(dn=' + repr(dn), 'description=' + repr(description) + ')')
+ logging.info('OgpCore: pushing description on ' + repr(dn) + '(description: ' + repr(fullTree) + ').')
mods = [(ldap.MOD_REPLACE, OgpLDAPConsts.ATTR_DESCRIPTION, description)]
self.__modify(dn, mods)
+ def pushPasswd(self, dn, passwd):
+ """
+ Sets the OgpLDAPConsts.ATTR_USERPASSWORD LDAP attribute
+ dn : the distinguished name of the targeted object
+ passwd: the cleartext password
+ """
+ logging.debug('OgpCore.__ogpcore.pushPasswd(dn=' + repr(dn), 'passwd=****)')
+ logging.info('OgpCore: pushing userPasword on ' + repr(dn) + '.')
+ s=sha1()
+ s.update(passwd)
+ mods = [(ldap.MOD_REPLACE, OgpLDAPConsts.ATTR_DESCRIPTION, "{SHA}" + standard_b64encode(s.digest()))]
+ self.__modify(dn, mods)
+
def pullPluginConf(self, dn, pluginName, fullTree=False):
"""
Retrieves the XML tree containing the configuration for a given plugin and a given DN.
@@ -139,6 +195,7 @@
pluginName: the targeted plugin name
fullTree: if set to True, merges the conf from the baseDN up to the given DN
"""
+ logging.debug('OgpCore.__ogpcore.pullPluginConf(dn=' + repr(dn) + 'pluginName=' + repr(pluginName) + ', fullTree=' + repr(fullTree) + ')')
pConf = None
if fullTree:
dn=str2dn(dn)
@@ -168,6 +225,8 @@
dn: the distinguished name of the targeted object
pluginConf: a XML tree reprensenting the XML configuration. Its root must be <plugin name="[pluginName]">
"""
+ logging.debug('OgpCore.__ogpcore.pushPluginConf(dn=' + repr(dn) + 'pluginConf=' + pluginConf.toString() + ')')
+ logging.info('OgpCore: pushing conf for plugin ' + pluginName + ' on ' + repr(dn) + '.')
#replace current <plugin name="..." /> entry
pluginName = pluginConf.get(OgpXmlConsts.ATTR_PLUGIN_NAME)
currentConf = self.__pullConf(dn)
@@ -192,6 +251,7 @@
Returns a dict containing all the oGPSOA attributes from the baseDN up to the targeted object.
dn: the distinguished name of the targeted object
"""
+ logging.debug('OgpCore.__ogpcore.pullSOAs(dn=' + repr(dn) + ')')
SOAs = {}
dn=str2dn(dn)
dn.reverse()
@@ -210,6 +270,7 @@
identified by its DN, to install the configuration store in the LDAP.
dn: the distinguished name of the targeted object
"""
+ logging.debug('OgpCore.__ogpcore.getRequiredPlugins(dn=' + repr(dn) + ')')
plugins = []
dn=str2dn(dn)
dn.reverse()
@@ -227,18 +288,43 @@
return plugins
def __add(self, dn, attrs):
- ldif = modlist.addModlist(attrs)
- self.l.add_s(dn,ldif)
+ logging.debug('OgpCore.__ogpcore.__add(dn=' + repr(dn) + ', attrs=' + repr(attrs) + ')')
+ try:
+ ldif = modlist.addModlist(attrs)
+ self.l.add_s(dn,ldif)
+ except:
+ logging.error('OgpCore: __add failed with ' + repr(sys.exc_info()[1]) + '.')
+ raise
def __modify(self, dn, mods):
- self.l.modify_s(dn,mods)
+ logging.debug('OgpCore.__ogpcore.__modify(dn=' + repr(dn) + ', mods=' + repr(mods) + ')')
+ try:
+ self.l.modify_s(dn,mods)
+ except:
+ logging.error('OgpCore: __modify failed with ' + repr(sys.exc_info()[1]) + '.')
+ raise
def __delete(self, dn):
- self.l.delete_s(dn)
+ logging.debug('OgpCore.__ogpcore.__delete(dn=' + repr(dn) + ')')
+ try:
+ self.l.delete_s(dn)
+ except:
+ logging.error('OgpCore: __delete failed with ' + repr(sys.exc_info()[1]) + '.')
+ raise
def __pullConf(self, dn):
- return fromstring(self.pullAttributes(dn,[OgpLDAPConsts.ATTR_CONFIG])[OgpLDAPConsts.ATTR_CONFIG][0], OGP_PARSER)
+ logging.debug('OgpCore.__ogpcore.__pullConf(dn=' + repr(dn) + ')')
+ try:
+ return fromstring(self.pullAttributes(dn,[OgpLDAPConsts.ATTR_CONFIG])[OgpLDAPConsts.ATTR_CONFIG][0], OGP_PARSER)
+ except:
+ logging.error('OgpCore: __pullConf failed with ' + repr(sys.exc_info()[1]) + '.')
+ raise
def __pullSOA(self, dn):
- return int(self.pullAttributes(dn, [OgpLDAPConsts.ATTR_OGPSOA])[OgpLDAPConsts.ATTR_OGPSOA][0])
-
+ logging.debug('OgpCore.__ogpcore.__pullSOA(dn=' + repr(dn) + ')')
+ try:
+ return int(self.pullAttributes(dn, [OgpLDAPConsts.ATTR_OGPSOA])[OgpLDAPConsts.ATTR_OGPSOA][0])
+ except:
+ logging.error('OgpCore: __pullSOA failed with ' + repr(sys.exc_info()[1]) + '.')
+ raise
+
Modified: trunk/src/lib/ogp/core/ogpldapconsts.py
===================================================================
--- trunk/src/lib/ogp/core/ogpldapconsts.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/core/ogpldapconsts.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -16,6 +16,7 @@
ATTR_OBJECTSID = "objectSid"
ATTR_OGPSOA = "oGPSOA"
ATTR_MACHINECERTIFICATE = "oGPMachineCertificate"
+ ATTR_USERPASSWORD = "userPassword"
VALUE_CONFIG = "<ogp/>"
VALUE_SAMACCOUNTNAME = "N/A"
Modified: trunk/src/lib/ogp/etree/__init__.py
===================================================================
--- trunk/src/lib/ogp/etree/__init__.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/etree/__init__.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -4,6 +4,7 @@
from lxml.etree import *
from elementmethods import *
from ogpxmlconsts import *
+import logging
def parse(source, parser=None):
if not hasattr(source, "read"):
@@ -20,3 +21,5 @@
OGP_PARSER = XMLParser()
OGP_PARSER.set_element_class_lookup(ElementDefaultClassLookup(element=OgpElement))
Element = OGP_PARSER.makeelement
+
+logging.debug('Loaded ogp.etree.')
Modified: trunk/src/lib/ogp/etree/elementmethods.py
===================================================================
--- trunk/src/lib/ogp/etree/elementmethods.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/etree/elementmethods.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -5,8 +5,10 @@
from copy import deepcopy
from ogpxmlconsts import *
from ogp.misc import *
+import logging
def Element(name):
+ logging.debug('Element(name=' + repr(name) + ')')
OGP_PARSER = XMLParser()
OGP_PARSER.set_element_class_lookup(ElementDefaultClassLookup(element=OgpElement))
return OGP_PARSER.makeelement(name)
@@ -34,6 +36,7 @@
If target attribute is text, deletes all subelements.
If targeted attribue is tail, forces value to None
"""
+ logging.debug('OgpElement.__setattr__(item=' + repr(item) + ', value=' + repr(value) + ')')
if item == "text" and value is not None:
self.delElements()
if item == "tail":
@@ -47,6 +50,7 @@
Protects the 'attrib' attributes by returning a copy instead of the real object.
This returns a dict instance, not an _Attrib, but it seems to work
"""
+ logging.debug('OgpElement.__getattr__(item=' + repr(item) + ')')
if item == "attrib":
return dict(ElementBase.__getattribute__(self, item))
else:
@@ -56,6 +60,7 @@
"""
Provides a private property to access the real 'attrib' attribute.
"""
+ logging.debug('OgpElement.__getRealAttrib()')
return ElementBase.__getattribute__(self, "attrib")
__attrib = property(__getRealAttrib)
@@ -63,6 +68,7 @@
"""
Returns the attributes dict(), without the OgpXmlConsts.ATTR_BLOCK ('block') attribute.
"""
+ logging.debug('OgpElement.__getAttributes()')
res = dict()
for key in self.attrib:
if key != OgpXmlConsts.ATTR_BLOCK:
@@ -74,6 +80,7 @@
"""
A more convenient way to access the OgpXmlConsts.ATTR_BLOCK ('block') special attribute.
"""
+ logging.debug('OgpElement.__getBlocking()')
b = self.get(OgpXmlConsts.ATTR_BLOCK)
if b is None:
return False
@@ -84,7 +91,7 @@
"""
Sets the OgpXmlConsts.ATTR_BLOCK ('block') special attribute.
"""
- assert isinstance(blocking, bool)
+ logging.debug('OgpElement.__setBlocking(blocking=' + repr(blocking) + ')')
if blocking:
self.__attrib[OgpXmlConsts.ATTR_BLOCK] = str(blocking).lower()
else:
@@ -98,6 +105,7 @@
"""
Removes any child
"""
+ logging.debug('OgpElement.delElements()')
for e in self:
self.remove(e)
@@ -105,7 +113,7 @@
"""
Checks if no child element has the same name and the same attributes,
"""
- assert isinstance(elt, OgpElement)
+ logging.debug('OgpElement.__checkUnicity(elt=' + repr(elt) + ')')
for e in self:
if e.tag == elt.tag and e.attributes == elt.attributes:
return False
@@ -116,7 +124,7 @@
Works as the standard function, but if newChild is an Element,
checks unicity before adding, and deletes text
"""
- assert isinstance(newChild, OgpElement)
+ logging.debug('OgpElement.append(newChild=' + repr(newChild) + ')')
if (not self.__checkUnicity(newChild)):raise OgpXmlError('append: element is not unique.')
self.text = None
ElementBase.append(self, newChild)
@@ -126,9 +134,7 @@
Works as the standard function, but if newChild is an Element, but
checks unicity before adding, and deletes text.
"""
- assert isinstance(newChild, OgpElement)
- assert isinstance(index, int)
-
+ logging.debug('OgpElement.insert(index=' + repr(index) + ', newChild=' + repr(newChild) + ')')
if (not self.__checkUnicity(newChild)):raise OgpXmlError('insert: element is not unique.')
self.text = None
ElementBase.insert(self, index, element)
@@ -138,8 +144,8 @@
Works as the standard function, but if newChild is an Element, but
checks unicity before adding, and deletes text.
"""
+ logging.debug('OgpElement.extend(elements=' + repr(elements) + ')')
for element in elements:
- assert isinstance(element, OgpElement)
if (not self.__checkUnicity(element)):raise OgpXmlError('extend: element is not unique.')
self.text = None
ElementBase.extend(self, elements)
@@ -150,8 +156,7 @@
Works as the standard function, but if newChild is an Element, but
checks that self will still be unique after setting the attribute.
"""
- assert isinstance(name, str)
- assert isinstance(value, str)
+ logging.debug('OgpElement.set(name=' + repr(name) + ', value=' + repr(value) + ')')
#Computation of new attribute list
newattrs=self.attributes
newattrs[name] = value
@@ -169,8 +174,7 @@
Merges self with peer. Peer is considered as the "child" conf (LDAP speaking), so that it has precendence on self.
See plugin documentation for further details on the algorithm
"""
- assert isinstance(peer, OgpElement)
-
+ logging.debug('OgpElement.merge()')
#if self and peer are not exactly the same (i.e. same name and same attributes),
#raise OgpXmlError.
if self.tag != peer.tag or self.attributes != peer.attributes:
@@ -218,8 +222,7 @@
e.merge(deepcopy(peerCommon[k]))
def __reorder_ids(self, peer):
- assert isinstance(peer, OgpElement)
-
+ logging.debug('OgpElement.__reorder_ids(peer=' + repr(peer) + ')')
peerMaxId = 0
if len(peer) > 0 and len(self) > 0:
for e in peer:
@@ -233,12 +236,14 @@
e.set(OgpXmlConsts.ATTR_ID, str(int(id) + peerMaxId + 1))
def toString(self, xsl=None, params=None):
+ logging.debug('OgpElement.__reorder_ids(xsl=' + repr(xsl) + ', params=' + repr(params) + ')')
if xsl is None:
return tostring(self)
else:
self.__processXsl(xsl, params)
def __processXsl(self, xsl, params):
+ logging.debug('OgpElement.__processXsl(xsl=' + repr(xsl) + ', params=' + repr(params) + ')')
transform = XSLT(xsl)
if params is None:
return str(transform(self))
@@ -246,6 +251,12 @@
return str(transform(self), params)
def __makePlugin(name, fileNames):
+ """
+ Creates a standard XML plugin tree, with the specified <file> sections
+ name: the plugin name
+ fileNames: the list of the desired files
+ """
+ logging.debug('OgpElement.__makePlugin(name=' + repr(name) + ', fileNames=' + repr(fileNames) + ')')
res = Element(OgpXmlConsts.TAG_PLUGIN)
res.set(OgpXmlConsts.ATTR_PLUGIN_NAME, name)
res.append(Element(OgpXmlConsts.TAG_CONF))
@@ -258,6 +269,11 @@
makePlugin = staticmethod(__makePlugin)
def __makeFile(name):
+ """
+ Creates a standard XML file tree.
+ name: the file name
+ """
+ logging.debug('OgpElement.__makeFile(name=' + repr(name) + ')')
res = Element(OgpXmlConsts.TAG_FILE)
res.set(OgpXmlConsts.ATTR_FILE_NAME, name)
res.append(Element(OgpXmlConsts.TAG_CONF))
@@ -270,8 +286,8 @@
OGP XML error class.
"""
def __init__(self, value):
- assert isinstance(value, str)
self.value = value
+ logging.error(str(self))
def __str__(self):
return repr("OgpXmlError: " + self.value)
Modified: trunk/src/lib/ogp/plugins/__init__.py
===================================================================
--- trunk/src/lib/ogp/plugins/__init__.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/plugins/__init__.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -7,12 +7,16 @@
from os import listdir
from imp import *
from sys import stderr
+import logging
# Load plugins
path = dirname(resource_filename(__name__, '__init.py__'))
for d in listdir(path):
if isdir(join(path,d)):
try:
- load_package('ogp.plugins.' + d,join(path,d))
+ load_package('ogp.plugins.' + d, join(path,d))
+ logging.debug('ogp.plugins: loaded plugin ' + repr(d) + '.')
except:
- stderr.write("ogp.plugins warning: failed to load plugin '" + d + "'.\n")
+ logging.warning('ogp.plugins: failed to load plugin ' + repr(d) + '.')
+
+logging.debug('Loaded ogp.plugins.')
Modified: trunk/src/lib/ogp/plugins/motd/motd.py
===================================================================
--- trunk/src/lib/ogp/plugins/motd/motd.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/plugins/motd/motd.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -3,6 +3,7 @@
from ogp.plugins.plugin import *
from os import spawnl, P_WAIT
+import logging
class Motd(Plugin):
name = "motd"
@@ -13,8 +14,10 @@
__distro_xpath = OgpXmlConsts.TAG_CONF + "/distro"
def pushFile(self, file, content, blocking=False):
+ logging.debug('Motd.pushFile(file=' + repr(file) + ', content=' + repr(content) + ', blocking=' + repr(blocking) + ')')
+ logging.debug('Motd: pushing file ' + repr(file) + '(blocking=' + repr(blocking) + ')')
if file == 'motd.tail':
- print "motd.tail should not be edited! Editing motd..."
+ logging.warning('Motd.pushFile: motd.tail should not be edited! Editing motd...')
file = 'motd'
if file == 'motd':
@@ -23,6 +26,7 @@
file_e.blocking = blocking
def pullFile(self, file, fullTree=False):
+ logging.debug('Motd.pullFile(file=' + repr(file) + ', fullTree=' + repr(fullTree) + ')')
if fullTree:
parentConf = self.core.pullPluginConf(self.parentDn, self.name, fullTree=True)
if parentConf is None:
@@ -33,6 +37,7 @@
return self.currentConf.xpath(self.__motd_xpath + '/' + OgpXmlConsts.TAG_CONF)[0].text
def help(self, cmdName=None):
+ logging.debug('Motd.help(cmdName=' + repr(cmdName) + ')')
if cmdName is None:
return {'setdistro': "Sets distribution name."}
elif cmdName == 'setdistro':
@@ -42,6 +47,8 @@
raise OgpPluginError('help: unknown command (' + cmdName + ')')
def runCommand(self, cmdName, argv):
+ logging.debug('Motd.runCommand(cmdName=' + repr(cmdName) + ', argv=' + repr(argv) + ')')
+ logging.info('Motd: running command ' + repr(cmdName) + '(arguments: ' + repr(argv) + ')')
if cmdName != 'setdistro':
raise OgpPluginError('runCommand: unknown command (' + cmdName + ')')
else:
@@ -61,6 +68,8 @@
dist_e.blocking = blocking
def installConf(self):
+ logging.debug('Motd.installConf()')
+ logging.info('Motd: installing conf.')
motd = str(self.pullFile('motd', True))
dist_e = self.currentConf.xpath(self.__motd_xpath)
prefix = '/home/alban/tmp/ogp/etc/'
Modified: trunk/src/lib/ogp/plugins/ogpdaemon/ogpdaemon.py
===================================================================
--- trunk/src/lib/ogp/plugins/ogpdaemon/ogpdaemon.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/plugins/ogpdaemon/ogpdaemon.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -3,6 +3,7 @@
from ogp.plugins.plugin import *
from os import spawnl, P_WAIT
+import logging
class OgpDaemon(Plugin):
name = "ogpdaemon"
@@ -12,12 +13,15 @@
__conf_xpath = OgpXmlConsts.TAG_CONF
def pushFile(self, file, content, blocking=False):
+ logging.debug('OgpDaemon.pushFile(file=' + repr(file) + ', content=' + repr(content) + ', blocking=' + repr(blocking) + ')')
raise OgpPluginError("pushFile: OgpDaemon has no files! You're useless buddy!")
def pullFile(self, file, fullTree=False):
+ logging.debug('OgpDaemon.pullFile(file=' + repr(file) + ', fullTree=' + repr(fullTree) + ')')
raise OgpPluginError("pullFile: OgpDaemon has no files! You're useless buddy!")
def help(self, cmdName=None):
+ logging.debug('Motd.help(cmdName=' + repr(cmdName) + ')')
if cmdName is None:
return {'setparam': "Sets a parameter.",'setparam': "Gets a parameter."}
elif cmdName == 'setparam':
@@ -34,6 +38,8 @@
raise OgpPluginError("help: unknown command '" + cmdName + "'")
def runCommand(self, cmdName, argv):
+ logging.debug('OgpDaemon.runCommand(cmdName=' + repr(cmdName) + ', argv=' + repr(argv) + ')')
+ logging.info('OgpDaemon: running command ' + repr(cmdName) + '(arguments: ' + repr(argv) + ')')
if cmdName == 'setparam':
self.__setParam(argv['param'], argv['value'])
return None
@@ -43,6 +49,9 @@
raise OgpPluginError("runCommand: unknown command '" + cmdName +"'")
def installConf(self):
+ logging.debug('OgpDaemon.installConf()')
+ logging.info('OgpDaemon: retrieving conf.')
+
local = {}
remote = {}
for p in self.__localParams:
@@ -52,6 +61,7 @@
return {'local':local,'remote':remote}
def __getParam(self, param, fullTree=False):
+ logging.debug('OgpDaemon.__getParam(param=' + repr(param) + ', fullTree=' + repr(fullTree) + ')')
defaults = {
'updateOnStartup':'true',
'timeBetweenUpdates':'15',
@@ -81,6 +91,8 @@
def __setParam(self, param, value):
+ logging.debug('OgpDaemon.__setParam(param=' + repr(param) + ', value=' + repr(value) + ')')
+ logging.debug('OgpDaemon: setting param' + repr(param) + ' to ' + repr(value) + '.')
if (param not in self.__localParams) and (param not in self.__remoteParams):
raise OgpPluginError("__setParam: unknown parameter '" + param + "'")
xpath = self.__conf_xpath + '/' + param
Modified: trunk/src/lib/ogp/plugins/plugin.py
===================================================================
--- trunk/src/lib/ogp/plugins/plugin.py 2009-03-25 13:43:34 UTC (rev 88)
+++ trunk/src/lib/ogp/plugins/plugin.py 2009-03-25 15:41:51 UTC (rev 89)
@@ -7,6 +7,7 @@
from ogp.misc import *
import os
from stat import ST_MODE, S_IXUSR, S_IRUSR, S_IWUSR, S_IXGRP, S_IRGRP, S_IWGRP, S_IXOTH, S_IROTH, S_IWOTH, S_ISUID, S_ISGID, S_ISVTX
+import logging
class omitted(object):
pass
@@ -16,6 +17,7 @@
Plugin class and metaclass __setattr__ method
Throws an exception when attempting to modify the plugin name.
"""
+ logging.debug('setattr(self=' + repr(self) + ', item=' + repr(item) + ', value=' + repr(value) + ')')
ro = ['name', 'files']
if item in ro:
raise OgpPluginError('__setattr__: ' + item + ' is readonly.')
@@ -31,10 +33,10 @@
"""
Provides plugins' base class and plugin registration mechanism.
"""
+ __metaclass__ = M_Plugin
name = None # the plugin name
files = []
- __metaclass__ = M_Plugin
parentDn = None
currentConf = None
dn = None
@@ -42,6 +44,7 @@
__registeredPlugins = dict()
def __init__(self, dn):
+ logging.debug('Plugin.__init__(dn=' + repr(dn) + ')')
self.core = OgpCore.getInstance()
self.dn = dn
# Dirty but it pleases Michel :-P
@@ -58,6 +61,7 @@
"""
returns a plugin class from a name.
"""
+ logging.debug('Plugin.getPluginFromName(name=' + repr(name) + ')')
return Plugin.__registeredPlugins[name]
getPluginFromName = staticmethod(__getPluginFromName)
@@ -66,6 +70,7 @@
Registers a plugin class.
Plugins should register themselves in their __init__.py using Plugin.registerPlugin([pluginClass]).
"""
+ logging.debug('Plugin.__registerPlugin(pluginClass=' + repr(pluginClass) + ')')
try:
Plugin.__registeredPlugins[pluginClass.name]
raise OgpPluginError("registerPlugin: duplicated plugin name '" + pluginClass.name + "'.")
@@ -78,19 +83,24 @@
"""
Returns a dict() containing all the registered plugin classes
"""
+ logging.debug('Plugin.__getRegisteredPlugins()')
return Plugin.__registeredPlugins.copy()
getRegisteredPlugins = staticmethod(__getRegisteredPlugins)
def update(self):
"""
- Commit changes to LDAP
+ Commits changes to LDAP
"""
+ logging.debug('Plugin.update()')
+ logging.info('Plugin: commiting changes to LDAP.')
self.core.pushPluginConf(self.dn, self.currentConf)
def cancel(self):
"""
Do not commit and discard changes.
"""
+ logging.debug('Plugin.canel()')
+ logging.info('Plugin: discarding changes.')
self.currentConf = self.core.pullPluginConf(self.dn, self.name)
if self.currentConf is None:
self.currentConf = OgpElement.makePlugin(self.name, self.files)
@@ -101,6 +111,8 @@
Changes owner, changes the user and/or group ownership of
the given file
"""
+ logging.debug('Plugin.chown(fileName=' + repr(fileName) + ', uid=' + repr(uid) + ', gid=' + repr(gid) + ', blocking=' + repr(blocking) + ')')
+ logging.debug('Plugin: setting owner/group on file' + repr(fileName) + ' (uid=' + repr(uid) + ', gid=' + repr(gid) + ', blocking=' + repr(blocking) + ')')
file_e = self.__getFile(fileName)
sec_e = file_e.xpath(OgpXmlConsts.TAG_SECURITY)[0]
@@ -137,6 +149,11 @@
gid_e.blocking = blocking
def __getFile(self, fileName):
+ """
+ Returns the XML tree corresponding to a given file name
+ fileName: the targeted file name
+ """
+ logging.debug('Plugin.__getFile(fileName=' + repr(fileName) + ')')
arg = OgpXmlConsts.TAG_FILES + '/' + OgpXmlConsts.TAG_FILE + '[@' + OgpXmlConsts.ATTR_FILE_NAME + "='" + fileName + "']"
try:
return self.currentConf.xpath(arg)[0]
@@ -148,6 +165,8 @@
"""
Changes the permissions of the given file according to mode
"""
+ logging.debug('Plugin.chmod(fileName=' + repr(fileName) + ', rights=' + repr(rights) + ', blocking=' + repr(blocking) + ')')
+ logging.debug('Plugin: setting permissions on file' + repr(fileName) + ' (permissions=' + repr(rights) + ', blocking=' + repr(blocking) + ')')
file_e = self.__getFile(fileName)
sec_e = file_e.xpath(OgpXmlConsts.TAG_SECURITY)[0]
for tag in rights:
@@ -174,6 +193,8 @@
Reads attributes for file 'fileName' in XML tree and sets them
on file 'filePath'
"""
+ logging.debug('Plugin.setSecurityAttributes(fileName=' + repr(fileName) + ', filePath=' + repr(filePath) + ')')
+ logging.debug('Plugin: setting security attributes on file ' + repr(filePath) + ' from ' + repr(fileName) + 'file section.')
# Default file stats (644)
mask = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
# Default owner
@@ -259,8 +280,8 @@
OGP plugin error class.
"""
def __init__(self, value):
- assert isinstance(value, str)
self.value = value
+ logging.error(str(self))
def __str__(self):
return repr("OgpPluginError: " + self.value)
Modified: trunk/src/lib/ogp/plugins/test/__init__.pyc
===================================================================
(Binary files differ)
Modified: trunk/src/lib/ogp/plugins/test/test.pyc
===================================================================
(Binary files differ)