2788N/A#!/usr/bin/python
2788N/A
2788N/A# CDDL HEADER START
2788N/A#
2788N/A# The contents of this file are subject to the terms of the
2788N/A# Common Development and Distribution License, Version 1.0 only
2788N/A# (the "License"). You may not use this file except in compliance
2788N/A# with the License.
2788N/A#
6982N/A# You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6982N/A# or http://forgerock.org/license/CDDLv1.0.html.
2788N/A# See the License for the specific language governing permissions
2788N/A# and limitations under the License.
2788N/A#
2788N/A# When distributing Covered Code, include this CDDL HEADER in each
6982N/A# file and include the License file at legal-notices/CDDLv1_0.txt.
6982N/A# If applicable, add the following below this CDDL HEADER, with the
6982N/A# fields enclosed by brackets "[]" replaced with your own identifying
2788N/A# information:
2788N/A# Portions Copyright [yyyy] [name of copyright owner]
2788N/A#
2788N/A# CDDL HEADER END
2788N/A#
2788N/A#
3232N/A# Copyright 2008 Sun Microsystems, Inc.
6303N/A# Portions Copyright 2011-2013 ForgeRock AS.
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A# Global variable containing the list of servers ("Server" class instances) deployed
2788N/A_topologyServerList = []
2788N/A
2788N/A
2788N/A
2788N/A# Define ChangelogServer class
2788N/Aclass ChangelogServer:
2788N/A def __init__(self, port, id):
2788N/A self.port = port
2788N/A self.id = id
2788N/A self.changelogServerList = []
2788N/A
2788N/A def addChangelogServer(self, hostname, port):
2788N/A self.changelogServerList.append('%s:%s' % (hostname, port))
2788N/A
2788N/A def getPort(self):
2788N/A return self.port
2788N/A
2788N/A def getId(self):
2788N/A return self.id
2788N/A
2788N/A def getChangelogServerList(self):
2788N/A return self.changelogServerList
2788N/A
2788N/A
2788N/A# Define SynchronizedSuffix class:
2788N/Aclass SynchronizedSuffix:
2788N/A def __init__(self, suffixDn, id):
2788N/A self.suffixDn = suffixDn
2788N/A self.id = id
2788N/A self.changelogServerList = []
2788N/A
2788N/A def addChangelogServer(self, hostname, port):
2788N/A self.changelogServerList.append('%s:%s' % (hostname, port))
2788N/A
2788N/A def getSuffixDn(self):
2788N/A return self.suffixDn
2788N/A
2788N/A def getId(self):
2788N/A return self.id
2788N/A
2788N/A def getChangelogServerList(self):
2788N/A return self.changelogServerList
2788N/A
2788N/A
2788N/A# Define Server class
2788N/Aclass Server:
6984N/A def __init__(self, hostname, dir, port, adminPort, sslPort, jmxPort, rootDn, rootPwd, baseDn, debugPort, datadir):
2788N/A self.hostname = hostname
2788N/A self.dir = dir
5540N/A self.temp = '%s/temp' % dir
5540N/A if self.hostIsLocal(self.hostname):
5540N/A self.data = datadir
5540N/A else:
5540N/A self.data = '%s/testdata/data' % self.dir
2788N/A self.port = port
3853N/A self.adminPort = adminPort
2788N/A self.sslPort = sslPort
2788N/A self.jmxPort = jmxPort
2788N/A self.rootDn = rootDn
2788N/A self.rootPwd = rootPwd
2788N/A self.baseDn = baseDn
2788N/A self.changelogServer = None
6984N/A self.debugPort = debugPort
2788N/A self.synchronizedSuffixList = []
2788N/A
2788N/A def __repr__(self):
4631N/A return "Server: hostname=%s, directory=%s" % (self.hostname, self.dir)
2788N/A
2788N/A def addChangelogServer(self, changelogServer):
2788N/A self.changelogServer = changelogServer
2788N/A
2788N/A def addSynchronizedSuffix(self, synchronizedSuffix):
2788N/A self.synchronizedSuffixList.append(synchronizedSuffix)
2788N/A
2788N/A def getHostname(self):
2788N/A return self.hostname
5540N/A
2788N/A def getDir(self):
2788N/A return self.dir
5540N/A
5540N/A def getTmpDir(self):
5540N/A return self.temp
5540N/A
5540N/A def getDataDir(self):
5540N/A return self.data
2788N/A
2788N/A def getPort(self):
2788N/A return self.port
2788N/A
3853N/A def getAdminPort(self):
3853N/A return self.adminPort
3853N/A
2788N/A def getSslPort(self):
2788N/A return self.sslPort
2788N/A
2788N/A def getJmxPort(self):
2788N/A return self.jmxPort
2788N/A
2788N/A def getRootDn(self):
2788N/A return self.rootDn
2788N/A
2788N/A def getRootPwd(self):
2788N/A return self.rootPwd
2788N/A
2788N/A def getBaseDn(self):
2788N/A return self.baseDn
2788N/A
2788N/A def getChangelogServer(self):
2788N/A return self.changelogServer
2788N/A
6984N/A def getDebugPort(self):
6984N/A return self.debugPort
6984N/A
2788N/A def getSynchronizedSuffixList(self):
2788N/A return self.synchronizedSuffixList
2788N/A
2788N/A def requiresSynchronization(self):
4631N/A return (self.changelogServer is not None) or (len(self.synchronizedSuffixList) > 0)
4631N/A
4631N/A def isOnlyLdapServer(self):
4631N/A return (self.changelogServer is None) and (len(self.synchronizedSuffixList) > 0)
4631N/A
4631N/A def isOnlyReplServer(self):
4631N/A return (self.changelogServer is not None) and (len(self.synchronizedSuffixList) == 0)
4631N/A
4631N/A def splitReplServer(self):
4631N/A new_hostname = self.hostname
4631N/A new_dir = '%s-repl-server' % self.dir
4631N/A new_port = str( int(self.port) + 1 )
4631N/A new_adminPort = str( int(self.adminPort) + 1 )
4631N/A new_sslPort = str( int(self.sslPort) + 1 )
4631N/A new_jmxPort = str( int(self.jmxPort) + 1 )
4631N/A new_rootDn = self.rootDn
4631N/A new_rootPwd = self.rootPwd
4631N/A new_baseDn = self.baseDn
6984N/A new_changelogServer = self.changelogServer
6984N/A new_debugPort = self.debugPort
4631N/A self.changelogServer = None
4631N/A
4631N/A replServer = Server(new_hostname, new_dir, new_port, new_adminPort, new_sslPort,
6984N/A new_jmxPort, new_rootDn, new_rootPwd, new_baseDn, self.debugPort, self.data)
4631N/A replServer.addChangelogServer(new_changelogServer)
4631N/A
4631N/A return replServer
2788N/A
5540N/A def hostIsLocal(self,hostname):
5540N/A from socket import gethostbyname
5540N/A if gethostbyname(hostname).startswith('127.0'):
5540N/A return 1
5540N/A else:
5540N/A return 0
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the replication configuration
2788N/A# corresponding to the given server.
2788N/Adef write_replication_conf_ldif_file(path, server):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A # write the main replication configuration entry
2788N/A ldifLines.append('')
2788N/A
2788N/A ldifLines.append('dn: cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config')
2788N/A ldifLines.append('objectClass: top')
2788N/A ldifLines.append('objectClass: ds-cfg-synchronization-provider')
2788N/A ldifLines.append('objectClass: ds-cfg-replication-synchronization-provider')
2788N/A ldifLines.append('cn: Multimaster Synchronization')
2788N/A ldifLines.append('ds-cfg-enabled: true')
2788N/A ldifLines.append('ds-cfg-java-class: org.opends.server.replication.plugin.MultimasterReplication')
2788N/A
2788N/A
2788N/A # if server is a changelog server, write its corresponding configuration
2788N/A changelogServer = server.getChangelogServer()
2788N/A if changelogServer is not None :
2788N/A port = changelogServer.getPort()
2788N/A id = changelogServer.getId()
2788N/A list = changelogServer.getChangelogServerList()
2788N/A
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: cn=Replication Server,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config')
2788N/A ldifLines.append('objectClass: top')
2788N/A ldifLines.append('objectClass: ds-cfg-replication-server')
2788N/A ldifLines.append('cn: Replication Server')
2788N/A ldifLines.append('ds-cfg-replication-port: %s' % port)
2788N/A
2788N/A for chglgServer in list:
2788N/A ldifLines.append('ds-cfg-replication-server: %s' % chglgServer)
2788N/A
2788N/A ldifLines.append('ds-cfg-replication-server-id: %s' % id)
2788N/A
2788N/A
2788N/A # write the domains replication configuration entry
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: cn=domains,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config')
2788N/A ldifLines.append('objectClass: top')
2788N/A ldifLines.append('objectClass: ds-cfg-branch')
2788N/A ldifLines.append('cn: domains')
2788N/A
2788N/A # write the configuration for the synchronized suffixes, if any
2788N/A synchronizedSuffixList = server.getSynchronizedSuffixList()
2788N/A for i in range( len(synchronizedSuffixList) ):
2788N/A suffix = synchronizedSuffixList[i]
2788N/A dn = suffix.getSuffixDn()
2788N/A id = suffix.getId()
2788N/A list = suffix.getChangelogServerList()
2788N/A name = 'SUFFIX-%s' % i
2788N/A
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: cn=%s,cn=domains,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config' % name)
2788N/A ldifLines.append('objectClass: top')
2788N/A ldifLines.append('objectClass: ds-cfg-replication-domain')
2788N/A ldifLines.append('cn: %s' % name)
2788N/A ldifLines.append('ds-cfg-base-dn: %s' % dn)
2788N/A
2788N/A for chglgServer in list:
2788N/A ldifLines.append('ds-cfg-replication-server: %s' % chglgServer)
2788N/A
2788N/A ldifLines.append('ds-cfg-server-id: %s' % id)
2788N/A ldifLines.append('ds-cfg-receive-status: true')
2788N/A
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the root suffix entry to add
2788N/A# for a given suffix.
2788N/Adef write_replication_add_root_suffix_ldif_file(path, suffix):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A equalChar = suffix.find('=')
2788N/A commaChar = suffix.find(',')
2788N/A if commaChar == -1:
2788N/A commaChar = len(suffix)
2788N/A rdnType = suffix[:equalChar].strip()
2788N/A rdnValue = suffix[equalChar + 1 : commaChar].strip()
2788N/A
2788N/A if rdnType == 'o':
2788N/A objclass = 'organization'
2788N/A elif rdnType == 'ou':
2788N/A objclass = 'organizationalunit'
2788N/A elif rdnType == 'dc':
2788N/A objclass = 'domain'
2788N/A else:
2788N/A objclass = 'unknown'
2788N/A
2788N/A ldifLines.append('dn: %s' % suffix)
2788N/A ldifLines.append('%s: %s' % (rdnType,rdnValue))
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: %s' % objclass)
2788N/A
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with an entry to add
2788N/A# under a given suffix.
2788N/Adef write_replication_add_single_ldif_file(path, suffix):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A
2788N/A ldifLines.append('dn: uid=scarter,%s' % suffix)
2788N/A ldifLines.append('cn: Sam Carter')
2788N/A ldifLines.append('sn: Carter')
2788N/A ldifLines.append('givenname: Sam')
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: person')
2788N/A ldifLines.append('objectclass: organizationalPerson')
2788N/A ldifLines.append('objectclass: inetOrgPerson')
2788N/A ldifLines.append('ou: Accounting')
2788N/A ldifLines.append('ou: People')
2788N/A ldifLines.append('l: Sunnyvale')
2788N/A ldifLines.append('uid: scarter')
2788N/A ldifLines.append('mail: scarter@example.com')
2788N/A ldifLines.append('telephonenumber: +1 408 555 4798')
2788N/A ldifLines.append('facsimiletelephonenumber: +1 408 555 9751')
2788N/A ldifLines.append('roomnumber: 4612')
2788N/A ldifLines.append('userpassword: sprain')
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the entries to add
2788N/A# under a given suffix.
2788N/Adef write_replication_add_multiple_ldif_file(path, suffix):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A ldifLines.append('dn: o=replication tests,%s' % suffix)
2788N/A ldifLines.append('o: replication tests')
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: organization')
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: ou=People,o=replication tests,%s' % suffix)
2788N/A ldifLines.append('ou: People')
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: organizationalunit')
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: ou=Groups, o=replication tests,%s' % suffix)
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: organizationalunit')
2788N/A ldifLines.append('ou: Groups')
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: cn=Directory Administrators, ou=Groups, o=replication tests,%s' % suffix)
2788N/A ldifLines.append('cn: Directory Administrators')
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: groupofuniquenames')
2788N/A ldifLines.append('ou: Groups')
2788N/A ldifLines.append('uniquemember: uid=kvaughan, ou=People, o=replication tests,%s' % suffix)
2788N/A ldifLines.append('uniquemember: uid=rdaugherty, ou=People, o=replication tests,%s' % suffix)
2788N/A ldifLines.append('uniquemember: uid=hmiller, ou=People, o=replication tests,%s' % suffix)
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: ou=Special Users,o=replication tests,%s' % suffix)
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: organizationalUnit')
2788N/A ldifLines.append('ou: Special Users')
2788N/A ldifLines.append('description: Special Administrative Accounts')
2788N/A ldifLines.append('')
2788N/A ldifLines.append('dn: uid=scarter,ou=People,o=replication tests,%s' % suffix)
2788N/A ldifLines.append('cn: Sam Carter')
2788N/A ldifLines.append('sn: Carter')
2788N/A ldifLines.append('givenname: Sam')
2788N/A ldifLines.append('objectclass: top')
2788N/A ldifLines.append('objectclass: person')
2788N/A ldifLines.append('objectclass: organizationalPerson')
2788N/A ldifLines.append('objectclass: inetOrgPerson')
2788N/A ldifLines.append('ou: Accounting')
2788N/A ldifLines.append('ou: People')
2788N/A ldifLines.append('l: Sunnyvale')
2788N/A ldifLines.append('uid: scarter')
2788N/A ldifLines.append('mail: scarter@example.com')
2788N/A ldifLines.append('telephonenumber: +1 408 555 4798')
2788N/A ldifLines.append('facsimiletelephonenumber: +1 408 555 9751')
2788N/A ldifLines.append('roomnumber: 4612')
2788N/A ldifLines.append('userpassword: sprain')
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the modify to operate
2788N/A# on an entry in a given suffix.
2788N/Adef write_replication_mod_ldif_file(path, dn, mod_type, attr_type, attr_value):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A ldifLines.append('dn: %s' % dn)
2788N/A ldifLines.append('changetype: modify')
2788N/A ldifLines.append('%s: %s' % (mod_type,attr_type))
2788N/A if attr_value != None :
2788N/A ldifLines.append('%s: %s' % (attr_type,attr_value))
2788N/A
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the modify to operate
2788N/A# on an entry in a given suffix.
2788N/Adef write_replication_mod_binary_ldif_file(path, dn, mod_type, attr_type, binary_value_path):
2788N/A
2788N/A # open file and read the binary value (which is encoded in base64)
2788N/A binaryValueFile = open(binary_value_path, "r")
2788N/A binaryValue = binaryValueFile.read()
2788N/A binaryValueFile.close()
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A ldifLines.append('dn: %s' % dn)
2788N/A ldifLines.append('changetype: modify')
2788N/A ldifLines.append('%s: %s' % (mod_type,attr_type))
2788N/A ldifLines.append('%s:: %s' % (attr_type,binaryValue))
2788N/A
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A
2788N/A
2788N/A
2788N/A
2788N/A# Define the function that writes a ldif file with the modDN to operate
2788N/A# on an entry in a given suffix.
2788N/Adef write_replication_moddn_ldif_file(path, dn, newrdn, newsuperior, deleteoldrdn):
2788N/A
2788N/A ldifLines = []
2788N/A
2788N/A ldifLines.append('dn: %s' % dn)
2788N/A ldifLines.append('changetype: moddn')
2788N/A ldifLines.append('newRDN: %s' % newrdn)
2788N/A ldifLines.append('deleteOldRDN: %s' % deleteoldrdn)
2788N/A if newsuperior != None:
2788N/A ldifLines.append('newSuperior: %s' % newsuperior)
2788N/A
2788N/A
2788N/A
2788N/A # write out the ldif file
2788N/A outfile = open(path,"w")
2788N/A
2788N/A for line in ldifLines:
2788N/A outfile.write("%s\n" % line)
2788N/A
2788N/A outfile.close()
2788N/A