2013-11-27 07:53:57 -06:00
|
|
|
#! /usr/bin/python2 -E
|
2011-07-14 22:35:01 -05:00
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
#
|
|
|
|
# Based on ipa-replica-manage by Karl MacMillan <kmacmillan@mentalrootkit.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2015-08-12 06:44:11 -05:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipapython.ipa_log_manager import root_logger
|
2014-04-10 07:14:10 -05:00
|
|
|
from ipaserver.install import (replication, installutils, bindinstance,
|
|
|
|
cainstance, certs)
|
2015-07-20 09:04:07 -05:00
|
|
|
from ipalib import api, errors
|
2013-09-11 03:27:34 -05:00
|
|
|
from ipalib.constants import CACERT
|
2015-10-30 07:06:21 -05:00
|
|
|
from ipalib.util import has_managed_topology
|
2015-12-16 09:06:03 -06:00
|
|
|
from ipapython import ipautil, ipaldap, version
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
from ipapython.dn import DN
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
# dict of command name and tuples of min/max num of args needed
|
|
|
|
commands = {
|
2014-07-23 12:03:46 -05:00
|
|
|
"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]",
|
|
|
|
"must provide the name of the server to disconnect"),
|
|
|
|
"del": (1, 1, "<master fqdn>",
|
|
|
|
"must provide hostname of master to delete"),
|
|
|
|
"re-initialize": (0, 0, "", ""),
|
|
|
|
"force-sync": (0, 0, "", ""),
|
|
|
|
"set-renewal-master": (0, 1, "[master fqdn]", "")
|
2011-07-14 22:35:01 -05:00
|
|
|
}
|
|
|
|
|
2012-11-20 06:47:00 -06:00
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
def parse_options():
|
2016-11-23 03:04:43 -06:00
|
|
|
from optparse import OptionParser # pylint: disable=deprecated-module
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
parser = OptionParser(version=version.VERSION)
|
|
|
|
parser.add_option("-H", "--host", dest="host", help="starting host")
|
|
|
|
parser.add_option("-p", "--password", dest="dirman_passwd", help="Directory Manager password")
|
|
|
|
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
|
|
|
|
help="provide additional information")
|
|
|
|
parser.add_option("-f", "--force", dest="force", action="store_true", default=False,
|
|
|
|
help="ignore some types of errors")
|
|
|
|
parser.add_option("--from", dest="fromhost", help="Host to get data from")
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
valid_syntax = False
|
|
|
|
|
|
|
|
if len(args):
|
|
|
|
n = len(args) - 1
|
|
|
|
k = commands.keys()
|
|
|
|
for cmd in k:
|
|
|
|
if cmd == args[0]:
|
|
|
|
v = commands[cmd]
|
|
|
|
err = None
|
|
|
|
if n < v[0]:
|
|
|
|
err = v[3]
|
|
|
|
elif n > v[1]:
|
|
|
|
err = "too many arguments"
|
|
|
|
else:
|
|
|
|
valid_syntax = True
|
|
|
|
if err:
|
|
|
|
parser.error("Invalid syntax: %s\nUsage: %s [options] %s" % (err, cmd, v[2]))
|
|
|
|
|
|
|
|
if not valid_syntax:
|
|
|
|
cmdstr = " | ".join(commands.keys())
|
|
|
|
parser.error("must provide a command [%s]" % cmdstr)
|
|
|
|
|
|
|
|
return options, args
|
|
|
|
|
|
|
|
def list_replicas(realm, host, replica, dirman_passwd, verbose):
|
|
|
|
|
|
|
|
peers = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
# connect to main IPA LDAP server
|
2016-11-01 08:52:33 -05:00
|
|
|
ldap_uri = ipaldap.get_ldap_uri(host, 636, cacert=CACERT)
|
|
|
|
conn = ipaldap.LDAPClient(ldap_uri, cacert=CACERT)
|
2016-10-05 10:42:32 -05:00
|
|
|
conn.simple_bind(bind_dn=ipaldap.DIRMAN_DN,
|
|
|
|
bind_password=dirman_passwd)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), ipautil.realm_to_suffix(realm))
|
2013-01-30 08:51:08 -06:00
|
|
|
entries = conn.get_entries(dn, conn.SCOPE_ONELEVEL)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
for ent in entries:
|
|
|
|
try:
|
|
|
|
cadn = DN(('cn', 'CA'), DN(ent.dn))
|
2013-01-23 09:05:21 -06:00
|
|
|
entry = conn.get_entry(cadn)
|
2013-09-10 05:20:24 -05:00
|
|
|
peers[ent.single_value['cn']] = ['master', '']
|
2011-07-14 22:35:01 -05:00
|
|
|
except errors.NotFound:
|
2013-09-10 05:20:24 -05:00
|
|
|
peers[ent.single_value['cn']] = ['CA not configured', '']
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit(
|
|
|
|
"Failed to get data from '%s' while trying to list replicas: %s" %
|
|
|
|
(host, e))
|
2011-07-14 22:35:01 -05:00
|
|
|
finally:
|
2013-01-30 05:46:48 -06:00
|
|
|
conn.unbind()
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
if not replica:
|
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-08-11 06:51:14 -05:00
|
|
|
for k, p in peers.items():
|
2015-08-12 06:44:11 -05:00
|
|
|
print('%s: %s' % (k, p[0]))
|
2011-07-14 22:35:01 -05:00
|
|
|
return
|
|
|
|
|
2013-03-13 08:36:41 -05:00
|
|
|
try:
|
|
|
|
repl = replication.get_cs_replication_manager(realm, replica, dirman_passwd)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-03-13 08:36:41 -05:00
|
|
|
sys.exit(str(e))
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
entries = repl.find_replication_agreements()
|
|
|
|
|
|
|
|
for entry in entries:
|
2015-08-12 06:44:11 -05:00
|
|
|
print('%s' % entry.single_value.get('nsds5replicahost'))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
if verbose:
|
2015-08-12 06:44:11 -05:00
|
|
|
print(" last init status: %s" % entry.single_value.get(
|
|
|
|
'nsds5replicalastinitstatus'))
|
|
|
|
print(" last init ended: %s" % str(
|
2013-01-21 06:40:42 -06:00
|
|
|
ipautil.parse_generalized_time(
|
2015-08-12 06:44:11 -05:00
|
|
|
entry.single_value['nsds5replicalastinitend'])))
|
|
|
|
print(" last update status: %s" % entry.single_value.get(
|
|
|
|
'nsds5replicalastupdatestatus'))
|
|
|
|
print(" last update ended: %s" % str(
|
2013-01-21 06:40:42 -06:00
|
|
|
ipautil.parse_generalized_time(
|
2015-08-12 06:44:11 -05:00
|
|
|
entry.single_value['nsds5replicalastupdateend'])))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
def del_link(realm, replica1, replica2, dirman_passwd, force=False):
|
|
|
|
|
|
|
|
repl2 = None
|
|
|
|
|
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
repl1 = replication.get_cs_replication_manager(realm, replica1, dirman_passwd)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
repl1.hostnames = [replica1, replica2]
|
|
|
|
|
2012-08-30 15:24:10 -05:00
|
|
|
repl_list1 = repl1.find_replication_agreements()
|
|
|
|
|
|
|
|
# Find the DN of the replication agreement to remove
|
|
|
|
replica1_dn = None
|
|
|
|
for e in repl_list1:
|
2013-09-10 05:20:24 -05:00
|
|
|
if e.single_value.get('nsDS5ReplicaHost') == replica2:
|
2012-08-30 15:24:10 -05:00
|
|
|
replica1_dn = e.dn
|
|
|
|
break
|
|
|
|
|
|
|
|
if replica1_dn is None:
|
|
|
|
sys.exit("'%s' has no replication agreement for '%s'" % (replica1, replica2))
|
|
|
|
|
|
|
|
repl1.hostnames = [replica1, replica2]
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2015-07-30 09:49:29 -05:00
|
|
|
except errors.NetworkError as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("Unable to connect to %s: %s" % (replica1, e))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("Failed to get data from '%s': %s" % (replica1, e))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
repl2 = replication.get_cs_replication_manager(realm, replica2, dirman_passwd)
|
2012-11-20 06:47:00 -06:00
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
repl2.hostnames = [replica1, replica2]
|
|
|
|
|
2012-08-30 15:24:10 -05:00
|
|
|
repl_list = repl2.find_replication_agreements()
|
|
|
|
|
|
|
|
# Now that we've confirmed that both hostnames are vaild, make sure
|
|
|
|
# that we aren't removing the last link from either side.
|
2011-07-14 22:35:01 -05:00
|
|
|
if not force and len(repl_list) <= 1:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Cannot remove the last replication link of '%s'" % replica2)
|
|
|
|
print("Please use the 'del' command to remove it from the domain")
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-08-30 15:24:10 -05:00
|
|
|
if not force and len(repl_list1) <= 1:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Cannot remove the last replication link of '%s'" % replica1)
|
|
|
|
print("Please use the 'del' command to remove it from the domain")
|
2012-08-30 15:24:10 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Find the DN of the replication agreement to remove
|
|
|
|
replica2_dn = None
|
2016-06-03 04:09:00 -05:00
|
|
|
for entry in repl_list:
|
|
|
|
if entry.single_value.get('nsDS5ReplicaHost') == replica1:
|
|
|
|
replica2_dn = entry.dn
|
2012-08-30 15:24:10 -05:00
|
|
|
break
|
|
|
|
|
|
|
|
# This should never happen
|
|
|
|
if replica2_dn is None:
|
|
|
|
sys.exit("'%s' has no replication agreement for '%s'" % (replica1, replica2))
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
except errors.NotFound:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("'%s' has no replication agreement for '%s'" % (replica2, replica1))
|
2011-07-14 22:35:01 -05:00
|
|
|
if not force:
|
|
|
|
return
|
2016-06-03 04:09:00 -05:00
|
|
|
except Exception as exc:
|
|
|
|
print("Failed to get data from '%s': %s" % (replica2, exc))
|
2011-07-14 22:35:01 -05:00
|
|
|
if not force:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if repl2:
|
|
|
|
failed = False
|
|
|
|
try:
|
2012-08-30 15:24:10 -05:00
|
|
|
repl2.delete_agreement(replica1, replica2_dn)
|
2012-11-20 06:47:00 -06:00
|
|
|
repl2.delete_referral(replica1, repl1.port)
|
2016-06-03 04:09:00 -05:00
|
|
|
except Exception as exc:
|
|
|
|
print("Unable to remove agreement on %s: %s" % (replica2, exc))
|
2011-07-14 22:35:01 -05:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
if failed:
|
|
|
|
if force:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Forcing removal on '%s'" % replica1)
|
2011-07-14 22:35:01 -05:00
|
|
|
else:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not repl2 and force:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Forcing removal on '%s'" % replica1)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2012-08-30 15:24:10 -05:00
|
|
|
repl1.delete_agreement(replica2, replica1_dn)
|
2012-11-20 06:47:00 -06:00
|
|
|
repl1.delete_referral(replica2, repl2.port)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Deleted replication agreement from '%s' to '%s'" % (replica1, replica2))
|
2012-01-16 09:24:15 -06:00
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
def del_master(realm, hostname, options):
|
|
|
|
delrepl = None
|
2012-01-16 09:24:15 -06:00
|
|
|
|
|
|
|
# 1. Connect to the local dogtag DS server
|
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
thisrepl = replication.get_cs_replication_manager(realm, options.host,
|
|
|
|
options.dirman_passwd)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("Failed to connect to server %s: %s" % (options.host, e))
|
2012-01-16 09:24:15 -06:00
|
|
|
|
|
|
|
# 2. Ensure we have an agreement with the master
|
|
|
|
if thisrepl.get_replication_agreement(hostname) is None:
|
|
|
|
sys.exit("'%s' has no replication agreement for '%s'" % (options.host, hostname))
|
|
|
|
|
|
|
|
# 3. Connect to the dogtag DS to be removed.
|
2011-07-14 22:35:01 -05:00
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
delrepl = replication.get_cs_replication_manager(realm, hostname,
|
|
|
|
options.dirman_passwd)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-07-14 22:35:01 -05:00
|
|
|
if not options.force:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Unable to delete replica %s: %s" % (hostname, e))
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Unable to connect to replica %s, forcing removal" % hostname)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2012-01-16 09:24:15 -06:00
|
|
|
# 4. Get list of agreements.
|
2011-07-14 22:35:01 -05:00
|
|
|
if delrepl is None:
|
|
|
|
# server not up, just remove it from this server
|
|
|
|
replica_names = [options.host]
|
|
|
|
else:
|
2013-04-08 07:09:16 -05:00
|
|
|
replica_entries = delrepl.find_ipa_replication_agreements()
|
2013-09-10 05:20:24 -05:00
|
|
|
replica_names = [rep.single_value.get('nsds5replicahost')
|
2013-04-08 07:09:16 -05:00
|
|
|
for rep in replica_entries]
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2012-01-16 09:24:15 -06:00
|
|
|
# 5. Remove each agreement
|
2011-07-14 22:35:01 -05:00
|
|
|
for r in replica_names:
|
|
|
|
try:
|
|
|
|
del_link(realm, r, hostname, options.dirman_passwd, force=True)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("There were issues removing a connection: %s" % e)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2014-04-10 07:14:10 -05:00
|
|
|
# 6. Pick CA renewal master
|
|
|
|
ca = cainstance.CAInstance(api.env.realm, certs.NSS_DIR)
|
|
|
|
if ca.is_renewal_master(hostname):
|
|
|
|
ca.set_renewal_master(options.host)
|
|
|
|
|
|
|
|
# 7. And clean up the removed replica DNS entries if any.
|
2013-04-15 05:19:35 -05:00
|
|
|
try:
|
2016-11-11 05:45:11 -06:00
|
|
|
if bindinstance.dns_container_exists(api.env.basedn):
|
2013-04-15 05:19:35 -05:00
|
|
|
bind = bindinstance.BindInstance()
|
2016-06-12 11:05:48 -05:00
|
|
|
bind.update_system_records()
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Failed to cleanup %s DNS entries: %s" % (hostname, e))
|
|
|
|
print("You may need to manually remove them from the tree")
|
2013-04-15 05:19:35 -05:00
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
def add_link(realm, replica1, replica2, dirman_passwd, options):
|
2013-03-13 08:36:41 -05:00
|
|
|
try:
|
|
|
|
repl2 = replication.get_cs_replication_manager(realm, replica2,
|
|
|
|
dirman_passwd)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-03-13 08:36:41 -05:00
|
|
|
sys.exit(str(e))
|
2011-07-14 22:35:01 -05:00
|
|
|
try:
|
2016-11-01 08:52:33 -05:00
|
|
|
ldap_uri = ipaldap.get_ldap_uri(replica2, 636, cacert=CACERT)
|
|
|
|
conn = ipaldap.LDAPClient(ldap_uri, cacert=CACERT)
|
2016-10-05 10:42:32 -05:00
|
|
|
conn.simple_bind(bind_dn=ipaldap.DIRMAN_DN,
|
|
|
|
bind_password=dirman_passwd)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
dn = DN(('cn', 'CA'), ('cn', replica2), ('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
|
|
|
ipautil.realm_to_suffix(realm))
|
2014-11-06 15:10:01 -06:00
|
|
|
conn.get_entries(dn, conn.SCOPE_BASE)
|
2013-01-30 05:46:48 -06:00
|
|
|
conn.unbind()
|
2013-01-28 11:02:48 -06:00
|
|
|
except errors.NotFound:
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit('%s does not have a CA configured.' % replica2)
|
2015-07-30 09:49:29 -05:00
|
|
|
except errors.NetworkError as e:
|
2013-01-28 11:02:48 -06:00
|
|
|
sys.exit("Unable to connect to %s: %s" % (ipautil.format_netloc(replica2, 636), str(e)))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-28 11:02:48 -06:00
|
|
|
sys.exit("Failed to get data while trying to bind to '%s': %s" % (replica1, str(e)))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
repl1 = replication.get_cs_replication_manager(realm, replica1,
|
|
|
|
dirman_passwd)
|
2011-07-14 22:35:01 -05:00
|
|
|
entries = repl1.find_replication_agreements()
|
|
|
|
for e in entries:
|
2013-09-10 05:20:24 -05:00
|
|
|
if e.single_value.get('nsDS5ReplicaHost') == replica2:
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit('This replication agreement already exists.')
|
|
|
|
repl1.hostnames = [replica1, replica2]
|
|
|
|
|
2013-01-30 08:51:08 -06:00
|
|
|
except errors.NotFound:
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit("Cannot find replica '%s'" % replica1)
|
2015-07-30 09:49:29 -05:00
|
|
|
except errors.NetworkError as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("Unable to connect to %s: %s" % (replica1, e))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit(
|
|
|
|
"Failed to get data from '%s' while trying to get current "
|
|
|
|
"agreements: %s" % (replica1, e))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2012-11-20 06:47:00 -06:00
|
|
|
repl1.setup_replication(
|
|
|
|
replica2, repl2.port, 0, DN(('cn', 'Directory Manager')),
|
|
|
|
dirman_passwd, is_cs_replica=True, local_port=repl1.port)
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Connected '%s' to '%s'" % (replica1, replica2))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
def re_initialize(realm, options):
|
|
|
|
|
|
|
|
if not options.fromhost:
|
|
|
|
sys.exit("re-initialize requires the option --from <host name>")
|
|
|
|
|
|
|
|
thishost = installutils.get_fqdn()
|
|
|
|
|
2013-03-13 08:36:41 -05:00
|
|
|
try:
|
|
|
|
repl = replication.get_cs_replication_manager(realm, options.fromhost,
|
|
|
|
options.dirman_passwd)
|
|
|
|
thisrepl = replication.get_cs_replication_manager(realm, thishost,
|
|
|
|
options.dirman_passwd)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-03-13 08:36:41 -05:00
|
|
|
sys.exit(str(e))
|
|
|
|
|
2012-11-16 06:59:11 -06:00
|
|
|
filter = repl.get_agreement_filter(host=thishost)
|
2013-01-28 11:02:48 -06:00
|
|
|
try:
|
|
|
|
entry = repl.conn.get_entries(
|
2013-01-30 08:51:08 -06:00
|
|
|
DN(('cn', 'config')), repl.conn.SCOPE_SUBTREE, filter)
|
2013-01-28 11:02:48 -06:00
|
|
|
except errors.NotFound:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.error("Unable to find %s -> %s replication agreement" % (options.fromhost, thishost))
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit(1)
|
|
|
|
if len(entry) > 1:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.error("Found multiple agreements for %s. Only initializing the first one returned: %s" % (thishost, entry[0].dn))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2013-03-13 08:36:41 -05:00
|
|
|
repl.hostnames = thisrepl.hostnames = [thishost, options.fromhost]
|
|
|
|
thisrepl.enable_agreement(options.fromhost)
|
|
|
|
repl.enable_agreement(thishost)
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
repl.initialize_replication(entry[0].dn, repl.conn)
|
|
|
|
repl.wait_for_repl_init(repl.conn, entry[0].dn)
|
|
|
|
|
|
|
|
def force_sync(realm, thishost, fromhost, dirman_passwd):
|
|
|
|
|
|
|
|
try:
|
2013-03-13 08:36:41 -05:00
|
|
|
repl = replication.get_cs_replication_manager(realm, fromhost,
|
|
|
|
dirman_passwd)
|
2011-07-14 22:35:01 -05:00
|
|
|
repl.force_sync(repl.conn, thishost)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-03-13 08:36:41 -05:00
|
|
|
sys.exit(str(e))
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2014-07-23 12:03:46 -05:00
|
|
|
def set_renewal_master(realm, replica):
|
|
|
|
if not replica:
|
|
|
|
replica = installutils.get_fqdn()
|
|
|
|
|
|
|
|
ca = cainstance.CAInstance(realm, certs.NSS_DIR)
|
|
|
|
if ca.is_renewal_master(replica):
|
|
|
|
sys.exit("%s is already the renewal master" % replica)
|
|
|
|
|
|
|
|
try:
|
|
|
|
ca.set_renewal_master(replica)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2014-07-23 12:03:46 -05:00
|
|
|
sys.exit("Failed to set renewal master to %s: %s" % (replica, e))
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
print("%s is now the renewal master" % replica)
|
2014-07-23 12:03:46 -05:00
|
|
|
|
2015-10-30 07:06:21 -05:00
|
|
|
|
|
|
|
def exit_on_managed_topology(what, hint="topologysegment"):
|
|
|
|
if hint == "topologysegment":
|
|
|
|
hinttext = ("Please use `ipa topologysegment-*` commands to manage "
|
|
|
|
"the topology.")
|
|
|
|
elif hint == "ipa-replica-manage-del":
|
|
|
|
hinttext = ("Please use the `ipa-replica-manage del` command.")
|
|
|
|
else:
|
|
|
|
assert False, "Unexpected value"
|
|
|
|
sys.exit("{0} is deprecated with managed IPA replication topology. {1}"
|
|
|
|
.format(what, hinttext))
|
|
|
|
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
def main():
|
|
|
|
options, args = parse_options()
|
|
|
|
|
|
|
|
# Just initialize the environment. This is so the installer can have
|
|
|
|
# access to the plugin environment
|
2011-11-15 13:39:31 -06:00
|
|
|
api_env = {'in_server' : True,
|
|
|
|
'verbose' : options.verbose,
|
|
|
|
}
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
if os.getegid() != 0:
|
|
|
|
api_env['log'] = None # turn off logging for non-root
|
|
|
|
|
|
|
|
api.bootstrap(**api_env)
|
|
|
|
api.finalize()
|
|
|
|
|
|
|
|
dirman_passwd = None
|
2015-07-20 09:04:07 -05:00
|
|
|
realm = api.env.realm
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
if options.host:
|
|
|
|
host = options.host
|
|
|
|
else:
|
|
|
|
host = installutils.get_fqdn()
|
|
|
|
|
|
|
|
options.host = host
|
|
|
|
|
|
|
|
if options.dirman_passwd:
|
|
|
|
dirman_passwd = options.dirman_passwd
|
|
|
|
else:
|
2011-10-06 01:22:08 -05:00
|
|
|
dirman_passwd = installutils.read_password("Directory Manager", confirm=False,
|
|
|
|
validate=False, retry=False)
|
|
|
|
if dirman_passwd is None:
|
2013-07-09 05:29:21 -05:00
|
|
|
sys.exit("Directory Manager password required")
|
2011-07-14 22:35:01 -05:00
|
|
|
|
|
|
|
options.dirman_passwd = dirman_passwd
|
|
|
|
|
2016-10-27 03:31:45 -05:00
|
|
|
api.Backend.ldap2.connect(bind_pw=options.dirman_passwd)
|
2015-10-30 07:06:21 -05:00
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
if args[0] == "list":
|
|
|
|
replica = None
|
|
|
|
if len(args) == 2:
|
|
|
|
replica = args[1]
|
|
|
|
list_replicas(realm, host, replica, dirman_passwd, options.verbose)
|
|
|
|
elif args[0] == "del":
|
2015-10-30 07:06:21 -05:00
|
|
|
if has_managed_topology(api):
|
|
|
|
exit_on_managed_topology(
|
|
|
|
"Removal of IPA CS replication agreement and replication data",
|
|
|
|
hint="ipa-replica-manage-del")
|
2011-07-14 22:35:01 -05:00
|
|
|
del_master(realm, args[1], options)
|
|
|
|
elif args[0] == "re-initialize":
|
|
|
|
re_initialize(realm, options)
|
|
|
|
elif args[0] == "force-sync":
|
|
|
|
if not options.fromhost:
|
|
|
|
sys.exit("force-sync requires the option --from <host name>")
|
|
|
|
force_sync(realm, host, options.fromhost, options.dirman_passwd)
|
|
|
|
elif args[0] == "connect":
|
2015-10-30 07:06:21 -05:00
|
|
|
if has_managed_topology(api):
|
|
|
|
exit_on_managed_topology("Creation of IPA CS replication agreement")
|
2011-07-14 22:35:01 -05:00
|
|
|
if len(args) == 3:
|
|
|
|
replica1 = args[1]
|
|
|
|
replica2 = args[2]
|
|
|
|
elif len(args) == 2:
|
|
|
|
replica1 = host
|
|
|
|
replica2 = args[1]
|
|
|
|
add_link(realm, replica1, replica2, dirman_passwd, options)
|
|
|
|
elif args[0] == "disconnect":
|
2015-10-30 07:06:21 -05:00
|
|
|
if has_managed_topology(api):
|
|
|
|
exit_on_managed_topology("Removal of IPA CS replication agreement")
|
2011-07-14 22:35:01 -05:00
|
|
|
if len(args) == 3:
|
|
|
|
replica1 = args[1]
|
|
|
|
replica2 = args[2]
|
|
|
|
elif len(args) == 2:
|
|
|
|
replica1 = host
|
|
|
|
replica2 = args[1]
|
2012-08-30 15:24:10 -05:00
|
|
|
del_link(realm, replica1, replica2, dirman_passwd, options.force)
|
2014-07-23 12:03:46 -05:00
|
|
|
elif args[0] == 'set-renewal-master':
|
|
|
|
replica = None
|
|
|
|
if len(args) > 1:
|
|
|
|
replica = args[1]
|
|
|
|
set_renewal_master(realm, replica)
|
2011-07-14 22:35:01 -05:00
|
|
|
|
2016-10-27 03:31:45 -05:00
|
|
|
api.Backend.ldap2.disconnect()
|
|
|
|
|
2011-07-14 22:35:01 -05:00
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(1)
|
2015-07-30 09:49:29 -05:00
|
|
|
except SystemExit as e:
|
2011-07-14 22:35:01 -05:00
|
|
|
sys.exit(e)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-01-30 08:51:08 -06:00
|
|
|
sys.exit("unexpected error: %s" % e)
|