def easy_ssh_between_lin_jump_and_agent(logger=None, agent_ip=None, lin_jump=None): logger.info( "Adding Agent VM %s KEY into Lin Jump known hosts file." % agent_ip) cmd = "sshpass -p \'%s\' ssh %s@%s {} {}".format(AGENT_ROOT_PWD, AGENT_DEFAULT_ROOT, agent_ip, SSH_KEYSCAN_COMMAND, agent_ip) logger.info("Scanning Agent VM SSH key on lin jump %s" % cmd) (return_code, ssh_key_stdout, stderr) = run_cmd_over_ssh( cmd, lin_jump, LIN_JUMP_USR, LIN_JUMP_PWD) if return_code != 0 or len(ssh_key_stdout) == 0 or "ssh-rsa" not in ssh_key_stdout: err_msg = "Failed getting Lin jump SSH key ssh key. Return code %d Error %s" % ( return_code, stderr) raise Exception(err_msg) logger.info("Execution stdout {%s} " % ssh_key_stdout) cmd = " echo \"{}\" >> {} ".format( ssh_key_stdout, LIN_JUMP_KNOWN_HOSTS) logger.debug("Appending Agent SSH key to Lin Jump known hosts file.") (return_code, stdout, stderr) = run_cmd_over_ssh(cmd, lin_jump, LIN_JUMP_USR, LIN_JUMP_PWD) if return_code != 0: err_msg = "Failed adding Agent SSH key into Lin jump known hosts file. Return Code %d Error %s" raise Exception(err_msg) logger.info("Finish adding Agent SSH key into Lin jump known hosts.")
def easy_ssh_agent(logger=None, agent_ip=None): logger.info("Adding Agent VM SSH KEY into local known hosts file.") cmd = "{} {}".format(SSH_KEYSCAN_COMMAND, agent_ip) logger.info("Scanning Agent VM SSH key command %s" % cmd) (return_code, ssh_key_stdout, stderr) = run_cmd_over_ssh( cmd, agent_ip, AGENT_DEFAULT_ROOT, AGENT_ROOT_PWD) if return_code != 0 or len(ssh_key_stdout) == 0 or "ssh-rsa" not in ssh_key_stdout: err_msg = "Failed getting Agent VM SSH key ssh key. Return code %d Error %s" % ( return_code, stderr) logger.error(err_msg) raise Exception(err_msg) logger.info("Execution stdout {%s} " % ssh_key_stdout) cmd = " echo \"{}\" >> {} ".format( ssh_key_stdout, AGENT_KNOWN_HOSTS_FILE_NAME) logger.debug("Appending Agent VM SSH key to local known hosts file.") (return_code, stdout, stderr) = run_local_sh_cmd(cmd) if return_code != 0: err_msg = "Failed adding Agent VM SSH entry in local known hosts file. Return Code %d Error %s" err_msg = err_msg % (return_code, stderr) logger.error(err_msg) raise Exception(err_msg) logger.info("Finish adding Agent VM SSH KEY into local known hosts file.")
def issue_start_cmd_to_agent(logger=None, agent_ip=None): cmd = "AgentLauncher -e -a" (rt, out, err) = run_cmd_over_ssh( cmd, agent_ip, AGENT_DEFAULT_ROOT, AGENT_ROOT_PWD) if rt != 0: err_msg = "Failed executing agent command." logger.error(err_msg) raise Exception(err_msg) logger.info("Successfully start execution. out \n %s \n err %s " % (out, err))
def sftp_run_list_to_agent(logger=None, agent_ip=None, local_run_list=None, lin_jump=None): jump_vm_sftp = SFTPManager(jump_vm_ip, LIN_JUMP_USR, LIN_JUMP_PWD) jump_vm_sftp.initiate_sftp_session() jump_vm_sftp.put_remote_file(local_run_list, LIN_JUMP_RUNLIST_LOC) jump_vm_sftp.terminate_sftp_session() logger.info("Uploading runlist.json to lin jump %s " % LIN_JUMP_RUNLIST_LOC) cmd = "sshpass -p \'%s\' scp %s %s@%s:%s".format(AGENT_ROOT_PWD, LIN_JUMP_RUNLIST_LOC, AGENT_DEFAULT_ROOT, agent_ip, AGENT_RUN_LIST_LOC) logger.info("Copy runlist.json from lin jump to agent <%s>" % cmd) (return_code, stdout, stderr) = run_cmd_over_ssh(cmd, lin_jump, LIN_JUMP_USR, LIN_JUMP_PWD) if return_code != 0: err_msg = "Failed copying runlist.json from lin jump to agent. Return Code %d Error %s" raise Exception(err_msg) logger.info("Finish copying runlist.json from lin jump to agent.")