[Dev OpenGP] [30] OgpCore is now a singleton |
[ Thread Index |
Date Index
| More opengp.tuxfamily.org/development Archives
]
Revision: 30
Author: alband85
Date: 2009-03-11 11:37:26 +0100 (Wed, 11 Mar 2009)
Log Message:
-----------
OgpCore is now a singleton
Modified Paths:
--------------
trunk/src/OgpCore.py
Modified: trunk/src/OgpCore.py
===================================================================
--- trunk/src/OgpCore.py 2009-03-10 17:26:20 UTC (rev 29)
+++ trunk/src/OgpCore.py 2009-03-11 10:37:26 UTC (rev 30)
@@ -5,64 +5,85 @@
import ldap.modlist as modlist
from OgpLDAPConsts import *
-class OgpCore:
+class OgpCore(object):
- def __init__(self, uri, dn=None, passwd=None, cert=None):
- '''
- Initlialize connection to LDAP server.
- uri: ldap://host:port
- dn: usdr dn
- passwd: user password
- cert: path to cert file (.pem)
- '''
- self.l = ldap.initialize(uri)
- self.l.simple_bind_s(dn, passwd)
+ __instance = None
- def __del__(self):
- self.l.unbind_s()
+ def __init__(self, uri, dn=None, passwd=None, cert=None):
+ """ Create singleton instance """
+ # Check whether we already have an instance
+ if OgpCore.__instance is None:
+ # Create and remember instance
+ OgpCore.__instance = OgpCore.__ogpcore(uri, dn, passwd, cert)
+ # Store instance reference as the only member in the handle
+ self.__dict__['OgpCore__instance'] = OgpCore.__instance
- def createOU(self, dn, description=None):
- attrs = {}
- attrs['objectclass'] = OgpLDAPConsts.OBJECTCLASS_OU
- attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
- attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
- attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
- self.__add(dn, attrs)
+ def __getattr__(self, attr):
+ """ Delegate access to implementation """
+ return getattr(self.__instance, attr)
- def __add(self, dn, attrs):
- ldif = modlist.addModlist(attrs)
- self.l.add_s(dn,ldif)
+ def __setattr__(self, attr, value):
+ """ Delegate access to implementation """
+ return setattr(self.__instance, attr, value)
- def createMachine(self, dn, others={}):
- attrs = others
- attrs['objectClass'] = OgpLDAPConsts.OBJECTCLASS_MACHINE
- attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
- try:
- attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME]
- except:
- attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME] = OgpLDAPConsts.VALUE_SAMACCOUNTNAME
- try:
- attrs[OgpLDAPConsts.ATTR_OBJECTSID]
- except:
- attrs[OgpLDAPConsts.ATTR_OBJECTSID] = OgpLDAPConsts.VALUE_OBJECTSID
- attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
- self.__add(dn, attrs)
+
+ class __ogpcore:
- def push(self, plugin, dn, overwrite):
- pass
+ def __init__(self, uri, dn=None, passwd=None, cert=None):
+ """
+ Initlialize connection to LDAP server.
+ uri: ldap://host:port
+ dn: usdr dn
+ passwd: user password
+ cert: path to cert file (.pem)
+ """
+ self.l = ldap.initialize(uri)
+ self.l.simple_bind_s(dn, passwd)
- def pull(self, ou, recursive):
- pass
+ def __del__(self):
+ self.l.unbind_s()
- def pullPlugin(self, ou, plugin, recursive):
- pass
+ def createOU(self, dn, description=None):
+ attrs = {}
+ attrs['objectclass'] = OgpLDAPConsts.OBJECTCLASS_OU
+ attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
+ attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
+ attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
+ self.__add(dn, attrs)
- def getFileList(self, ou, recursive):
- pass
+ def __add(self, dn, attrs):
+ ldif = modlist.addModlist(attrs)
+ self.l.add_s(dn,ldif)
- def build(self, ou, recursive):
- pass
+ def createMachine(self, dn, others={}):
+ attrs = others
+ attrs['objectClass'] = OgpLDAPConsts.OBJECTCLASS_MACHINE
+ attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
+ try:
+ attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME]
+ except:
+ attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME] = OgpLDAPConsts.VALUE_SAMACCOUNTNAME
+ try:
+ attrs[OgpLDAPConsts.ATTR_OBJECTSID]
+ except:
+ attrs[OgpLDAPConsts.ATTR_OBJECTSID] = OgpLDAPConsts.VALUE_OBJECTSID
+ attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
+ self.__add(dn, attrs)
- def buildFile(self, ou, recursive):
- pass
+ def push(self, plugin, dn, overwrite):
+ pass
+ def pull(self, ou, recursive):
+ pass
+
+ def pullPlugin(self, ou, plugin, recursive):
+ pass
+
+ def getFileList(self, ou, recursive):
+ pass
+
+ def build(self, ou, recursive):
+ pass
+
+ def buildFile(self, ou, recursive):
+ pass