/usr/lib/python3/dist-packages/lib389/tasks.py is in python3-lib389 1.3.7.10-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 | # --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2015 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---
import time
import os.path
import ldap
from datetime import datetime
from lib389 import Entry
from lib389._mapped_object import DSLdapObject
from lib389.exceptions import Error
from lib389._constants import (
DEFAULT_SUFFIX, DEFAULT_BENAME, DN_EXPORT_TASK, DN_BACKUP_TASK,
DN_IMPORT_TASK, DN_RESTORE_TASK, DN_INDEX_TASK, DN_MBO_TASK,
DN_TOMB_FIXUP_TASK, DN_TASKS, DIRSRV_STATE_ONLINE
)
from lib389.properties import (
TASK_WAIT, EXPORT_REPL_INFO, MT_PROPNAME_TO_ATTRNAME, MT_SUFFIX,
TASK_TOMB_STRIP
)
class Task(DSLdapObject):
def __init__(self, instance, dn=None, batch=False):
super(Task, self).__init__(instance, dn, batch)
self._rdn_attribute = 'cn'
self._must_attributes = ['cn']
self._create_objectclasses = ['top', 'extensibleObject']
self._protected = False
self._exit_code = None
def is_complete(self):
"""Return True if task is complete, else False."""
self._exit_code = self.get_attr_val("nsTaskExitCode")
if not self.exists() or self._exit_code is not None:
return True
return False
def get_exit_code(self):
"""Return task's exit code if task is complete, else None."""
if self.is_complete():
try:
return int(self._exit_code)
except TypeError:
return None
return None
def wait(self):
"""Wait until task is complete."""
while True:
if self.is_complete():
break
time.sleep(1)
def create(self, rdn=None, properties=None, basedn=None):
properties['cn'] = self.cn
return super(Task, self).create(rdn, properties, basedn)
@staticmethod
def _get_task_date():
"""Return a timestamp to use in naming new task entries."""
return datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
class MemberOfFixupTask(Task):
def __init__(self, instance, dn=None, batch=False):
self.cn = 'memberOf_fixup_' + Task._get_task_date()
dn = "cn=" + self.cn + "," + DN_MBO_TASK
super(MemberOfFixupTask, self).__init__(instance, dn, batch)
self._must_attributes.extend(['basedn'])
class USNTombstoneCleanupTask(Task):
def __init__(self, instance, dn=None, batch=False):
self.cn = 'usn_cleanup_' + Task._get_task_date()
dn = "cn=" + self.cn + ",cn=USN tombstone cleanup task," + DN_TASKS
super(USNTombstoneCleanupTask, self).__init__(instance, dn, batch)
def _validate(self, rdn, properties, basedn):
if not 'suffix' in properties and not 'backend' in properties:
raise Error("Either suffix or backend must be specified for cleanup task.")
return super(USNTombstoneCleanupTask, self)._validate(rdn, properties, basedn)
class SchemaReloadTask(Task):
def __init__(self, instance, dn=None, batch=False):
self.cn = 'schema_reload_' + Task._get_task_date()
dn = "cn=" + self.cn + ",cn=schema reload task," + DN_TASKS
super(SchemaReloadTask, self).__init__(instance, dn, batch)
class Tasks(object):
proxied_methods = 'search_s getEntry'.split()
def __init__(self, conn):
"""@param conn - a DirSrv instance"""
self.conn = conn
self.log = conn.log
self.dn = None # DN of the last task attempted
self.entry = None
def __getattr__(self, name):
from lib389 import DirSrv
if name in Tasks.proxied_methods:
return DirSrv.__getattr__(self.conn, name)
def checkTask(self, entry, dowait=False):
'''check task status - task is complete when the nsTaskExitCode attr
is set return a 2 tuple (true/false,code) first is false if task is
running, true if done - if true, second is the exit code - if dowait
is True, this function will block until the task is complete'''
attrlist = ['nsTaskLog', 'nsTaskStatus', 'nsTaskExitCode',
'nsTaskCurrentItem', 'nsTaskTotalItems']
done = False
exitCode = 0
dn = entry.dn
while not done:
entry = self.conn.getEntry(dn, attrlist=attrlist)
self.log.debug("task entry %r" % entry)
if entry.nsTaskExitCode:
exitCode = int(entry.nsTaskExitCode)
done = True
if dowait:
time.sleep(1)
else:
break
return (done, exitCode)
def importLDIF(self, suffix=None, benamebase=None, input_file=None,
args=None):
'''
Import from a LDIF format a given 'suffix' (or 'benamebase' that stores
that suffix). It uses an internal task to acheive this request.
If 'suffix' and 'benamebase' are specified, it uses 'benamebase' first
else 'suffix'.
If both 'suffix' and 'benamebase' are missing it raise ValueError
'input_file' is the ldif input file
@param suffix - suffix of the backend
@param benamebase - 'commonname'/'cn' of the backend (e.g. 'userRoot')
@param ldif_input - file that will contain the entries in LDIF format
to import
@param args - is a dictionary that contains modifier of the import task
wait: True/[False] - If True, 'export' waits for the completion
of the task before to return
@return None
@raise ValueError
'''
if self.conn.state != DIRSRV_STATE_ONLINE:
raise ValueError("Invalid Server State %s! Must be online" % self.conn.state)
# Checking the parameters
if not benamebase and not suffix:
raise ValueError("Specify either bename or suffix")
if not input_file:
raise ValueError("input_file is mandatory")
if not os.path.exists(input_file):
raise ValueError("Import file (%s) does not exist" % input_file)
# Prepare the task entry
cn = "import_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_IMPORT_TASK)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('nsFilename', input_file)
if benamebase:
entry.setValues('nsInstance', benamebase)
else:
entry.setValues('nsIncludeSuffix', suffix)
# start the task and possibly wait for task completion
self.conn.add_s(entry)
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: import task %s for file %s exited with %d" %
(cn, input_file, exitCode))
else:
self.log.info("Import task %s for file %s completed successfully" %
(cn, input_file))
self.dn = dn
self.entry = entry
return exitCode
def exportLDIF(self, suffix=None, benamebase=None, output_file=None,
args=None):
'''
Export in a LDIF format a given 'suffix' (or 'benamebase' that stores
that suffix). It uses an internal task to acheive this request.
If 'suffix' and 'benamebase' are specified, it uses 'benamebase' first
else 'suffix'.
If both 'suffix' and 'benamebase' are missing it raises ValueError
'output_file' is the output file of the export
@param suffix - suffix of the backend
@param benamebase - 'commonname'/'cn' of the backend (e.g. 'userRoot')
@param output_file - file that will contain the exported suffix in LDIF
format
@param args - is a dictionary that contains modifier of the export task
wait: True/[False] - If True, 'export' waits for the completion
of the task before to return
repl-info: True/[False] - If True, it adds the replication meta
data (state information, tombstones
and RUV) in the exported file
@return None
@raise ValueError
'''
# Checking the parameters
if not benamebase and not suffix:
raise ValueError("Specify either bename or suffix")
if not output_file:
raise ValueError("output_file is mandatory")
# Prepare the task entry
cn = "export_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_EXPORT_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsFilename': output_file
})
if benamebase:
entry.setValues('nsInstance', benamebase)
else:
entry.setValues('nsIncludeSuffix', suffix)
if args.get(EXPORT_REPL_INFO, False):
entry.setValues('nsExportReplica', 'true')
# start the task and possibly wait for task completion
self.conn.add_s(entry)
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: export task %s for file %s exited with %d" %
(cn, output_file, exitCode))
else:
self.log.info("Export task %s for file %s completed successfully" %
(cn, output_file))
self.dn = dn
self.entry = entry
return exitCode
def db2bak(self, backup_dir=None, args=None):
'''
Perform a backup by creating a db2bak task
@param backup_dir - backup directory
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
# Checking the parameters
if not backup_dir:
raise ValueError("You must specify a backup directory.")
# build the task entry
cn = "backup_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_BACKUP_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsArchiveDir': backup_dir,
'nsDatabaseType': 'ldbm database'
})
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the backup task (%s)" % dn)
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: backup task %s exited with %d" %
(cn, exitCode))
else:
self.log.info("Backup task %s completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
def bak2db(self, bename=None, backup_dir=None, args=None):
'''
Restore a backup by creating a bak2db task
@param bename - 'commonname'/'cn' of the backend (e.g. 'userRoot')
@param backup_dir - backup directory
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
# Checking the parameters
if not backup_dir:
raise ValueError("You must specify a backup directory")
if not os.path.exists(backup_dir):
raise ValueError("Backup file (%s) does not exist" % backup_dir)
# If a backend name was provided then verify it
if bename:
ents = self.conn.mappingtree.list(bename=bename)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % bename)
# build the task entry
cn = "restore_" + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = "cn=%s,%s" % (cn, DN_RESTORE_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsArchiveDir': backup_dir,
'nsDatabaseType': 'ldbm database'
})
if bename:
entry.update({'nsInstance': bename})
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the backup task (%s)" % dn)
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: restore task %s exited with %d" %
(cn, exitCode))
else:
self.log.info("Restore task %s completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
def reindex(self, suffix=None, benamebase=None, attrname=None, args=None):
'''
Reindex a 'suffix' (or 'benamebase' that stores that suffix) for a
given 'attrname'. It uses an internal task to acheive this request.
If 'suffix' and 'benamebase' are specified, it uses 'benamebase' first
else 'suffix'.
If both 'suffix' and 'benamebase' are missing it raise ValueError
@param suffix - suffix of the backend
@param benamebase - 'commonname'/'cn' of the backend (e.g. 'userRoot')
@param attrname - attribute name
@param args - is a dictionary that contains modifier of the reindex
task
wait: True/[False] - If True, 'index' waits for the completion
of the task before to return
@return None
@raise ValueError - if invalid missing benamebase and suffix or invalid
benamebase
@raise LDAPError if unable to search for index names
'''
if not benamebase and not suffix:
raise ValueError("Specify either bename or suffix")
# If backend name was provided, retrieve the suffix
if benamebase:
ents = self.conn.mappingtree.list(bename=benamebase)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % benamebase)
attr_suffix = MT_PROPNAME_TO_ATTRNAME[MT_SUFFIX]
if not ents[0].hasAttr(attr_suffix):
raise ValueError(
"invalid backend name: %s, or entry without %s" %
(benamebase, attr_suffix))
suffix = ents[0].getValue(attr_suffix)
entries_backend = self.conn.backend.list(suffix=suffix)
backend = entries_backend[0].cn # assume 1 local backend
attrs = []
if not attrname:
#
# Reindex all attributes - gather them first...
#
cn = "index_all_%s" % (time.strftime("%m%d%Y_%H%M%S",
time.localtime()))
dn = ('cn=%s,cn=ldbm database,cn=plugins,cn=config' % backend)
try:
indexes = self.conn.search_s(dn,
ldap.SCOPE_SUBTREE,
'(objectclass=nsIndex)')
for index in indexes:
attrs.append(index.getValue('cn'))
except ldap.LDAPError:
raise
else:
#
# Reindex specific attribute
#
cn = "index_%s_%s" % (attrname, time.strftime("%m%d%Y_%H%M%S",
time.localtime()))
attrs.append(attrname)
dn = "cn=%s,%s" % (cn, DN_INDEX_TASK)
entry = Entry(dn)
entry.update({
'objectclass': ['top', 'extensibleObject'],
'cn': cn,
'nsIndexAttribute': attrs,
'nsInstance': backend
})
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the index task for %s" % attrname)
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: index task %s exited with %d" %
(cn, exitCode))
else:
self.log.info("Index task %s completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
def fixupMemberOf(self, suffix=None, benamebase=None, filt=None,
args=None):
'''
Trigger a fixup task on 'suffix' (or 'benamebase' that stores that
suffix) related to the entries 'memberof' of groups. It uses an
internal task to acheive this request.
If 'suffix' and 'benamebase' are specified, it uses 'benamebase'
first else 'suffix'.
If both 'suffix' and 'benamebase' are missing it raise ValueError
'filt' is a filter that will select all the entries (under
'suffix') that we need to evaluate/fix. If missing, the default
value is "(|(objectclass=inetuser)(objectclass=inetadmin))"
@param suffix - suffix of the backend
@param benamebase - 'commonname'/'cn' of the backend
(e.g. 'userRoot')
@param args - is a dictionary that contains modifier of the
fixupMemberOf task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: if benamebase and suffix are specified, or can
not retrieve the suffix from the mapping tree
entry
'''
if not benamebase and not suffix:
raise ValueError("Specify either bename or suffix")
# If backend name was provided, retrieve the suffix
if benamebase:
ents = self.conn.mappingtree.list(bename=benamebase)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % benamebase)
attr = MT_PROPNAME_TO_ATTRNAME[MT_SUFFIX]
if not ents[0].hasAttr(attr):
raise ValueError(
"invalid backend name: %s, or entry without %s" %
(benamebase, attr))
suffix = ents[0].getValue(attr)
cn = "fixupmemberof_" + time.strftime("%m%d%Y_%H%M%S",
time.localtime())
dn = "cn=%s,%s" % (cn, DN_MBO_TASK)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
if filt:
entry.setValues('filter', filt)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the memberOf fixup task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: fixupMemberOf task %s for basedn %s exited with %d" %
(cn, suffix, exitCode))
else:
self.log.info(
"fixupMemberOf task %s for basedn %s completed successfully" %
(cn, suffix))
self.dn = dn
self.entry = entry
return exitCode
def fixupTombstones(self, bename=None, args=None):
'''
Trigger a tombstone fixup task on the specified backend
@param bename - 'commonname'/'cn' of the backend (e.g. 'userRoot').
Optional.
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: if bename name does not exist
'''
if not bename:
bename = DEFAULT_BENAME
# Verify the backend name
if bename:
ents = self.conn.mappingtree.list(bename=bename)
if len(ents) != 1:
raise ValueError("invalid backend name: %s" % bename)
cn = "fixupTombstone_" + time.strftime("%m%d%Y_%H%M%S",
time.localtime())
dn = "cn=%s,%s" % (cn, DN_TOMB_FIXUP_TASK)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('backend', bename)
if args and args.get(TASK_TOMB_STRIP, False):
entry.setValues('stripcsn', 'yes')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add the fixup tombstone task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: tombstone fixup task %s for backend %s exited with %d"
% (cn, bename, exitCode))
else:
self.log.info(
"tombstone fixup task %s for backend %s completed successfully"
% (cn, bename))
self.dn = dn
self.entry = entry
return exitCode
def automemberRebuild(self, suffix=DEFAULT_SUFFIX, scope='sub',
filterstr='objectclass=top', args=None):
'''
@param suffix - The suffix the task should examine - defualt is
"dc=example,dc=com"
@param scope - The scope of the search to find entries
@param fitlerstr - THe search filter to find entries
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=automember rebuild membership,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
entry.setValues('filter', filterstr)
entry.setValues('scope', scope)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Automember Rebuild Membership task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Automember Rebuild Membership task (%s) exited with %d"
% (cn, exitCode))
else:
self.log.info(
"Automember Rebuild Membership task(%s) completed successfully"
% (cn))
self.dn = dn
self.entry = entry
return exitCode
def automemberExport(self, suffix=DEFAULT_SUFFIX, scope='sub',
fstr='objectclass=top', ldif_out=None, args=None):
'''
@param suffix - The suffix the task should examine - default is
"dc=example,dc=com"
@param scope - The scope of the search to find entries
@param fstr - The search filter to find entries
@param ldif_out - The name for the output LDIF file
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
@raise ValueError: if ldif_out is not provided
'''
if not ldif_out:
raise ValueError("Missing ldif_out")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=automember export updates,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
entry.setValues('filter', fstr)
entry.setValues('scope', scope)
entry.setValues('ldif', ldif_out)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Automember Export Updates task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Automember Export Updates task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"Automember Export Updates task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def automemberMap(self, ldif_in=None, ldif_out=None, args=None):
'''
@param ldif_in - Entries to pass into the task for processing
@param ldif_out - The resulting LDIF of changes from ldif_in
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion
of the task before to return
@return exit code
@raise ValueError: if ldif_out/ldif_in is not provided
'''
if not ldif_out or not ldif_in:
raise ValueError("Missing ldif_out and/or ldif_in")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=automember map updates,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('ldif_in', ldif_in)
entry.setValues('ldif_out', ldif_out)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Automember Map Updates task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Automember Map Updates task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"Automember Map Updates task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def fixupLinkedAttrs(self, linkdn=None, args=None):
'''
@param linkdn - The DN of linked attr config entry (if None all
possible configurations are checked)
@param args - Is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion
of the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=fixup linked attributes,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
if linkdn:
entry.setValues('linkdn', linkdn)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Fixup Linked Attributes task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Fixup Linked Attributes task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"Fixup Linked Attributes task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def schemaReload(self, schemadir=None, args=None):
'''
@param schemadir - The directory to look for schema files(optional)
@param args - Is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=schema reload task,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
if schemadir:
entry.setValues('schemadir', schemadir)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Schema Reload task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Schema Reload task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("Schema Reload task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def fixupWinsyncMembers(self, suffix=DEFAULT_SUFFIX,
fstr='objectclass=top', args=None):
'''
@param suffix - The suffix the task should rebuild -
default is "dc=example,dc=com"
@param fstr - The search filter to find entries
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=memberuid task,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
entry.setValues('filter', fstr)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add fixupWinsyncMembers 'memberuid task'")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"fixupWinsyncMembers 'memberuid task' (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"'memberuid task' (%s) completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
def syntaxValidate(self, suffix=DEFAULT_SUFFIX, fstr='objectclass=top',
args=None):
'''
@param suffix - The suffix the task should validate -
default is "dc=example,dc=com"
@param fstr - The search filter to find entries
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=syntax validate,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('basedn', suffix)
entry.setValues('filter', fstr)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Syntax Validate task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Syntax Validate (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("Syntax Validate task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def usnTombstoneCleanup(self, suffix=DEFAULT_SUFFIX, bename=None,
maxusn_to_delete=None, args=None):
'''
@param suffix - The suffix the task should cleanup - default is
"dc=example,dc=com"
@param backend - The 'backend' the task should cleanup
@param maxusn_to_delete - Maximum number of usn's to delete
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return exit code
'''
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=USN tombstone cleanup task,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
if not bename:
entry.setValues('suffix', suffix)
else:
entry.setValues('backend', bename)
if maxusn_to_delete:
entry.setValues('maxusn_to_delete')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add USN tombstone cleanup task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: USN tombstone cleanup task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"USN tombstone cleanup task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def sysconfigReload(self, configfile=None, logchanges=None, args=None):
'''
@param configfile - The sysconfig file:
/etc/sysconfig/dirsrv-localhost
@param logchanges - True/False - Tell the server to log the changes
made by the task
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: If sysconfig file not provided
'''
if not configfile:
raise ValueError("Missing required paramter: configfile")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=cn=sysconfig reload,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('sysconfigfile', configfile)
if logchanges:
entry.setValues('logchanges', logchanges)
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Sysconfig Reload task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: Sysconfig Reload task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("Sysconfig Reload task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return exitCode
def cleanAllRUV(self, suffix=None, replicaid=None, force=None, args=None):
'''
@param replicaid - The replica ID to remove/clean
@param force - True/False - Clean all the replicas, even if one is down
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return tuple (task dn, and the exit code)
@raise ValueError: If missing replicaid
'''
if not replicaid:
raise ValueError("Missing required paramter: replicaid")
if not suffix:
raise ValueError("Missing required paramter: suffix")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=cleanallruv,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('replica-base-dn', suffix)
entry.setValues('replica-id', replicaid)
if force:
entry.setValues('replica-force-cleaning', 'yes')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add cleanAllRUV task")
return (dn, -1)
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: cleanAllRUV task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("cleanAllRUV task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return (dn, exitCode)
def abortCleanAllRUV(self, suffix=None, replicaid=None, certify=None,
args=None):
'''
@param replicaid - The replica ID to remove/clean
@param certify - True/False - Certify the task was aborted on all
the replicas
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of
the task before to return
@return tuple (task dn, and the exit code)
@raise ValueError: If missing replicaid
'''
if not replicaid:
raise ValueError("Missing required paramter: replicaid")
if not suffix:
raise ValueError("Missing required paramter: suffix")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=abort cleanallruv,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('replica-base-dn', suffix)
entry.setValues('replica-id', replicaid)
if certify:
entry.setValues('replica-certify-all', 'yes')
else:
entry.setValues('replica-certify-all', 'no')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add Abort cleanAllRUV task")
return (dn, -1)
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error(
"Error: Abort cleanAllRUV task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info(
"Abort cleanAllRUV task (%s) completed successfully" %
(cn))
self.dn = dn
self.entry = entry
return (dn, exitCode)
def upgradeDB(self, nsArchiveDir=None, nsDatabaseType=None,
nsForceToReindex=None, args=None):
'''
@param nsArchiveDir - The archive directory
@param nsDatabaseType - The database type - default is "ldbm database"
@param nsForceToReindex - True/False - force reindexing to occur
@param args - is a dictionary that contains modifier of the task
wait: True/[False] - If True, waits for the completion of the
task before to return
@return exit code
@raise ValueError: If missing nsArchiveDir
'''
if not nsArchiveDir:
raise ValueError("Missing required paramter: nsArchiveDir")
cn = 'task-' + time.strftime("%m%d%Y_%H%M%S", time.localtime())
dn = ('cn=%s,cn=upgradedb,cn=tasks,cn=config' % cn)
entry = Entry(dn)
entry.setValues('objectclass', 'top', 'extensibleObject')
entry.setValues('cn', cn)
entry.setValues('nsArchiveDir', nsArchiveDir)
if nsDatabaseType:
entry.setValues('nsDatabaseType', nsDatabaseType)
if nsForceToReindex:
entry.setValues('nsForceToReindex', 'True')
# start the task and possibly wait for task completion
try:
self.conn.add_s(entry)
except ldap.ALREADY_EXISTS:
self.log.error("Fail to add upgradedb task")
return -1
exitCode = 0
if args and args.get(TASK_WAIT, False):
(done, exitCode) = self.conn.tasks.checkTask(entry, True)
if exitCode:
self.log.error("Error: upgradedb task (%s) exited with %d" %
(cn, exitCode))
else:
self.log.info("Upgradedb task (%s) completed successfully" % (cn))
self.dn = dn
self.entry = entry
return exitCode
|