本文整理汇总了Python中lib389.Entry类的典型用法代码示例。如果您正苦于以下问题:Python Entry类的具体用法?Python Entry怎么用?Python Entry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_group
def add_group(topology):
"""Create a group for the user to have some rights to"""
log.info("Create a group entry: %s" % TEST_GROUP)
gentry = Entry(TEST_GROUP)
gentry.setValues("objectclass", "top", "extensibleobject")
gentry.setValues("cn", "testgroup")
topology.instance.add_s(gentry)
示例2: add_user
def add_user(topology):
"""Create a user entry"""
log.info("Create a user entry: %s" % TEST_USER)
uentry = Entry(TEST_USER)
uentry.setValues("objectclass", "top", "extensibleobject")
uentry.setValues("uid", "test")
topology.instance.add_s(uentry)
示例3: user
def user(topology):
"""Create user entries"""
for i in range(0, 2):
uentry = Entry('uid=test%s,%s' % (i, DEFAULT_SUFFIX))
uentry.setValues('objectclass', 'top', 'extensibleobject')
uentry.setValues('uid', 'test')
topology.standalone.add_s(uentry)
示例4: bak2db
def bak2db(self, bename=None, backup_dir=None, args=None):
'''
Restore a backup by creating a bak2db task
@param bename - 'commonname'/'cn' of the backend (e.g. 'userRoot')
@param backup_dir - backup directory
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
# Checking the parameters
if not backup_dir:
raise ValueError("You must specify a backup directory")
if not os.path.exists(backup_dir):
raise ValueError("Backup file (%s) does not exist" % backup_dir)
# If a backend name was provided then verify it
if bename:
ents = self.conn.mappingtree.list(bename=bename)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % bename)
# build the task entry
cn = "restore_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_RESTORE_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsArchiveDir': backup_dir,
'nsDatabaseType': 'ldbm database'
})
if bename:
entry.update({'nsInstance': bename})
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the backup task (%s)" % dn)
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: restore task %s exited with %d" % (cn, exitCode))
else:
self.log.info("Restore task %s completed successfully" % (cn))
return exitCode
示例5: syntaxValidate
def syntaxValidate(self, suffix=DEFAULT_SUFFIX, fstr='objectclass=top', args=None):
'''
@param suffix - The suffix the task should validate - default is "dc=example,dc=com"
@param fstr - The search filter to find entries
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=syntax validate,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
entry.setValues('filter', fstr)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Syntax Validate task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Syntax Validate (%s) exited with %d" % (cn, exitCode))
else:
self.log.info("Syntax Validate task (%s) completed successfully" % (cn))
return exitCode
示例6: test_update
def test_update(self):
expected = 'pluto minnie'
given = {'cn': expected}
t = ('o=pippo', {
'o': ['pippo'],
'objectclass': ['organization', 'top']
})
e = Entry(t)
e.update(given)
assert e.cn == expected, "Bad cn: %s, expected: %s" % (e.cn, expected)
示例7: enable_ssl
def enable_ssl(self, secport=636, secargs=None):
"""Configure SSL support into cn=encryption,cn=config.
secargs is a dict like {
'nsSSLPersonalitySSL': 'Server-Cert'
}
"""
self._log.debug("config.enable_ssl is deprecated! Use RSA, Encryption instead!")
self._log.debug("configuring SSL with secargs:%r" % secargs)
secargs = secargs or {}
dn_enc = 'cn=encryption,cn=config'
ciphers = ('-rsa_null_md5,+rsa_rc4_128_md5,+rsa_rc4_40_md5,'
'+rsa_rc2_40_md5,+rsa_des_sha,+rsa_fips_des_sha,'
'+rsa_3des_sha,+rsa_fips_3des_sha,+tls_rsa_export1024'
'_with_rc4_56_sha,+tls_rsa_export1024_with_des_cbc_sha')
mod = [(ldap.MOD_REPLACE, 'nsSSL3', secargs.get('nsSSL3', 'on')),
(ldap.MOD_REPLACE, 'nsSSLClientAuth',
secargs.get('nsSSLClientAuth', 'allowed')),
(ldap.MOD_REPLACE, 'nsSSL3Ciphers', secargs.get('nsSSL3Ciphers',
ciphers))]
self._instance.modify_s(dn_enc, mod)
dn_rsa = 'cn=RSA,cn=encryption,cn=config'
e_rsa = Entry(dn_rsa)
e_rsa.update({
'objectclass': ['top', 'nsEncryptionModule'],
'nsSSLPersonalitySSL': secargs.get('nsSSLPersonalitySSL',
'Server-Cert'),
'nsSSLToken': secargs.get('nsSSLToken', 'internal (software)'),
'nsSSLActivation': secargs.get('nsSSLActivation', 'on')
})
try:
self._instance.add_s(e_rsa)
except ldap.ALREADY_EXISTS:
pass
mod = [
(ldap.MOD_REPLACE,
'nsslapd-security',
secargs.get('nsslapd-security', 'on')),
(ldap.MOD_REPLACE,
'nsslapd-ssl-check-hostname',
secargs.get('nsslapd-ssl-check-hostname', 'off')),
(ldap.MOD_REPLACE,
'nsslapd-secureport',
str(secport))
]
self._log.debug("trying to modify %r with %r" % (DN_CONFIG, mod))
self._instance.modify_s(DN_CONFIG, mod)
fields = 'nsslapd-security nsslapd-ssl-check-hostname'.split()
return self._instance.getEntry(DN_CONFIG, attrlist=fields)
示例8: fixupTombstones
def fixupTombstones(self, bename=None, args=None):
'''
Trigger a tombstone fixup task on the specified backend
@param bename - 'commonname'/'cn' of the backend (e.g. 'userRoot').
Optional.
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
if not bename:
bename = DEFAULT_BENAME
# Verify the backend name
if bename:
ents = self.conn.mappingtree.list(bename=bename)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % bename)
cn = "fixupTombstone_" + time.strftime("%m%d%Y_%H%M%S",
time.localtime())
dn = "cn=%s,%s" % (cn, DN_TOMB_FIXUP_TASK)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('backend', bename)
if args and args.get(TASK_TOMB_STRIP, False):
entry.setValues('stripcsn', 'yes')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the fixup tombstone task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: tombstone fixup task %s for backend %s exited with %d"
% (cn, bename, exitCode))
else:
self.log.info(
"tombstone fixup task %s for backend %s completed successfully"
% (cn, bename))
self.dn = dn
self.entry = entry
return exitCode
示例9: db2bak
def db2bak(self, backup_dir=None, args=None):
'''
Perform a backup by creating a db2bak task
@param backup_dir - backup directory
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
# Checking the parameters
if not backup_dir:
raise ValueError("You must specify a backup directory.")
# build the task entry
cn = "backup_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_BACKUP_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsArchiveDir': backup_dir,
'nsDatabaseType': 'ldbm database'
})
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the backup task (%s)" % dn)
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: backup task %s exited with %d" %
(cn, exitCode))
else:
self.log.info("Backup task %s completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
示例10: add_user
def add_user(topology):
"""
Create a user entry
"""
log.info('Create a user entry: %s' % TEST_USER)
uentry = Entry(TEST_USER)
uentry.setValues('objectclass', 'top', 'extensibleobject')
uentry.setValues('uid', 'test')
topology.instance.add_s(uentry)
# This doesn't matter that we re-open the realm
krb = MitKrb5(realm=REALM)
krb.create_principal("test")
# We extract the kt so we can kinit from it
krb.create_keytab("test", "/tmp/test.keytab")
示例11: fixupLinkedAttrs
def fixupLinkedAttrs(self, linkdn=None, args=None):
'''
@param linkdn - The DN of linked attr config entry (if None all possible configurations are checked)
@param args - Is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=fixup linked attributes,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
if linkdn:
entry.setValues('linkdn', linkdn)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Fixup Linked Attributes task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Fixup Linked Attributes task (%s) exited with %d" % (cn, exitCode))
else:
self.log.info("Fixup Linked Attributes task (%s) completed successfully" % (cn))
return exitCode
示例12: schemaReload
def schemaReload(self, schemadir=None, args=None):
'''
@param schemadir - The directory to look for schema files(optional)
@param args - Is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=schema reload task,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
if schemadir:
entry.setValues('schemadir', schemadir)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Schema Reload task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Schema Reload task (%s) exited with %d" % (cn, exitCode))
else:
self.log.info("Schema Reload task (%s) completed successfully" % (cn))
return exitCode
示例13: automemberMap
def automemberMap(self, ldif_in=None, ldif_out=None, args=None):
'''
@param ldif_in - Entries to pass into the task for processing
@param ldif_out - The resulting LDIF of changes from ldif_in
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion
of the task before to return
@return exit code
@raise ValueError: if ldif_out/ldif_in is not provided
'''
if not ldif_out or not ldif_in:
raise ValueError("Missing ldif_out and/or ldif_in")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=automember map updates,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('ldif_in', ldif_in)
entry.setValues('ldif_out', ldif_out)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Automember Map Updates task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Automember Map Updates task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"Automember Map Updates task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
示例14: group
def group(topology):
"""Create a group entry"""
gentry = Entry('cn=testgroup,%s' % DEFAULT_SUFFIX)
gentry.setValues('objectclass', 'top', 'extensibleobject')
gentry.setValues('cn', 'testgroup')
for i in range(0, 2):
gentry.setValues('uniqueMember', 'uid=test%s,%s' % (i, DEFAULT_SUFFIX))
topology.standalone.add_s(gentry)
示例15: sysconfigReload
def sysconfigReload(self, configfile=None, logchanges=None, args=None):
'''
@param configfile - The sysconfig file:
/etc/sysconfig/dirsrv-localhost
@param logchanges - True/False - Tell the server to log the changes
made by the task
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: If sysconfig file not provided
'''
if not configfile:
raise ValueError("Missing required paramter: configfile")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=cn=sysconfig reload,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('sysconfigfile', configfile)
if logchanges:
entry.setValues('logchanges', logchanges)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Sysconfig Reload task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Sysconfig Reload task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("Sysconfig Reload task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode