mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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
This commit is contained in:
@@ -24,13 +24,15 @@ import traceback, logging
|
|||||||
|
|
||||||
from ipapython import ipautil
|
from ipapython import ipautil
|
||||||
from ipaserver.install import replication, dsinstance, installutils
|
from ipaserver.install import replication, dsinstance, installutils
|
||||||
from ipaserver.plugins.ldap2 import ldap2
|
from ipaserver import ipaldap
|
||||||
from ipapython import version
|
from ipapython import version
|
||||||
from ipalib import errors, util
|
from ipalib import errors, util
|
||||||
|
|
||||||
|
CACERT = "/etc/ipa/ca.crt"
|
||||||
|
|
||||||
# dict of command name and tuples of min/max num of args needed
|
# dict of command name and tuples of min/max num of args needed
|
||||||
commands = {
|
commands = {
|
||||||
"list":(0, 0, "", ""),
|
"list":(0, 1, "[master fqdn]", ""),
|
||||||
"connect":(1, 2, "<master fqdn> [other master fqdn]",
|
"connect":(1, 2, "<master fqdn> [other master fqdn]",
|
||||||
"must provide the name of the servers to connect"),
|
"must provide the name of the servers to connect"),
|
||||||
"disconnect":(1, 2, "<master fqdn> [other master fqdn]",
|
"disconnect":(1, 2, "<master fqdn> [other master fqdn]",
|
||||||
@@ -106,9 +108,8 @@ def get_realm_name():
|
|||||||
return c.default_realm
|
return c.default_realm
|
||||||
|
|
||||||
def get_suffix():
|
def get_suffix():
|
||||||
l = ldap2(shared_instance=False, base_dn='')
|
suffix = util.realm_to_suffix(get_realm_name())
|
||||||
suffix = l.normalize_dn(util.realm_to_suffix(get_realm_name()))
|
return ipaldap.IPAdmin.normalizeDN(suffix)
|
||||||
return suffix
|
|
||||||
|
|
||||||
def test_connection(host):
|
def test_connection(host):
|
||||||
"""
|
"""
|
||||||
@@ -120,24 +121,49 @@ def test_connection(host):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
replman = replication.ReplicationManager(host, None)
|
replman = replication.ReplicationManager(host, None)
|
||||||
dns = replman.find_replication_dns(replman.conn)
|
ents = replman.find_replication_agreements()
|
||||||
del replman
|
del replman
|
||||||
return True
|
return True
|
||||||
except ldap.LOCAL_ERROR:
|
except ldap.LOCAL_ERROR:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def list_masters(replman, verbose):
|
def list_masters(host, replica, dirman_passwd, verbose):
|
||||||
dns = replman.find_replication_dns(replman.conn)
|
|
||||||
|
|
||||||
for dn in dns:
|
if replica:
|
||||||
entry = replman.conn.search_s(dn, ldap.SCOPE_SUBTREE)[0]
|
try:
|
||||||
print entry.getValue('nsds5replicahost')
|
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
|
||||||
|
|
||||||
if verbose:
|
entries = repl.find_replication_agreements()
|
||||||
print " last init status: %s" % entry.nsds5replicalastinitstatus
|
|
||||||
print " last init ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastinitend))
|
for entry in entries:
|
||||||
print " last update status: %s" % entry.nsds5replicalastupdatestatus
|
print entry.nsds5replicahost
|
||||||
print " last update ended: %s" % str(ipautil.parse_generalized_time(entry.nsds5replicalastupdateend))
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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):
|
def del_link(replica1, replica2, dirman_passwd, force=False):
|
||||||
|
|
||||||
@@ -354,7 +380,10 @@ def main():
|
|||||||
r.suffix = get_suffix()
|
r.suffix = get_suffix()
|
||||||
|
|
||||||
if args[0] == "list":
|
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":
|
elif args[0] == "del":
|
||||||
del_master(r, args[1], options.force)
|
del_master(r, args[1], options.force)
|
||||||
elif args[0] == "init":
|
elif args[0] == "init":
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class GeneralizedTimeZone(datetime.tzinfo):
|
|||||||
if self.houroffset < 0:
|
if self.houroffset < 0:
|
||||||
self.minoffset *= -1
|
self.minoffset *= -1
|
||||||
|
|
||||||
def utcoffset(self):
|
def utcoffset(self, dt):
|
||||||
return datetime.timedelta(hours=self.houroffset, minutes=self.minoffset)
|
return datetime.timedelta(hours=self.houroffset, minutes=self.minoffset)
|
||||||
|
|
||||||
def dst(self):
|
def dst(self):
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class ReplicationManager:
|
|||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
def find_replication_dns(self, conn):
|
def find_replication_agreements(self):
|
||||||
"""
|
"""
|
||||||
The replication agreements are stored in
|
The replication agreements are stored in
|
||||||
cn="$SUFFIX",cn=mapping tree,cn=config
|
cn="$SUFFIX",cn=mapping tree,cn=config
|
||||||
@@ -130,10 +130,10 @@ class ReplicationManager:
|
|||||||
"""
|
"""
|
||||||
filt = "(|(objectclass=nsDSWindowsReplicationAgreement)(objectclass=nsds5ReplicationAgreement))"
|
filt = "(|(objectclass=nsDSWindowsReplicationAgreement)(objectclass=nsds5ReplicationAgreement))"
|
||||||
try:
|
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:
|
except ldap.NO_SUCH_OBJECT:
|
||||||
return []
|
ents = []
|
||||||
return [ent.dn for ent in ents]
|
return ents
|
||||||
|
|
||||||
def find_ipa_replication_agreements(self):
|
def find_ipa_replication_agreements(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user