[Dev OpenGP] [23] Added LDAP connection, OU creation, machine creation

[ Thread Index | Date Index | More opengp.tuxfamily.org/development Archives ]


Revision: 23
Author:   alband85
Date:     2009-03-05 15:20:16 +0100 (Thu, 05 Mar 2009)

Log Message:
-----------
Added LDAP connection, OU creation, machine creation

Modified Paths:
--------------
    trunk/src/OgpCore.py
    trunk/src/Plugin.py

Added Paths:
-----------
    trunk/src/OgpLDAPConsts.py


Modified: trunk/src/OgpCore.py
===================================================================
--- trunk/src/OgpCore.py	2009-02-24 13:41:59 UTC (rev 22)
+++ trunk/src/OgpCore.py	2009-03-05 14:20:16 UTC (rev 23)
@@ -1,30 +1,68 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*
 
+import ldap
+import ldap.modlist as modlist
+from OgpLDAPConsts import *
+
 class OgpCore:
-	def	__init__(self, host, port, dn=None, passwd=None, cert=None):
-		pass
 
-	def createOU(dn, others=None):
-		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 createMachine(dn, others=None):
+	def __del__(self):
+		self.l.unbind_s()
+
+	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 __add(self, dn, attrs):
+		ldif = modlist.addModlist(attrs)
+		self.l.add_s(dn,ldif)
+
+	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 push(self, file, dn, overwrite):
 		pass
 
-	def push(file, ou, overwrite):
+	def pull(self, ou, recursive):
 		pass
 
-	def pull(ou, recursive):
+	def pullFile(self, ou, file, recursive):
 		pass
 
-	def pullFile(ou, file, recursive):
+	def getFileList(self, ou, recursive):
 		pass
 
-	def getFileList(ou, recursive):
+	def build(self, ou, recursive):
 		pass
 
-	def build(ou, recursive):
+	def buildFile(self, ou, recusrive):
 		pass
 
-	def buildFile(ou, recusrive):
-		pass

Added: trunk/src/OgpLDAPConsts.py
===================================================================
--- trunk/src/OgpLDAPConsts.py	                        (rev 0)
+++ trunk/src/OgpLDAPConsts.py	2009-03-05 14:20:16 UTC (rev 23)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+
+class OgpLDAPConsts:
+
+	OBJECTCLASS_OU 			= "oGPOrganizationalUnit"
+	OBJECTCLASS_MACHINE 	= "oGPComputer"
+
+	ATTR_DESCRIPTION 		= "description"
+	ATTR_CONFIG 			= "oGPXMLConfig"
+	ATTR_SAMACCOUNTNAME		= "sAMAccountName"
+	ATTR_OBJECTSID			= "objectSid"
+	ATTR_OGPSOA				= "oGPSOA"
+	ATTR_MACHINECERTIFICATE	= "oGPMachineCertificate"
+
+	VALUE_CONFIG			= "<conf></conf>"
+	VALUE_SAMACCOUNTNAME	= "N/A"
+	VALUE_OBJECTSID			= "\0"
+	VALUE_OGPSOA			= "0"

Modified: trunk/src/Plugin.py
===================================================================
--- trunk/src/Plugin.py	2009-02-24 13:41:59 UTC (rev 22)
+++ trunk/src/Plugin.py	2009-03-05 14:20:16 UTC (rev 23)
@@ -17,7 +17,7 @@
 	toXML = AbstractMethod('toXML')
 
 	def getName():
-		pass
+		return ""
 
 	def mergeFile(parentFile, childFile):
 		pass


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/