def main(): shutil.copy(os.path.join(paths.config_directory(), 'core.py.template'), os.path.join(paths.config_directory(), 'core.py')) irods_config = IrodsConfig() irods_config.server_config['plugin_configuration']['rule_engines'] = [ { 'instance_name': 'irods_rule_engine_plugin-python-instance', 'plugin_name': 'irods_rule_engine_plugin-python', 'plugin_specific_configuration': {} } ] irods_config.commit(irods_config.server_config, irods_config.server_config_path, make_backup=True)
def main(): irods_config = IrodsConfig() irods_config.server_config['plugin_configuration']['rule_engines'].insert( 1, { "instance_name": "irods_rule_engine_plugin-audit_amqp-instance", "plugin_name": "irods_rule_engine_plugin-audit_amqp", "plugin_specific_configuration": { "amqp_location": "ANONYMOUS@localhost:5672", "amqp_options": "", "amqp_topic": "audit_messages", "log_path_prefix": "/tmp/irods", "pep_regex_to_match": "audit_.*", "test_mode": "true" } }) irods_config.server_config["rule_engine_namespaces"].append("audit_") irods_config.commit(irods_config.server_config, irods_config.server_config_path, make_backup=True)
def main(): l = logging.getLogger(__name__) logging.getLogger().setLevel(logging.NOTSET) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) (options, _) = parse_options() irods_config = IrodsConfig() irods.log.register_file_handler(irods_config.setup_log_path) if options.verbose > 0: llevel = logging.NOTSET if options.verbose == 1: llevel = logging.INFO elif options.verbose == 2: llevel = logging.DEBUG irods.log.register_tty_handler(sys.stdout, llevel, logging.WARNING) if options.server_log_level != None: irods_config.injected_environment['spLogLevel'] = str( options.server_log_level) if options.sql_log_level != None: irods_config.injected_environment['spLogSql'] = str( options.sql_log_level) if options.days_per_log != None: irods_config.injected_environment['logfileInt'] = str( options.days_per_log) if options.rule_engine_server_options != None: irods_config.injected_environment[ 'reServerOption'] = options.rule_engine_server_options if options.server_reconnect_flag: irods_config.injected_environment['irodsReconnect'] = '' try: setup_server(irods_config, json_configuration_file=options.json_configuration_file, test_mode=options.test_mode) except IrodsError: l.error('Error encountered running setup_irods:\n', exc_info=True) l.info('Exiting...') return 1 except KeyboardInterrupt: l.info('Script terminated by user.') l.debug('KeyboardInterrupt encountered:\n', exc_info=True) return 0
def scrub_main(): # Condition states that one of these columns does not have its associated value update_columns = {'resc_name': 'EMPTY_RESC_NAME', 'resc_hier': 'EMPTY_RESC_HIER', 'resc_group_name': 'EMPTY_RESC_GROUP_NAME'} update_condition = ' or '.join(["({key} != '{val}' or {key} is NULL)".format(key=key, val=update_columns[key]) for key in update_columns.keys()]) # Selects resc_ids of known non-coordinating resources coordinating_resources = ['compound', 'deferred', 'load_balanced', 'random', 'replication', 'roundrobin', 'passthru'] select_resc_ids = 'SELECT resc_id FROM R_RESC_MAIN WHERE resc_type_name NOT IN ({})'.format(','.join(["'{}'".format(resc) for resc in coordinating_resources])) parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description= ''' Replaces data in now unused columns of R_DATA_MAIN with the following values: {} WARNING: This script directly overwrites data in the columns listed above, making resc_id the only column to hold the location of the replica. Make sure catalog information is backed up before proceeding. The resc_id column must be valid for a row to be updated. This script must be run on the catalog provider. '''.format('\n'.join(['\t{}\t\t{}'.format(key, update_columns[key]) for key in update_columns.keys()]))) parser.add_argument('-d', '--dry-run', action='store_true', dest='dry_run', help='Count rows to be overwritten (no changes made to database)') parser.add_argument('-b', '--batch-size', action='store', dest='batch_size', type=int, default=500, help='Number of records to update per database commit (default: 500)') args = parser.parse_args() try: with contextlib.closing(database_connect.get_database_connection(IrodsConfig())) as connection: connection.autocommit = False if args.dry_run: dry_run(connection, select_resc_ids, update_condition) else: scrub_rows(connection, args.batch_size, select_resc_ids, update_columns, update_condition) except (TypeError): print('Failed getting database connection. Note: This script should be run on the iRODS catalog provider.')
def main(): l = logging.getLogger(__name__) logging.getLogger().setLevel(logging.NOTSET) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) (options, _) = parse_options() irods_config = IrodsConfig( top_level_directory=options.top_level_directory, config_directory=options.config_directory) irods.log.register_file_handler(irods_config.setup_log_path) if options.verbose: irods.log.register_tty_handler(sys.stdout, logging.INFO, logging.WARNING) if options.server_log_level != None: irods_config.injected_environment['spLogLevel'] = options.server_log_level if options.sql_log_level != None: irods_config.injected_environment['spLogSql'] = options.sql_log_level if options.days_per_log != None: irods_config.injected_environment['logfileInt'] = options.days_per_log if options.rule_engine_server_options != None: irods_config.injected_environment['reServerOption'] = options.rule_engine_server_options if options.server_reconnect_flag: irods_config.injected_environment['irodsReconnect'] = '' try: setup_server(irods_config) except IrodsError: l.error('Error encountered running setup_irods:\n', exc_info=True) l.info('Exiting...') return 1 except KeyboardInterrupt: l.info('Script terminated by user.') l.debug('KeyboardInterrupt encountered:\n', exc_info=True) return 0
#!/usr/bin/env python import shutil from irods import lib from irods.test import session from irods.configuration import IrodsConfig from irods import test import test.settings test_user_list = ['alice', 'bobby', 'otherrods', 'zonehopper', 'admin'] test_resc_list = ['AnotherResc', 'TestResc', 'pt', 'leaf'] # make admin session irods_config = IrodsConfig() admin_name = irods_config.client_environment['irods_user_name'] zone_name = irods_config.client_environment['irods_zone_name'] env_dict = lib.make_environment_dict(admin_name, test.settings.ICAT_HOSTNAME, zone_name, use_ssl=test.settings.USE_SSL) sess = session.IrodsSession(env_dict, test.settings.PREEXISTING_ADMIN_PASSWORD, False) # remove test stuff for user_name in test_user_list: # get permission on user's collection sess.run_icommand( 'ichmod -rM own {admin_name} /{zone_name}/home/{user_name}'.format( **locals()))
def get_current_schema_version(irods_config=None, cursor=None): if irods_config is None: irods_config = IrodsConfig() return irods_config.get_schema_version_in_database()
def run_irodsctl_with_arg(arg): irodsctl = os.path.join(IrodsConfig().irods_directory, 'irodsctl') subprocess.check_call([irodsctl, arg])
def __init__(self, *args, **kwargs): super(RegisteredTestResult, self).__init__(*args, **kwargs) unittest.registerResult(self) def startTest(self, test): # TextTestResult's impl prints as "test (module.class)" which prevents copy/paste print('{0} ... '.format(test.id()), end='', file=self.stream) unittest.TestResult.startTest(self, test) if __name__ == '__main__': logging.getLogger().setLevel(logging.NOTSET) l = logging.getLogger(__name__) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) irods.log.register_file_handler(IrodsConfig().test_log_path) parser = optparse.OptionParser() parser.add_option('--run_specific_test', metavar='dotted name') parser.add_option('--skip_until', action="store") parser.add_option('--run_python_suite', action='store_true') parser.add_option('--include_auth_tests', action='store_true') parser.add_option('--run_devtesty', action='store_true') parser.add_option('--topology_test', type='choice', choices=['icat', 'resource'], action='callback', callback=optparse_callback_topology_test, metavar='<icat|resource>') parser.add_option('--catch_keyboard_interrupt', action='callback',
def main(): logging.getLogger().setLevel(logging.NOTSET) l = logging.getLogger(__name__) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) if (os.geteuid() == 0): l.error('irodsctl should not be run by the root user.\n' 'Exiting...') return 1 operations_dict = {} operations_dict['start'] = lambda: irods_controller.start() operations_dict['graceful_start'] = lambda: irods_controller.start() operations_dict['stop'] = lambda: irods_controller.stop() operations_dict['restart'] = lambda: irods_controller.restart() operations_dict['graceful_restart'] = lambda: irods_controller.restart() operations_dict['status'] = lambda: irods_controller.status() operations_dict['get_environment'] = lambda: irods_config.print_execution_environment() (options, arguments) = parse_options() if len(arguments) != 1: l.error('irodsctl accepts exactly one positional argument, ' 'but {0} were provided.\n' 'Exiting...' % ( len(arguments))) return 1 operation = arguments[0] if operation not in operations_dict: l.error('irodsctl accepts the following positional arguments:\n' '%s\n' 'but \'%s\' was provided.\n' 'Exiting...' % ( irods.lib.indent(*operations_dict.keys()), operation)) return 1 irods_config = IrodsConfig() irods.log.register_file_handler(irods_config.control_log_path) if options.verbose: irods.log.register_tty_handler(sys.stdout, logging.INFO, logging.WARNING) if options.server_log_level != None: irods_config.injected_environment['spLogLevel'] = str(options.server_log_level) if options.sql_log_level != None: irods_config.injected_environment['spLogSql'] = str(options.sql_log_level) if options.days_per_log != None: irods_config.injected_environment['logfileInt'] = str(options.days_per_log) if options.rule_engine_server_options != None: irods_config.injected_environment['reServerOption'] = options.rule_engine_server_options if options.server_reconnect_flag: irods_config.injected_environment['irodsReconnect'] = '' irods_controller = IrodsController(irods_config) try: operations_dict[operation]() except IrodsError as e: l.error('Error encountered running irods_control %s:\n' % (operation), exc_info=True) l.info('Exiting...') return 1 return 0
def __init__(self, *args, **kwargs): super(RegisteredTestResult, self).__init__(*args, **kwargs) unittest.registerResult(self) def startTest(self, test): # TextTestResult's impl prints as "test (module.class)" which prevents copy/paste print('{0} ... '.format(test.id()), end='', file=self.stream) unittest.TestResult.startTest(self, test) if __name__ == '__main__': logging.getLogger().setLevel(logging.NOTSET) l = logging.getLogger(__name__) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) irods.log.register_file_handler(IrodsConfig().test_log_path) parser = optparse.OptionParser() parser.add_option('--run_specific_test', metavar='dotted name') parser.add_option('--skip_until', action="store") parser.add_option('--run_python_suite', action='store_true') parser.add_option('--run_plugin_tests', action='store_true') parser.add_option('--include_auth_tests', action='store_true') parser.add_option('--run_devtesty', action='store_true') parser.add_option('--topology_test', type='choice', choices=['icat', 'resource'], action='callback', callback=optparse_callback_topology_test, metavar='<icat|resource>') parser.add_option('--catch_keyboard_interrupt',
def main(): logging.getLogger().setLevel(logging.NOTSET) l = logging.getLogger(__name__) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) if (os.geteuid() == 0): l.error('irodsctl should not be run by the root user.\n' 'Exiting...') return 1 operations_dict = {} operations_dict['start'] = lambda: irods_controller.start(write_to_stdout=options.write_to_stdout, test_mode=options.test_mode) operations_dict['graceful_start'] = lambda: irods_controller.start(write_to_stdout=options.write_to_stdout, test_mode=options.test_mode) operations_dict['stop'] = lambda: irods_controller.stop() operations_dict['restart'] = lambda: irods_controller.restart(write_to_stdout=options.write_to_stdout, test_mode=options.test_mode) operations_dict['graceful_restart'] = lambda: irods_controller.restart(write_to_stdout=options.write_to_stdout, test_mode=options.test_mode) operations_dict['status'] = lambda: irods_controller.status() operations_dict['get_environment'] = lambda: irods_config.print_execution_environment() (options, arguments) = parse_options() if len(arguments) != 1: l.error('irodsctl accepts exactly one positional argument, ' 'but {0} were provided.\n' 'Exiting...' % ( len(arguments))) return 1 operation = arguments[0] if operation not in operations_dict: l.error('irodsctl accepts the following positional arguments:\n' '%s\n' 'but \'%s\' was provided.\n' 'Exiting...' % ( irods.lib.indent(*operations_dict.keys()), operation)) return 1 irods_config = IrodsConfig() if operation == 'status': options.verbose += 1 irods.log.register_file_handler(irods_config.control_log_path) if options.verbose > 0: llevel = logging.NOTSET if options.verbose == 1: llevel = logging.INFO elif options.verbose == 2: llevel = logging.DEBUG irods.log.register_tty_handler(sys.stdout, llevel, logging.WARNING) if options.server_log_level != None: irods_config.injected_environment['spLogLevel'] = str(options.server_log_level) if options.sql_log_level != None: irods_config.injected_environment['spLogSql'] = str(options.sql_log_level) if options.days_per_log != None: irods_config.injected_environment['logfileInt'] = str(options.days_per_log) if options.rule_engine_server_options != None: irods_config.injected_environment['reServerOption'] = options.rule_engine_server_options if options.server_reconnect_flag: irods_config.injected_environment['irodsReconnect'] = '' irods_controller = IrodsController(irods_config) try: operations_dict[operation]() except IrodsError as e: l.error('Error encountered running irods_control %s:\n' % (operation), exc_info=True) l.info('Exiting...') return 1 return 0
from irods.configuration import IrodsConfig from irods import lib config = IrodsConfig() config.server_config['plugin_configuration']['rule_engines'].insert( 1, { "instance_name": "irods_rule_engine_plugin-audit_amqp-instance", "plugin_name": "irods_rule_engine_plugin-audit_amqp", "plugin_specific_configuration": { "amqp_location": "[email protected]:5672", "amqp_options": "", "amqp_topic": "audit_messages", "pep_regex_to_match": "audit_.*" } }) config.server_config['rule_engine_namespaces'].insert(1, "audit_") lib.update_json_file_from_dict(config.server_config_path, config.server_config)
class RegisteredTestResult(unittest.TextTestResult): def __init__(self, *args, **kwargs): super(RegisteredTestResult, self).__init__(*args, **kwargs) unittest.registerResult(self) def startTest(self, test): # TextTestResult's impl prints as "test (module.class)" which prevents copy/paste print('{0} ... '.format(test.id()), end='', file=self.stream) unittest.TestResult.startTest(self, test) if __name__ == '__main__': logging.getLogger().setLevel(logging.NOTSET) l = logging.getLogger(__name__) irods.log.register_tty_handler(sys.stderr, logging.WARNING, None) irods.log.register_file_handler(IrodsConfig().test_log_path) parser = optparse.OptionParser() parser.add_option('--run_specific_test', metavar='dotted name') parser.add_option('--skip_until', action="store") parser.add_option('--run_python_suite', action='store_true') parser.add_option('--run_plugin_tests', action='store_true') parser.add_option('--include_auth_tests', action='store_true') parser.add_option('--run_devtesty', action='store_true') parser.add_option('--topology_test', type='choice', choices=['icat', 'resource'], action='callback', callback=optparse_callback_topology_test, metavar='<icat|resource>') parser.add_option('--catch_keyboard_interrupt', action='callback', callback=optparse_callback_catch_keyboard_interrupt) parser.add_option('--use_ssl', action='callback', callback=optparse_callback_use_ssl) parser.add_option('--use_mungefs', action='callback', callback=optparse_callback_use_mungefs) parser.add_option('--no_buffer', action='store_false', dest='buffer_test_output', default=True) parser.add_option('--xml_output', action='store_true', dest='xml_output', default=False) parser.add_option('--federation', type='str', nargs=3, action='callback', callback=optparse_callback_federation, metavar='<remote irods version, remote zone, remote host>')
from functools import reduce import sys from irods.configuration import IrodsConfig def usage(): print('Usage: get_irods_version.py ["string"|"integer"|"major"|"minor"|"patchlevel"]') # check parameters if len(sys.argv) != 2: usage() sys.exit(1) operations = {} operations['string'] = lambda x: x operations['integer'] = lambda x: reduce(lambda y, z: y*1000 + int(z), x.split('.'), 0) operations['major'] = lambda x: int(x.split('.')[0]) operations['minor'] = lambda x: int(x.split('.')[1]) operations['patchlevel'] = lambda x: int(x.split('.')[2]) # read version from VERSION.json version_string = IrodsConfig().version['irods_version'] try : value = operations[sys.argv[1]](version_string) except KeyError: print('ERROR: unknown format [%s] requested' % sys.argv[1], file=sys.stderr) usage() sys.exit(1) print(value)