Example #1
0
def list_testhosts(parser, options, args=None):
    if args:
        print_sub_help(parser, 'list_testhosts')
        return -1
    hostlist, config = read_config(options)
    for host in filter_config(hostlist, config, options):
        plat = config.get(host, 'platform')
        py = config.get(host, 'py')
        print host.ljust(30), plat.ljust(10), py
Example #2
0
def list_testhosts(parser, options, args=None):
    if args:
        print_sub_help(parser, 'list_testhosts')
        return -1
    hostlist, config = read_config(options)
    for host in filter_config(hostlist, config, options):
        plat = config.get(host, 'platform')
        py = config.get(host, 'py')
        print host.ljust(30), plat.ljust(10), py
def process_options(options):
    """Handles some config-related options so that the code
    doesn't have to be duplicated in multiple parsers.
    """
    hostlist, config = read_config(options)
    hosts = filter_config(hostlist, config, options)

    # find out which hosts are ec2 images, if any
    ec2_hosts = set()
    ec2_needed = False
    for host in hosts:
        if config.has_option(host, 'image_id'):
            ec2_hosts.add(host)
            ec2_needed = True
        elif config.has_option(host, 'instance_id'):
            ec2_needed = True

    if ec2_needed:
        from boto.ec2.connection import EC2Connection
        print 'connecting to EC2'
        conn = EC2Connection()
    else:
        conn = None

    for host in hosts:
        if host not in ec2_hosts and not config.has_option(host, 'addr'):
            if not config.has_option(host, 'instance_id'):
                raise RuntimeError("can't determine address for host %s" %
                                   host)

            # use instance_id to look up public dns name
            instance_id = config.get(host, 'instance_id')
            reslist = conn.get_all_instances([instance_id])
            if len(reslist) > 0:
                inst = reslist[0].instances[0]
            else:
                raise RuntimeError("can't find a running instance of host %s" %
                                   host)
            if inst.state == u'stopped':
                ec2_hosts.add(host)
            else:
                config.set(host, 'addr', inst.public_dns_name)

    options.hosts = hosts

    options.outdir = os.path.abspath(
        os.path.expanduser(os.path.expandvars(options.outdir)))

    return (config, conn, ec2_hosts)
def process_options(options):
    """Handles some config-related options so that the code
    doesn't have to be duplicated in multiple parsers.
    """
    hostlist, config = read_config(options)
    hosts = filter_config(hostlist, config, options)
        
    # find out which hosts are ec2 images, if any
    ec2_hosts = set()
    ec2_needed = False
    for host in hosts:
        if config.has_option(host, 'image_id'):
            ec2_hosts.add(host)
            ec2_needed = True
        elif config.has_option(host, 'instance_id'):
            ec2_needed = True

    if ec2_needed:
        from boto.ec2.connection import EC2Connection
        print 'connecting to EC2'
        conn = EC2Connection()
    else:
        conn = None

    for host in hosts:
        if host not in ec2_hosts and not config.has_option(host, 'addr'):
            if not config.has_option(host, 'instance_id'):
                raise RuntimeError("can't determine address for host %s" % host)
            
            # use instance_id to look up public dns name
            instance_id = config.get(host, 'instance_id')
            reslist = conn.get_all_instances([instance_id])
            if len(reslist) > 0:
                inst = reslist[0].instances[0]
            else:
                raise RuntimeError("can't find a running instance of host %s" % host)
            if inst.state == u'stopped':
                ec2_hosts.add(host)
            else:
                config.set(host, 'addr', inst.public_dns_name)
            
    options.hosts = hosts
    
    options.outdir = os.path.abspath(os.path.expanduser(
                                     os.path.expandvars(options.outdir)))

    return (config, conn, ec2_hosts)
Example #5
0
def list_testhosts(options):
    hostlist, config = read_config(options)
    for host in filter_config(hostlist, config, options):
        plat = config.get(host, 'platform')
        py = config.get(host, 'py')
        print host.ljust(30), plat.ljust(10), py
Example #6
0
def list_testhosts(options):
    hostlist, config = read_config(options)
    for host in filter_config(hostlist, config, options):
        plat = config.get(host, 'platform')
        py = config.get(host, 'py')
        print host.ljust(30), plat.ljust(10), py