def _send_scripts(domain_ip): remote_dir = './ssgts' archive_file = data.create_tarball('.') remote_archive_file = os.path.join(remote_dir, archive_file) machine = "root@{0}".format(domain_ip) logging.debug("Uploading scripts.") log_file_name = os.path.join(LogHelper.LOG_DIR, "data.upload.log") with open(log_file_name, 'a') as log_file: command = ("ssh", machine, "mkdir", "-p", remote_dir) if not _run_with_stdout_logging(command, log_file): logging.error("Cannot create directory {0}.".format(remote_dir)) return False command = ("scp", archive_file, "{0}:{1}".format(machine, remote_dir)) if not _run_with_stdout_logging(command, log_file): logging.error( "Cannot copy archive {0} to the target machine's directory {1}." .format(archive_file, remote_dir)) return False command = ("ssh", machine, "tar xf {0} -C {1}".format(remote_archive_file, remote_dir)) if not _run_with_stdout_logging(command, log_file): logging.error( "Cannot extract data tarball {0}.".format(remote_archive_file)) return False return remote_dir
def _send_scripts(domain_ip): remote_dir = './ssgts' archive_file = data.create_tarball('.') remote_archive_file = os.path.join(remote_dir, archive_file) machine = "root@{0}".format(domain_ip) logging.debug("Uploading scripts.") log_file_name = os.path.join(LogHelper.LOG_DIR, "data.upload.log") command = "ssh {0} mkdir -p {1}".format(machine, remote_dir) with open(log_file_name, 'a') as log_file: try: subprocess.check_call(shlex.split(command), stdout=log_file, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: logging.error("Cannot create directory {0}.".format(remote_dir)) return False command = "scp {0} {1}:{2}".format(archive_file, machine, remote_dir) subprocess.check_call(shlex.split(command), stdout=log_file, stderr=subprocess.STDOUT) command = "ssh {0} tar xf {1} -C {2}".format(machine, remote_archive_file, remote_dir) try: subprocess.check_call(shlex.split(command), stdout=log_file, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: logging.error( "Cannot extract data tarball {0}.".format(remote_archive_file)) return False return remote_dir
def _send_scripts(domain_ip): remote_dir = './ssgts' archive_file = data.create_tarball('.') remote_archive_file = os.path.join(remote_dir, archive_file) machine = "root@{0}".format(domain_ip) logging.debug("Uploading scripts.") log_file_name = os.path.join(LogHelper.LOG_DIR, "data.upload.log") with open(log_file_name, 'a') as log_file: args = common.SSH_ADDITIONAL_OPTS + (machine, "mkdir", "-p", remote_dir) try: _run_with_stdout_logging("ssh", args, log_file) except Exception: msg = "Cannot create directory {0}.".format(remote_dir) logging.error(msg) raise RuntimeError(msg) args = (common.SSH_ADDITIONAL_OPTS + (archive_file, "{0}:{1}".format(machine, remote_dir))) try: _run_with_stdout_logging("scp", args, log_file) except Exception: msg = ( "Cannot copy archive {0} to the target machine's directory {1}." .format(archive_file, remote_dir)) logging.error(msg) raise RuntimeError(msg) args = (common.SSH_ADDITIONAL_OPTS + (machine, "tar xf {0} -C {1}".format(remote_archive_file, remote_dir))) try: _run_with_stdout_logging("ssh", args, log_file) except Exception: msg = "Cannot extract data tarball {0}.".format( remote_archive_file) logging.error(msg) raise RuntimeError(msg) return remote_dir
def _send_scripts(domain_ip): remote_dir = './ssgts' archive_file = data.create_tarball('.') remote_archive_file = os.path.join(remote_dir, archive_file) machine = "root@{0}".format(domain_ip) logging.debug("Uploading scripts.") log_file_name = os.path.join(LogHelper.LOG_DIR, "data.upload.log") with open(log_file_name, 'a') as log_file: args = common.SSH_ADDITIONAL_OPTS + (machine, "mkdir", "-p", remote_dir) try: _run_with_stdout_logging("ssh", args, log_file) except Exception: msg = "Cannot create directory {0}.".format(remote_dir) logging.error(msg) raise RuntimeError(msg) args = (common.SSH_ADDITIONAL_OPTS + (archive_file, "{0}:{1}".format(machine, remote_dir))) try: _run_with_stdout_logging("scp", args, log_file) except Exception: msg = ("Cannot copy archive {0} to the target machine's directory {1}." .format(archive_file, remote_dir)) logging.error(msg) raise RuntimeError(msg) args = (common.SSH_ADDITIONAL_OPTS + (machine, "tar xf {0} -C {1}".format(remote_archive_file, remote_dir))) try: _run_with_stdout_logging("ssh", args, log_file) except Exception: msg = "Cannot extract data tarball {0}.".format(remote_archive_file) logging.error(msg) raise RuntimeError(msg) return remote_dir