Check for duplicate winsync agreement before trying to set one up.

We currently only support a single winsync agreement so all we need
to do is check to see if we have one with the remote host.

This also adds some minor exception handling cleanup.

https://fedorahosted.org/freeipa/ticket/2130
This commit is contained in:
Rob Crittenden
2012-02-08 14:47:43 -05:00
committed by Martin Kosek
parent 31f00f90f1
commit 5c7cd8ee2f

View File

@@ -199,10 +199,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
print "Please use the 'del' command to remove it from the domain"
return
except ldap.NO_SUCH_OBJECT:
print "'%s' has no replication agreement for '%s'" % (replica1, replica2)
return
except errors.NotFound:
except (ldap.NO_SUCH_OBJECT, errors.NotFound):
print "'%s' has no replication agreement for '%s'" % (replica1, replica2)
return
except Exception, e:
@@ -219,11 +216,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
print "Please use the 'del' command to remove it from the domain"
return
except ldap.NO_SUCH_OBJECT:
print "'%s' has no replication agreement for '%s'" % (replica2, replica1)
if not force:
return
except errors.NotFound:
except (ldap.NO_SUCH_OBJECT, errors.NotFound):
print "'%s' has no replication agreement for '%s'" % (replica2, replica1)
if not force:
return
@@ -357,6 +350,18 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
root_logger.error("winsync agreements need to be created as root")
sys.exit(1)
# See if we already have an agreement with this host
try:
repl = replication.ReplicationManager(realm, replica1, dirman_passwd)
if repl.get_agreement_type(replica2) == replication.WINSYNC:
agreement = repl.get_replication_agreement(replica2)
sys.exit("winsync agreement already exists on subtree %s" %
agreement.getValue('nsds7WindowsReplicaSubtree'))
else:
sys.exit("A replication agreement to %s already exists" % replica2)
except errors.NotFound:
pass
if options.cacert:
# have to install the given CA cert before doing anything else
ds = dsinstance.DsInstance(realm_name = realm,
@@ -372,10 +377,7 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
try:
repl1 = replication.ReplicationManager(realm, replica1, dirman_passwd)
except ldap.NO_SUCH_OBJECT:
print "Cannot find replica '%s'" % replica1
return
except errors.NotFound:
except (ldap.NO_SUCH_OBJECT, errors.NotFound):
print "Cannot find replica '%s'" % replica1
return
except Exception, e: