def infer_oracle_home(primary_host, instance_name, oratab_file): global oracle_home is_valid = True cmd = '/usr/bin/ssh %s ls -l %s' % (primary_host, oratab_file) output, errors, rc = ostools.run_command(cmd) if rc != 0: return False, 'Unable to reference standard oratab file location on primary host\n' filename = output.strip().split().pop() if filename != oratab_file: steplog.error('Standard path for oratab file of: %s not valid\n' % oratab_file) is_valid = False cmd = '/usr/bin/ssh %s /bin/cat %s' % (primary_host, oratab_file) output, errors, rc = ostools.run_command(cmd) if rc != 0: steplog.error("Oratab file not accessible for unknown reason.") is_valid = False entries = [line.strip() for line in output.split('\n')] matches = [entry.split(':')[1] for entry in entries if entry.split(':')[0] == instance_name] if not matches: steplog.error('Unable to match any oratab entries to target instance name: %s\n' % instance_name) is_valid = False oracle_home = matches[0] # take the oracle_home value for first instance that matched return is_valid, "Completed Oratab file validation and ORACLE_HOME discovery"
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()
def get_uncompressed_binary_file_size(file = None): file = "v10.5_linuxx64_server.tar.gz" keys = [] values = [] if not file: raise "Value Error. No input file is provided" else: command = 'gzip -l %s' % file steplog.info("command : %s" % command) out, err, rc = ostools.run_command(command) print "output : %s " % out print "error : %s " % err print "rc : %s " % rc if rc == 0: for line in out.readline(): if "compressed" in line: keys = line.split() else: values = line.split() if keys and values: bin_size_dict = dict(zip(keys, values)) compressed_size = keys['compressed'] uncompressed_size = keys['uncompressed'] print "compressed_size : %s " % compressed_size print "uncompressed_size : %s" % uncompressed_size
def get_installed_fixpack_version(install_path): cmd = os.path.join(install_path, "bin", "db2level") (out, err, rc) = ostools.run_command(cmd) dat = " ".join(out.splitlines()) pat = re.compile(r'Fix\s+Pack\s+\"(\d+)\"') x = pat.search(dat) if x is None: raise EnvironmentError("Invalid output from db2level") return x.group(1)
def get_installed_fixpack_build(install_path): cmd = os.path.join(install_path, "bin", "db2level") out, err, rc = ostools.run_command(cmd) lines = " ".join(out.splitlines()) match = re.compile(r'special_(\d+)') match_found = match.search(lines) if match_found: return match_found.group(1) else: return ''
def validate_db2_installation(db2_home=None): """ To validate and ensure that if the current db2 installation is good without any binary file corruption. """ print threading.currentThread().getName(), 'Starting' if not os.path.exists(db2_home): return False, "Invalid DB2 installation location specified. Please check" if not os.path.exists(os.path.join(db2_home, 'bin', 'db2')): return False, "Could not find DB2 command line processor. Installation might have been corrupted or incomplete" db2valpath = os.path.join(db2_home, 'bin', 'db2val') if not os.path.exists(db2valpath): return True, "db2val utility is not available for the current DB2 installation version. db2val cannot be run. Skipping this ..." else: out, err, rc = ostools.run_command( os.path.join(db2_home, "bin", "db2val")) if rc: return False, "Failed to run db2val to verify DB2 installation" if re.search("db2val command completed successfully. You may proceed", out): return True, "DB2 Installation found" return False, "Invalid DB2 Installation Directory specified"
def get_scan_port(oracle_home, host=None, user=None): """ Gets the RAC scan name """ env_str = oracletools.get_oracle_env_string(oracle_home) if host: command = 'ssh %s "%s; %s/bin/srvctl config scan_listener"' % ( host, env_str, oracle_home) else: command = "%s; %s/bin/srvctl config scan_listener" % (env_str, oracle_home) if user: output, err, rc = ostools.sudo_run_command(command, user=user) else: output, err, rc = ostools.run_command(command) if rc != 0: raise ValueError('Unable to run srvctl config scan command') m = re.search("TCP:(.*)", output, re.IGNORECASE) if not m: raise ValueError('Unable to find scan port') steplog.debug("RAC Scan name = %s" % m.group(1)) return m.group(1)
def update_listenerora_all_nodes(primary_hosts, standby_hosts, status): is_valid = True # Algorithm: # If the Listener entry or LISTENER_SCAN1 entry are missing, add them. # Next: # For each line in the listener.ora file (or the defaults added) that # starts with 'LISTENER' there must be a SID_LIST_%s % <that listener # name> with the appropriate details. for index, host in enumerate(primary_hosts + standby_hosts): steplog.debug('host: %r' % host) if host in standby_hosts: n = index + 1 - len(primary_hosts) prefix_sid_listener = STANDBY_PREFIX else: n = index + 1 prefix_sid_listener = '' if ENV_TYPE == 'GRID_CLUSTER': instance = ORACLE_SID[:-1] + str(n) else: instance = ORACLE_SID listener_lines = [] amended_content = [] catter = '/bin/cat %s' % lsnr_file_location out, err, rc = ostools.run_command(catter, host=host) if rc != 0: steplog.error('Failed to execute %s command on server %s' % (catter, host)) is_valid = False status[host] = False else: lf_lines = out.split('\n') listener_lines = [ line for line in lf_lines if line.strip() and not line.startswith('ADR_BASE') and not line.startswith('SID_LIST') and line[0] not in [' ', '#'] ] # Add defaults, unless there was an error executing the command above if len(listener_lines) == 0 and is_valid: listener_augment = LISTENER_ENTRY % ('LISTENER', DB_UNIQUE_NAME, ORACLE_SID) default_scan_lsnr_augment = LISTENER_ENTRY % ( 'LISTENER_SCAN1', DB_UNIQUE_NAME, ORACLE_SID) steplog.debug( 'No listener information found in listener.ora on host %s' % host) # Add default, add it to the listener lines too so that # sid_list_listener lines get created as well. amended_content.append(listener_augment) listener_lines.append(listener_augment) # TO RE-EVALUATE !!!! if ENV_TYPE == 'GRID_CLUSTER': amended_content.append(default_scan_lsnr_augment) listener_lines.append(default_scan_lsnr_augment) for line in listener_lines: line_items = [x.strip() for x in line.split('=')] lsnr_name = line_items[0] steplog.debug('lsnr_name: %r' % lsnr_name) dg_broker_desc = SID_LISTENER_DESC % ( "%s%s_DGMGRL" % (prefix_sid_listener, DB_UNIQUE_NAME), "%s%s" % (prefix_sid_listener, instance)) instance_desc = SID_LISTENER_DESC % ( "%s%s" % (prefix_sid_listener, DB_UNIQUE_NAME), "%s%s" % (prefix_sid_listener, instance)) s_lsnr_augment = SID_LISTENER_ENTRY % (lsnr_name, dg_broker_desc + instance_desc) # remove any already existing same SID_LIST_LISTENER entry of the corresponding listener in listener.ora file sid_list_listener_pattern = "SID_LIST_%s\s*=\s*\(SID_LIST" % lsnr_name removed = oracletools.remove_existing_network_config( lsnr_file_location, sid_list_listener_pattern, host) while removed: removed = oracletools.remove_existing_network_config( lsnr_file_location, sid_list_listener_pattern, host) # add this entry to listener.ora file amended_content.append(s_lsnr_augment) ok = True if len(amended_content) > 0: ok = ostools.write_file_remote(lsnr_file_location, '\n'.join(amended_content), host, append=True) if asm_user: ostools.set_file_owner(lsnr_file_location, asm_user, host) else: ostools.set_file_owner(lsnr_file_location, ORACLE_USER, host) if not ok or not is_valid: status[host] = False is_valid = False steplog.error('Failed attempt to augment listener.ora on host %r' % host) return is_valid