Ejemplo n.º 1
0
def run(args, logging):
    """
    Runs the cmd executor

    :param args: A NameSpace object with the arguments required
    :param logging: A python logging object
    :return: An exit code
    """
    hostname = build_data.read(args.build_id, 'instance', 'public_ip_address')

    client = SSHClient()
    client.set_missing_host_key_policy(AutoAddPolicy())

    logging.info('Connecting to remote host "{0}"...'.format(hostname))
    client.connect(hostname,
                   port=args.port,
                   username=args.username,
                   key_filename=args.key_filename,
                   timeout=args.timeout)

    logging.info('Executing command "{0}"...'.format(args.cmd))
    # pylint: disable=W0612
    stdin, stdout, stderr = client.exec_command(args.cmd)

    exit_code = stdout.channel.recv_exit_status()
    stdout = stdout.channel.makefile().read() or 'None'
    stderr = stderr.channel.makefile().read() or 'None'

    logging.info('Exit code...')
    logging.info(exit_code)
    logging.info('Standard out...')
    logging.info(stdout)
    logging.info('Standard error...')
    logging.info(stderr)
    return exit_code, stdout, stderr
Ejemplo n.º 2
0
def run(args, logging):
    """
    Runs the cmd executor

    :param args: A NameSpace object with the arguments required
    :param logging: A python logging object
    :return: An exit code
    """
    hostname = build_data.read(args.build_id, 'instance', 'public_ip_address')

    client = SSHClient()
    client.set_missing_host_key_policy(AutoAddPolicy())

    logging.info('Connecting to remote host "{0}"...'.format(hostname))
    client.connect(hostname, port=args.port, username=args.username,
                   key_filename=args.key_filename, timeout=args.timeout)

    logging.info('Executing command "{0}"...'.format(args.cmd))
    # pylint: disable=W0612
    stdin, stdout, stderr = client.exec_command(args.cmd)

    exit_code = stdout.channel.recv_exit_status()
    stdout = stdout.channel.makefile().read() or 'None'
    stderr = stderr.channel.makefile().read() or 'None'

    logging.info('Exit code...')
    logging.info(exit_code)
    logging.info('Standard out...')
    logging.info(stdout)
    logging.info('Standard error...')
    logging.info(stderr)
    return exit_code, stdout, stderr
Ejemplo n.º 3
0
def run(args, logging):
    """
    Terminates the AWS EC2 instance

    :param args: A NameSpace object with the arguments required
    :param logging: A python logging object
    :return: An exit code
    """
    instance_id = build_data.read(args.build_id, 'instance', 'id')
    logging.info('Read in config value id="{0}"...'.format(instance_id))

    ec2 = boto3.resource('ec2')
    for instance in ec2.instances.filter(InstanceIds=[instance_id]).all():
        instance.terminate()
    logging.info('Terminated instance "{0}"...'.format(instance_id))
    return 0, 'Terminated instance "{0}"'.format(instance_id), None
Ejemplo n.º 4
0
def run(args, logging):
    """
    Relieves a remote file using SFTP

    :param args: A NameSpace object with the arguments required
    :param logging: A python logging object
    :return: An exit code
    """
    hostname = build_data.read(args.build_id, 'instance', 'public_ip_address')

    client = SSHClient()
    client.set_missing_host_key_policy(AutoAddPolicy())

    logging.info('Connecting to remote host "{0}"...'.format(hostname))
    client.connect(hostname, port=args.port, username=args.username,
                   key_filename=args.key_filename, timeout=args.timeout)

    logging.info('Getting file "{0}"...'.format(args.remote_path))
    sftp_client = client.open_sftp()
    sftp_client.get(args.remote_path, args.local_path)
    return 0, None, None
Ejemplo n.º 5
0
def run(args, logging):
    """
    Relieves a remote file using SFTP

    :param args: A NameSpace object with the arguments required
    :param logging: A python logging object
    :return: An exit code
    """
    hostname = build_data.read(args.build_id, 'instance', 'public_ip_address')

    client = SSHClient()
    client.set_missing_host_key_policy(AutoAddPolicy())

    logging.info('Connecting to remote host "{0}"...'.format(hostname))
    client.connect(hostname,
                   port=args.port,
                   username=args.username,
                   key_filename=args.key_filename,
                   timeout=args.timeout)

    logging.info('Getting file "{0}"...'.format(args.remote_path))
    sftp_client = client.open_sftp()
    sftp_client.get(args.remote_path, args.local_path)
    return 0, None, None