def get_database_list(instance=None): """ This function is to extract and return the list of databases on the given target DB2 Instance. Usage: database_list = get_database_list('db2inst1') db_list = [database for database in database_list] """ databases = list() global db2_profile steplog.info('Pull the list of databases from the current instance.') if not instance: raise ValueError("You must provide the DB2 instance name") if not db2_profile: raise SystemError("Missing db2profile default path") if is_non_zero_file(db2_profile): cmd = '. ~%s/%s ; cd / ; db2 list database directory | grep "Database name"' % ( instance, db2_profile) out, err, rc = db2tools.run_instance_command(instance, cmd) steplog.debug(out) steplog.debug(rc) if rc == 0: if out: for line in out.splitlines(): if line.strip().startswith('Database name'): database_name = line.split('=')[1].strip() databases.append(database_name) return databases else: steplog.info("No database found for the current instance: %s" % instance) else: raise EnvironmentError( "Command could not run successfully. Please check again")
def main(): steplog.info('Validate Provision Oracle Data Guard') Validator.register(check_standby_DB_name) Validator.register(check_required_parameters) Validator.register(check_for_reachable_hosts, args=[PRIMARY_NODE_HOSTNAMES]) Validator.register(check_for_reachable_hosts, args=[STANDBY_NODE_HOSTNAMES]) if DB_FILE_NAME_CONVERT: Validator.register(check_filename_convert_pattern, args=[DB_FILE_NAME_CONVERT]) if LOG_FILE_NAME_CONVERT: Validator.register(check_filename_convert_pattern, args=[LOG_FILE_NAME_CONVERT]) Validator.register(oraclevalidation.validate_optional_file_name, args=[ORATAB_LOCATION, "Oratab File Location"]) Validator.register(oraclevalidation.validate_optional_file_name, args=[TNSNAMES_FILE_LOCATION, "Tnsnames File Location"]) Validator.register(commonvalidation.validate_parameter_in_allowed_values, args=[DB_PROTECTION_MODE, VALID_DB_PRIMARY_PROTECTION_MODES, "Database Protection Mode"]) Validator.register(commonvalidation.validate_parameter_in_allowed_values, args=[DG_STANDBY_TYPE, VALID_DATA_GUARD_STANDBY_TYPES, "Data Guard Standby Type"]) Validator.register(commonvalidation.validate_parameter_in_allowed_values, args=[UPDATE_STANDBY_ORATAB_FILE, ["yes", "no"], "Update oratab file on Standby Servers"]) Validator.register(commonvalidation.validate_parameter_in_allowed_values, args=[CHG_REMOTE_LOGIN_PSWDFILE, ["yes", "no"], "Change Remote Login PasswordFile on Primary"]) Validator.validate() failures = Validator.str_failed_results() if failures: msg = 'Error(s) validating parameters for Provision Oracle Data Guard:\n\n%s' % failures steplog.info(msg) steplog.error(msg) sys.exit(1) # given the instance name in primary_db_instance_name, # identify the matching entry in the /etc/oratab on the # primary_node_hostnames[0] and pluck out the corresponding # oracle_home value Validator.register(infer_oracle_home, args=[PRIMARY_NODE_HOSTNAMES[0], PRIMARY_DB_INSTANCE_NAME, ORATAB_LOCATION]) Validator.validate() failures = Validator.str_failed_results() if failures: msg = 'Error(s) validating parameters for Provision Oracle Data Guard:\n\n%s' % failures steplog.info(msg) steplog.error(msg) sys.exit(1) Validator.register(oraclevalidation.validate_oracle_home, args=[oracle_home]) Validator.register(check_working_credential) Validator.register(check_standby_service_name) Validator.validate() failures = Validator.str_failed_results() if failures: msg = 'Error(s) validating parameters for Provision Oracle Data Guard:\n\n%s' % failures steplog.info(msg) steplog.error(msg) sys.exit(1) steplog.info('Validate Provision Oracle Data Guard successful. You may proceed.') print_header() sys.exit(0)
def main(): print "----------------------------------------------------------------------------------------" steplog.info('Binding packages with database objects') print "----------------------------------------------------------------------------------------" instance_line = {} database_list = [] instance_to_set = "" install_path = params['DB2 Installation Location'] db2_install = db2tools.DB2Installation(install_path) db2_install.find_instances_and_das() ## Extract the instance details found on the target machine ## instance_line = db2_install.instances ## First Instance in the instances found on the target ## if not instance_line: steplog.warn( "No instance(s) found for %s DB2 Installation. There is nothing to bind....." % params['DB2 Installation Location']) sys.exit(1) else: first_inst_name = instance_line.keys()[0] if first_inst_name: instance_to_set = first_inst_name steplog.info( "Instances are found in %s DB2 setup. Upgrade process will run.." % params['DB2 Existing Installation Location']) steplog.debug(instance_to_set) if instance_to_set: ## Setup the default DB2 Instance on target machine environment ## os.environ["DB2INSTANCE"] = instance_to_set.strip() steplog.debug(os.environ["DB2INSTANCE"]) ## First Instance in the instances found on the target ## if instance_line: count = len(instance_line) for instance in instance_line: steplog.info("Instance Counter : %s" % count) count -= 1 instance_to_bind = instance_line.keys()[count] steplog.info("Instance found for binding its databases : %s" % instance_to_bind) database_list = get_databases(instance_to_bind) if database_list: bind_db2schema_packages(database_list, instance_to_bind) bind_db2client_packages(database_list, instance_to_bind) bind_db2ubind_packages(database_list, instance_to_bind) else: steplog.info( "No database found under instance %s. No binding will occure" % instance_to_bind)
def create_backup_dir(params_dict): """ To check and create a backup director path if not found. """ print threading.currentThread().getName(), 'Starting' backup_location = params_dict['DB2 Installation Backup Directory'] if not os.path.exists(backup_location): steplog.info("Attempting to create the backup directory") try: os.makedirs(backup_location) steplog.info("Backup directory has been created") except OSError: if not os.path.isdir(backup_location): raise ValueError("Backup directory could not be created")
def get_databases(instance): """ This function is to extract the list of databases on the given target DB2 Instance """ databases = [] steplog.info('Getting list of databases.') cmd = '. ~%s/sqllib/db2profile ; cd / ; db2 list database directory | grep "Database name"' % instance out, err, retCode = db2tools.run_instance_command(instance, cmd) steplog.debug(out) if out: for line in out.splitlines(): if line.strip().startswith('Database name'): database_name = line.split('=')[1].strip() databases.append(database_name) return databases
def main(): steplog.info("------------------------------------------------------") steplog.info("Shutting down the DB2 Instances to patch fixpack") steplog.info("------------------------------------------------------") Instance_line={} # params = parametertools.parse_dma_params() install_path = params['Install Path'] db2_install = db2tools.DB2Installation(install_path) db2_install.find_instances_and_das() ## Extract the instance details found on the target machine ## Instance_line = db2_install.instances ## First Instance in the instances found on the target ## if Instance_line: first_inst_name = Instance_line.keys()[0] instance_to_set = first_inst_name steplog.debug(first_inst_name) if instance_to_set: ## Setup the default DB2 Instance on target machine environment ## os.environ["DB2INSTANCE"] = instance_to_set.strip() steplog.debug(os.environ["DB2INSTANCE"]) inst_fix_pack = get_installed_fixpack_version(install_path) media_fixpack = get_db2_binary_fixpack_version(params['Stage Archive']) custom_fixpack = params['If Custom Fixpack'] custom_fixpack = custom_fixpack.strip() print custom_fixpack if custom_fixpack== "true" or custom_fixpack == "yes" or custom_fixpack == "y": steplog.info("The current version of fixpack determined from the binary is of the same version as of on the target. Custom fixpack will be installed") inst_fix_build_num = get_installed_fixpack_build(params['Install Path']) print "Installed fixpack build : %s" % inst_fix_build_num media_build_num = get_db2_binary_build_version(params['Stage Archive']) if not media_build_num or inst_fix_build_num: if not int(media_build_num) > int(inst_fix_build_num): steplog.error("A greater version or same version of Fixpack build %s is already installed" % inst_fix_build_num) sys.exit(1) else: if not int(media_fixpack) > int(inst_fix_pack): steplog.error("A greater version or same version of Fix pack %s is already installed" % inst_fix_pack) sys.exit(1) states = get_software_states(db2_install, install_path) shutdown_software(db2_install, states) for key, value in states.items(): if isinstance(value, list): params[key] = ','.join(value) else: params[key] = value parametertools.print_header(params)
def main(): global response_dbca storage_type = "" datafile_info = "" if DATAFILE_LOCATION: datafile_info, storage_type = get_datafile_and_storage() policy_params = '' if POLICY_MANAGED.lower() == 'true' and CRS_HOME: policy_params = get_policy_params() pwd_info = get_password_settings() #Added two lines for test purpose-sylesh print "Till here the value is passed" print DBCA_CHARSET charset = 'US7ASCII' if DBCA_CHARSET: charset = DBCA_CHARSET # Adding this line to test- sylesh print charset national_charset = 'UTF8' if DBCA_NATIONAL_CHARSET: national_charset = DBCA_NATIONAL_CHARSET container_params = get_container_params() default_response_file = get_default_response(policy_params, datafile_info, storage_type, pwd_info, charset, national_charset, container_params) if response_dbca: # If the template exists, use it. steplog.info("Using existing response file %s" % response_dbca) modify_response(response_dbca) else: # If the response file does not exist, create it. steplog.info("Creating a new DBCA response file.") response_dbca = os.path.join(System.getProperty("java.io.tmpdir"), "%sDBCA.rsp" % DATABASE_NAME) create_response(default_response_file, response_dbca) print_header() sys.exit(0)
def set_defaults(): global tns_file_location, lsnr_file_location global asm_home, asm_user if not tns_file_location: tns_file_location = '%s/network/admin/tnsnames.ora' % ORACLE_HOME if not lsnr_file_location: if ASM_DISKGROUP: asm_home, asm_sid = oracletools.get_asm_info_from_oratab_file( ORATAB_FILE_LOCATION) if not asm_home: steplog.error('Unable to detect ASM entry in %s' % ORATAB_FILE_LOCATION) sys.exit(1) steplog.info('asm_home: %r' % asm_home) asm_user = ostools.get_file_owner(asm_home) steplog.info('asm_user: %r' % asm_user) lsnr_file_location = '%s/network/admin/listener.ora' % asm_home else: lsnr_file_location = '%s/network/admin/listener.ora' % ORACLE_HOME
def main(): steplog.info('Setup Network Configuration on Primary and Standby Servers') set_defaults() get_listener_ports() steplog.info("ORACLE_HOME : %s" % ORACLE_HOME) steplog.info("tnsnames file location: %s" % tns_file_location) steplog.info("listener file location: %s" % lsnr_file_location) primary_hosts = PRIMARY_NODE_HOSTNAMES standby_hosts = STANDBY_NODE_HOSTNAMES # prime the status dict with True values status = {} # key by host, boolean value for host in primary_hosts + standby_hosts: status[host] = True is_valid = update_tnsnames_all_nodes(primary_hosts, standby_hosts, status) if not is_valid: steplog.error('Error updating tnsnames on some host(s)') sys.exit(1) is_valid = update_listenerora_all_nodes(primary_hosts, standby_hosts, status) if not is_valid: steplog.error('Error updating listener.ora on some standby host(s)') sys.exit(1) # now, exit with a success code, if and only if there aren't any # False entries for any host in the status dict failures = [host for host in status.keys() if status[host] != True] if len(failures) > 0: sys.exit(1) set_params(params, standby_hosts[0]) parametertools.print_header(params) steplog.info( 'Setup Network Configuration on Primary and Standby Servers successful. You may proceed.' ) sys.exit(0)
def get_listener_ports(): global primary_lsnr_port_num, standby_lsnr_port_num steplog.info( 'Attempt to get the primary db listener port and standby db listener port' ) primary_host = PRIMARY_NODE_HOSTNAMES[0] standby_host = STANDBY_NODE_HOSTNAMES[0] if ASM_DISKGROUP: p_lsnr_info = oracletools.fetch_listener(primary_host, HOSTNAME, asm_home) s_lsnr_info = oracletools.fetch_listener(standby_host, HOSTNAME, asm_home) primary_lsnr_port_num = p_lsnr_info['port'] standby_lsnr_port_num = s_lsnr_info['port'] else: primary_lsnr_port_num = oracletools.get_oracle_listener_port( oracle_home=ORACLE_HOME) standby_lsnr_port_num = oracletools.get_oracle_listener_port( oracle_home=ORACLE_HOME, host=standby_host) steplog.info('Found the listener port numbers')
def main(): print("-" * 80) steplog.info('Validating rollback fixpack parameters...') print("-" * 80) if ostools.is_windows(): steplog.error('This workflow runs on unix platforms only.') sys.exit(1) p1 = threading.Thread(name='create_backup_dir', target=create_backup_dir, args=(params, )) p2 = threading.Thread(name='validate_db2_installation', target=validate_db2_installation, args=(params['Current DB2 Installation Location'], )) p3 = threading.Thread(name='check_required_parameters', target=check_required_parameters, args=(params, )) p1.start() p2.start() p3.start() p1.join() p2.join() p3.join() Validator.register(commonvalidation.check_filespace_requirements, args=[setup_filespace_requirements()]) Validator.validate() failures = Validator.str_failed_results() if failures: msg = 'Error(s) validating parameters for Rollback DB2 Fixpack :\n\n%s' % failures steplog.info(msg) steplog.error(msg) sys.exit(1) fixpack_number = db2tools.get_installed_fixpack_version( params['Current DB2 Installation Location']) params['Fixpack Number'] = fixpack_number print_header(params) print("-" * 80) steplog.info( 'Validation for rollback fixpack parameters successful. You may proceed.' ) print("-" * 80)
def main(): print("-" * 80) steplog.info("Verify post rollback fixpack") print("-" * 80) steplog.info( 'Comparing instance version with fixpack version that you want to rollback.' ) fixpack_version, instance_version = db2tools.get_instance_version( params['DB2 Installation Location']) print("Current instance version", instance_version) print("-" * 80) if int(instance_version) == int(params['Fixpack Number']): steplog.error("Fixpack level matchs: %s = %s. Rollback did not occur" % (instance_version, params['Fixpack Number'])) return_code = 1 else: steplog.info( "Fixpack level do not match: %s != %s. Fixpack successfully rolled back." % (instance_version, params['Fixpack Number'])) return_code = 0 print("-" * 80) sys.exit(return_code)
def get_db2_binary_build_version(STAGE_DIRECTORY): """ This method is to find DB2 version from the unzip binary """ val = "" path_for_base_db2_file = "" db2_version_list = ['10.1', '10.5', '9.7', '9.5'] dir_list = glob.glob("%s/*" % (STAGE_DIRECTORY)) for elm in dir_list: fixpack_type = os.path.split(elm)[-1] if fixpack_type.startswith('universal'): steplog.info("This is a universal fixpack binary : %s" % fixpack_type) server_dirname = elm steplog.debug("Server Directory Name : %s " % server_dirname) steplog.debug("Stage Directory Path : %s " % STAGE_DIRECTORY) if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2') elif fixpack_type.startswith('server'): steplog.info("This is a server fixpack binary : %s" % fixpack_type) server_dirname = elm steplog.debug("Server Directory Name : %s " % server_dirname) steplog.debug("Stage Directory Path : %s " % STAGE_DIRECTORY) if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2') if os.path.exists(path_for_base_db2_file): steplog.info("DB2 binary is found and it is uncompressed") try: files = os.listdir(path_for_base_db2_files) for item in files: if item.startswith('spec'): val = item steplog.debug("File to extract the fixpack version build number : %s" % val) spec_file = os.path.join(path_for_base_db2_files, 'spec') if os.path.isfile(spec_file): print ("Spac file exists and reading") with open(spec_file) as fh: for line in fh: if "special_" in line: build_level_list = line.split("=") build_level = build_level_list[-1] build_num = build_level[8:] steplog.info("Special fixpack build level : %s " % build_num) return build_num except IOError: steplog.info('There is no file exists') else: steplog.info("DB2 binary may have not unzipped")
def get_db2_binary_fixpack_version(STAGE_DIRECTORY): """ This method is to find DB2 version from the unzip binary """ val = "" path_for_base_db2_file = "" db2_version_list = ['10.1', '10.5', '9.7', '9.5'] dir_list = glob.glob("%s/*" % (STAGE_DIRECTORY)) for elm in dir_list: fixpack_type = os.path.split(elm)[-1] if fixpack_type.startswith('universal'): steplog.info("This is a universal fixpack binary : %s" % fixpack_type) server_dirname = elm steplog.debug("Server Directory Name : %s " % server_dirname) steplog.debug("Stage Directory Path : %s " % STAGE_DIRECTORY) if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'aix', 'FILES') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'linuxamd64', 'FILES') elif fixpack_type.startswith('server'): steplog.info("This is a server fixpack binary : %s" % fixpack_type) server_dirname = elm steplog.debug("Server Directory Name : %s " % server_dirname) steplog.debug("Stage Directory Path : %s " % STAGE_DIRECTORY) if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'aix', 'FILES') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'linuxamd64', 'FILES') if os.path.exists(path_for_base_db2_file): steplog.info("DB2 binary is found and it is uncompressed") try: files = os.listdir(path_for_base_db2_files) for item in files: if item.startswith('INSTANCE_SETUP_SUPPORT_'): val = item steplog.info("Found the file to extract the fixpack version : %s" % val) break s1 = re.compile(r'_(\d+\.\d+)\.', re.DOTALL) match_found = s1.search(val) if match_found: db2_version_from_file = match_found.group(1) if db2_version_from_file in db2_version_list: steplog.info("This is the valid DB2 version : %s" % db2_version_from_file) pat = re.compile(r"INSTANCE_SETUP_SUPPORT_\d+\.\d+\.\d+\.(\d+)_") fp_found = pat.search(val) return fp_found.group(1) else: return False except IOError: steplog.info('There is no file exists') else: steplog.info("DB2 binary may have not unzipped")
def get_db2_binary_fixpack_version(STAGE_DIRECTORY): """ This method is to find DB2 version from the unzip binary """ val = "" dirnames = glob.glob("%s/%s" % (STAGE_DIRECTORY, "server*")) #dirnames = glob.glob("%s/%s" % (STAGE_DIRECTORY, "universal*")) dirname = dirnames[0] server_dirname = os.path.split(dirname)[-1] db2_version_list = ['10.1', '10.5', '9.7', '9.5'] if server_dirname path_for_base_db2_file = "" if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'aix', 'FILES') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'linuxamd64', 'FILES') else: steplog.warn("Media contains unsupported OS") return False if os.path.exists(path_for_base_db2_file): steplog.info("DB2 binary is found and it is uncompressed") try: files = os.listdir(path_for_base_db2_files) for item in files: if item.startswith('INSTANCE_SETUP_SUPPORT_'): val = item steplog.info(" We found the file for finding the version : %s" % val) break s1 = re.compile(r'_(\d+\.\d+)\.', re.DOTALL) match_found = s1.search(val) if match_found: db2_version_from_file = match_found.group(1) if db2_version_from_file in db2_version_list: steplog.info("This is the valid DB2 version : %s" % db2_version_from_file) pat = re.compile(r"INSTANCE_SETUP_SUPPORT_\d+\.\d+\.\d+\.(\d+)_") fp_found = pat.search(val) return fp_found.group(1) else: return False except IOError: steplog.info('There is no file exists') else: steplog.info("DB2 binary have not unzipped") def main(): Instance_line={} params = parametertools.parse_dma_params() install_path = params['Install Path'] db2_install = db2tools.DB2Installation(install_path) db2_install.find_instances_and_das() ## Extract the instance details found on the target machine ## Instance_line = db2_install.instances ## First Instance in the instances found on the target ## if Instance_line: first_inst_name = Instance_line.keys()[0] instance_to_set = first_inst_name steplog.debug(first_inst_name) if instance_to_set: ## Setup the default DB2 Instance on target machine environment ## os.environ["DB2INSTANCE"] = instance_to_set.strip() steplog.debug(os.environ["DB2INSTANCE"]) inst_fix_pack = get_installed_fixpack_version(install_path) media_fixpack = get_db2_binary_fixpack_version(params['Stage Archive']) if not int(media_fixpack) > int(inst_fix_pack): steplog.error("A greater version or same version of Fix pack %s is already installed" % inst_fix_pack) sys.exit(1) states = get_software_states(db2_install) shutdown_software(db2_install, states) for key, value in states.items(): if isinstance(value, list): params[key] = ','.join(value) else: params[key] = value parametertools.print_header(params) def get_software_states(db2_install): up_instances, _ = db2_install.get_instance_up_down_states() up_licd, _ = db2_install.get_instance_license_daemon_states() is_das_up = False if db2_install.das is None else db2_install.das.up_down == 'up' is_fmc_up = db2_install.get_fmc_pid() is not None auto_starts = [] if is_fmc_up: auto_starts, _ = db2_install.get_auto_start_states() states = { 'Up Instances': up_instances, 'Up LICDs': up_licd, 'Is DAS Up': is_das_up, 'Auto Starts': auto_starts, } return states def shutdown_software(db2_install, states): db2_install.force_applications_shutdown() db2_install.terminate_instances() db2_install.set_instance_up_down_states(offs=states['Up Instances']) db2_install.set_instance_license_daemon_states(offs=states['Up LICDs']) if states['Is DAS Up']: db2_install.das.up_down = 'down' if ostype.is_aix(): ostools.run_command('/usr/sbin/slibclean') auto_starts = states['Auto Starts'] if auto_starts: db2_install.set_auto_start_states(offs=auto_starts) db2_install.ip_clean_instances() if __name__ == '__main__': main()
def modify_response(file_name): response = open(file_name, "r") lines = response.readlines() response.close() response = open(file_name, "w") for line in lines: if line.upper().startswith('GDBNAME'): steplog.info("Updating GDBNAME in %s." % file_name) response.write('GDBNAME = "%s"\n' % DATABASE_NAME) elif line.upper().startswith('SID'): steplog.info("Updating SID in %s." % file_name) response.write('SID = "%s"\n' % ORACLE_SID) elif line.upper().startswith('NODELIST'): steplog.info("Updating NODELIST in %s." % file_name) if NODE_LIST: response.write('NODELIST = "%s"\n' % NODE_LIST) elif line.upper().startswith('SYSTEMPASSWORD'): if pythontools.is_dma_param_null(DBCA_PASSWORD_SYSTEM): system_password = line.split('=')[1].strip().strip('"') response.write('SYSTEMPASSWORD = "******"\n' % system_password) else: response.write('SYSTEMPASSWORD = "******"\n' % DBCA_PASSWORD_SYSTEM) elif line.upper().startswith('TEMPLATENAME'): if TEMPLATE_NAME: steplog.info("Updating TEMPLATENAME in %s." % file_name) response.write('TEMPLATENAME = "%s"\n' % TEMPLATE_NAME) else: response.write(line) elif line.upper().startswith('VARIABLESFILE'): if VARIABLES_FILE: steplog.info("Updating VARIABLESFILE in %s." % file_name) response.write('VARIABLESFILE = "%s"\n' % VARIABLES_FILE) else: response.write(line) elif line.upper().startswith('CREATEASCONTAINERDATABASE'): if CONTAINER_DATABASE: steplog.info("Updating CREATEASCONTAINERDATABASE in %s." % file_name) response.write('CREATEASCONTAINERDATABASE="true"\n') else: response.write(line) else: response.write(line) response.close() steplog.info("Success.")
def get_db2_binary_fixpack_version(STAGE_DIRECTORY): """ This method is to find DB2 version from the unzip binary """ val = "" #dirnames = glob.glob("%s/%s" % (STAGE_DIRECTORY, "server*")) #dirnames = glob.glob("%s/%s" % (STAGE_DIRECTORY, "universal*")) path_for_base_db2_file = "" db2_version_list = ['10.1', '10.5', '9.7', '9.5'] dir_list = glob.glob("%s/*" % (STAGE_DIRECTORY)) for elm in dir_list: if os.path.split(elm)[-1] == 'universal': steplog.info("This fixpack is a universal fixpack") server_dirname = elm if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'aix', 'FILES') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'linuxamd64', 'FILES') elif os.path.split(elm)[-1] == 'server': steplog.info("This fixpack is a server fixpack") server_dirname = elm if ostools.is_aix(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'aix', 'FILES') elif ostools.is_linux(): path_for_base_db2_files = os.path.join(STAGE_DIRECTORY, server_dirname, 'db2', 'linuxamd64', 'FILES') else: steplog.warn("Media contains unsupported OS") return False if os.path.exists(path_for_base_db2_file): steplog.info("DB2 binary is found and it is uncompressed") try: files = os.listdir(path_for_base_db2_files) for item in files: if item.startswith('INSTANCE_SETUP_SUPPORT_'): val = item steplog.info(" We found the file for finding the version : %s" % val) break s1 = re.compile(r'_(\d+\.\d+)\.', re.DOTALL) match_found = s1.search(val) if match_found: db2_version_from_file = match_found.group(1) if db2_version_from_file in db2_version_list: steplog.info("This is the valid DB2 version : %s" % db2_version_from_file) pat = re.compile(r"INSTANCE_SETUP_SUPPORT_\d+\.\d+\.\d+\.(\d+)_") fp_found = pat.search(val) return fp_found.group(1) else: return False except IOError: steplog.info('There is no file exists') else: steplog.info("DB2 binary have not unzipped")
def get_policy_params(): #verify if a server pool already exists -> srvctl status srvpool command = os.path.join(CRS_HOME, "bin", "srvctl") steplog.info("Running command %s" % command + " status srvpool") status_srvpool = os.popen(command + " status srvpool").read() steplog.info("Srvpool status: %s" % status_srvpool) matches = re.finditer('Server pool name: (.*)', status_srvpool) server_pools = [ match.group(1) for match in matches if match.group(1) not in ("Free", "Generic") ] srvpool_name = "%sClusterPool" % NODE_LIST.split(',')[0][0:4] if len(server_pools) == 0: steplog.info("No server pool exists on the system.") steplog.info("%s server pool will be created." % srvpool_name) create_srvpool = "true" else: steplog.info("%d server pools found on the system." % len(server_pools)) steplog.info("%s server pool will be used." % server_pools[0]) create_srvpool = "false" srvpool_name = server_pools[0] return """CREATESERVERPOOL = "%s" FORCE = "false" SERVERPOOLNAME = %s CARDINALITY = %d""" % (create_srvpool, srvpool_name, len(NODE_LIST.split(',')))