From 2255479ef0e69bc966f9027f21faf7b14635227c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 10 Jan 2011 10:57:43 -0500 Subject: Refactor some replication code This simplifies or rationalizes some code in order to make it easier to change it to fix bug #690 --- install/tools/ipa-replica-manage | 107 ++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 64 deletions(-) (limited to 'install/tools') diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage index da2c9d4a..9d8f1510 100755 --- a/install/tools/ipa-replica-manage +++ b/install/tools/ipa-replica-manage @@ -54,18 +54,19 @@ def parse_options(): parser.add_option("-f", "--force", dest="force", action="store_true", default=False, help="ignore some types of errors") parser.add_option("--port", type="int", dest="port", + default=replication.PORT, help="port number of other server") - parser.add_option("--binddn", dest="binddn", + parser.add_option("--binddn", dest="binddn", default=None, help="Bind DN to use with remote server") - parser.add_option("--bindpw", dest="bindpw", + parser.add_option("--bindpw", dest="bindpw", default=None, help="Password for Bind DN to use with remote server") parser.add_option("--winsync", dest="winsync", action="store_true", default=False, help="This is a Windows Sync Agreement") - parser.add_option("--cacert", dest="cacert", + parser.add_option("--cacert", dest="cacert", default=None, help="Full path and filename of CA certificate to use with TLS/SSL to the remote server") - parser.add_option("--win-subtree", dest="win_subtree", + parser.add_option("--win-subtree", dest="win_subtree", default=None, help="DN of Windows subtree containing the users you want to sync (default cn=Users," sys.exit(1) - repl = replication.ReplicationManager(options.fromhost, options.dirman_passwd) - repl.suffix = get_suffix() + repl = replication.ReplicationManager(realm, options.fromhost, options.dirman_passwd) thishost = installutils.get_fqdn() @@ -360,13 +339,12 @@ def re_initialize(options): repl.initialize_replication(entry[0].dn, repl.conn) repl.wait_for_repl_init(repl.conn, entry[0].dn) - ds = dsinstance.DsInstance(realm_name = get_realm_name(), dm_password = options.dirman_passwd) + ds = dsinstance.DsInstance(realm_name = realm, dm_password = options.dirman_passwd) ds.init_memberof() -def force_sync(thishost, fromhost, dirman_passwd): +def force_sync(realm, thishost, fromhost, dirman_passwd): - repl = replication.ReplicationManager(fromhost, dirman_passwd) - repl.suffix = get_suffix() + repl = replication.ReplicationManager(realm, fromhost, dirman_passwd) filter = "(&(nsDS5ReplicaHost=%s)(|(objectclass=nsDSWindowsReplicationAgreement)(objectclass=nsds5ReplicationAgreement)))" % thishost entry = repl.conn.search_s("cn=config", ldap.SCOPE_SUBTREE, filter) @@ -381,6 +359,7 @@ def main(): options, args = parse_options() dirman_passwd = None + realm = krbV.default_context().default_realm if options.host: host = options.host @@ -392,7 +371,7 @@ def main(): if options.dirman_passwd: dirman_passwd = options.dirman_passwd else: - if not test_connection(host) or args[0] == "connect": + if not test_connection(realm, host) or args[0] == "connect": dirman_passwd = getpass.getpass("Directory Manager password: ") options.dirman_passwd = dirman_passwd @@ -401,16 +380,16 @@ def main(): replica = None if len(args) == 2: replica = args[1] - list_masters(host, replica, dirman_passwd, options.verbose) + list_masters(realm, host, replica, dirman_passwd, options.verbose) elif args[0] == "del": - del_master(args[1], options) + del_master(realm, args[1], options) elif args[0] == "re-initialize": - re_initialize(options) + re_initialize(realm, options) elif args[0] == "force-sync": if not options.fromhost: print "force-sync requires the option --from " sys.exit(1) - force_sync(host, options.fromhost, options.dirman_passwd) + force_sync(realm, host, options.fromhost, options.dirman_passwd) elif args[0] == "connect": if len(args) == 3: replica1 = args[1] @@ -418,7 +397,7 @@ def main(): elif len(args) == 2: replica1 = host replica2 = args[1] - add_link(replica1, replica2, dirman_passwd, options) + add_link(realm, replica1, replica2, dirman_passwd, options) elif args[0] == "disconnect": if len(args) == 3: replica1 = args[1] @@ -426,7 +405,7 @@ def main(): elif len(args) == 2: replica1 = host replica2 = args[1] - del_link(replica1, replica2, dirman_passwd) + del_link(realm, replica1, replica2, dirman_passwd) try: main() -- cgit