summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2010-12-15 14:55:30 -0500
committerSimo Sorce <ssorce@redhat.com>2010-12-21 17:28:13 -0500
commitefd8b03ccfc5ba25c383eacafa948aa0aa5feddf (patch)
tree2922b7d3369b01aef11d7cebf187b335fcf374a2
parent6bbd4eed9f4b1dcb3cb2fdc136575671832fca5f (diff)
downloadfreeipa-efd8b03ccfc5ba25c383eacafa948aa0aa5feddf.tar.gz
freeipa-efd8b03ccfc5ba25c383eacafa948aa0aa5feddf.tar.xz
freeipa-efd8b03ccfc5ba25c383eacafa948aa0aa5feddf.zip
Make ipa-replica-manage list return all known masters
if ipa-replica-manage list is given a master name as argument then the tool has the old behavior of listing that specific master replication agreements Fixes: https://fedorahosted.org/freeipa/ticket/625
-rwxr-xr-xinstall/tools/ipa-replica-manage63
-rw-r--r--ipapython/ipautil.py2
-rw-r--r--ipaserver/install/replication.py8
3 files changed, 51 insertions, 22 deletions
diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage
index 1007462a8..6f857e9d4 100755
--- a/install/tools/ipa-replica-manage
+++ b/install/tools/ipa-replica-manage
@@ -24,13 +24,15 @@ import traceback, logging
from ipapython import ipautil
from ipaserver.install import replication, dsinstance, installutils
-from ipaserver.plugins.ldap2 import ldap2
+from ipaserver import ipaldap
from ipapython import version
from ipalib import errors, util
+CACERT = "/etc/ipa/ca.crt"
+
# dict of command name and tuples of min/max num of args needed
commands = {
- "list":(0, 0, "", ""),
+ "list":(0, 1, "[master fqdn]", ""),
"connect":(1, 2, "<master fqdn> [other master fqdn]",
"must provide the name of the servers to connect"),
"disconnect":(1, 2, "<master fqdn> [other master fqdn]",
@@ -106,9 +108,8 @@ def get_realm_name():
return c.default_realm
def get_suffix():
- l = ldap2(shared_instance=False, base_dn='')
- suffix = l.normalize_dn(util.realm_to_suffix(get_realm_name()))
- return suffix
+ suffix = util.realm_to_suffix(get_realm_name())
+ return ipaldap.IPAdmin.normalizeDN(suffix)
def test_connection(host):
"""
@@ -120,24 +121,49 @@ def test_connection(host):
"""
try:
replman = replication.ReplicationManager(host, None)
- dns = replman.find_replication_dns(replman.conn)
+ ents = replman.find_replication_agreements()
del replman
return True
except ldap.LOCAL_ERROR:
return False
-def list_masters(replman, verbose):
- dns = replman.find_replication_dns(replman.conn)
+def list_masters(host, replica, dirman_passwd, verbose):
+
+ if replica:
+ try:
+ repl = replication.ReplicationManager(replica, dirman_passwd)
+ repl.suffix = get_suffix()
+ except Exception, e:
+ print "Failed to get data from '%s': %s" % (replica, str(e))
+ return
+
+ entries = repl.find_replication_agreements()
+
+ for entry in entries:
+ print entry.nsds5replicahost
- for dn in dns:
- entry = replman.conn.search_s(dn, ldap.SCOPE_SUBTREE)[0]
- print entry.getValue('nsds5replicahost')
+ if verbose:
+ print " last init status: %s" % entry.nsds5replicalastinitstatus
+ print " last init ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastinitend))
+ print " last update status: %s" % entry.nsds5replicalastupdatestatus
+ print " last update ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastupdateend))
+ else:
+ try:
+ conn = ipaldap.IPAdmin(host, 636, cacert=CACERT)
+ if dirman_passwd:
+ conn.do_simple_bind(bindpw=dirman_passwd)
+ else:
+ conn.sasl_interactive_bind_s('', ipaldap.sasl_auth)
+
+ dn = 'cn=masters,cn=ipa,cn=etc,%s' % get_suffix()
+ entries = conn.search_s(dn, ldap.SCOPE_ONELEVEL)
- if verbose:
- print " last init status: %s" % entry.nsds5replicalastinitstatus
- print " last init ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastinitend))
- print " last update status: %s" % entry.nsds5replicalastupdatestatus
- print " last update ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastupdateend))
+ for ent in entries:
+ print ent.cn
+
+ except Exception, e:
+ print "Failed to get data from '%s': %s" % (host, str(e))
+ return
def del_link(replica1, replica2, dirman_passwd, force=False):
@@ -354,7 +380,10 @@ def main():
r.suffix = get_suffix()
if args[0] == "list":
- list_masters(r, options.verbose)
+ replica = None
+ if len(args) == 2:
+ replica = args[1]
+ list_masters(host, replica, dirman_passwd, options.verbose)
elif args[0] == "del":
del_master(r, args[1], options.force)
elif args[0] == "init":
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 06495f4ee..77c838e80 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -346,7 +346,7 @@ class GeneralizedTimeZone(datetime.tzinfo):
if self.houroffset < 0:
self.minoffset *= -1
- def utcoffset(self):
+ def utcoffset(self, dt):
return datetime.timedelta(hours=self.houroffset, minutes=self.minoffset)
def dst(self):
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index 000529f47..5474efdb8 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -117,7 +117,7 @@ class ReplicationManager:
return retval
- def find_replication_dns(self, conn):
+ def find_replication_agreements(self):
"""
The replication agreements are stored in
cn="$SUFFIX",cn=mapping tree,cn=config
@@ -130,10 +130,10 @@ class ReplicationManager:
"""
filt = "(|(objectclass=nsDSWindowsReplicationAgreement)(objectclass=nsds5ReplicationAgreement))"
try:
- ents = conn.search_s("cn=mapping tree,cn=config", ldap.SCOPE_SUBTREE, filt)
+ ents = self.conn.search_s("cn=mapping tree,cn=config", ldap.SCOPE_SUBTREE, filt)
except ldap.NO_SUCH_OBJECT:
- return []
- return [ent.dn for ent in ents]
+ ents = []
+ return ents
def find_ipa_replication_agreements(self):
"""