Exemple #1
0
def create_server():
    print(green("Creating Rackspace server..."))

    try:
        from cloudservers import CloudServers
        from cloudservers.exceptions import NotFound
    except ImportError:
        raise Exception("python-cloudservers libray required "
        				"for creating servers with Rackspace")

    cs = CloudServers(
    	get_or_prompt('rackspace_username', 'Username'),
    	get_or_prompt('rackspace_apikey', 'API Key'))

    image = cs.images.find(
    	id=int(get_or_prompt('rackspace_image', 'Server Image ID')))
    
    flavor = cs.flavors.find(
    	id=int(get_or_prompt('rackspace_flavor', 'Server Flavor ID')))

    server = cs.servers.create(
    	get_or_prompt('rackspace_servername', 'Server Name'), 
    	image=image, 
    	flavor=flavor)
    
    while True:
        while True:
            try:
                server = cs.servers.find(id=server.id)
                break;
            except NotFound:
                print(yellow('Waiting for new server'))
                time.sleep(10)
                pass

        if server.status != 'ACTIVE':
            print(yellow("Server status: %s" % server.status))
            time.sleep(10)
            continue
        break

    print(green("Server status: %s" % server.status))
    print(green("Update the server password:"******"Instance state: %s" % server.status))
    print(green("Public IP: %s" % public_ip))
    
    return public_ip
Exemple #2
0
def create_server():
    """Creates an EC2 Server"""

    try:
        import boto
    except ImportError:
        sys.exit("boto library required for creating servers with Amazon.")

    print(green("Creating EC2 server"))

    conn = boto.connect_ec2(
        get_or_prompt('ec2_key', 'API Key'),
        get_or_prompt('ec2_secret', 'API Secret'))
    
    reservation = conn.run_instances(
        get_or_prompt(
            'ec2_ami', 'AMI ID', 'ami-fd589594'),
        instance_type=get_or_prompt(
            'ec2_instancetype', 'Instance Type', 't1.micro'),
        key_name=get_or_prompt(
            'ec2_keypair', 'Key Pair'),
        security_groups=get_or_prompt_list(
            'ec2_secgroups', 'Security Groups'))
    
    instance = reservation.instances[0]
    
    time.sleep(3)

    tag = get_or_prompt('ec2_tag', 'Instance Tag (blank for none)', '').strip()

    if len(tag) > 0:
        conn.create_tags([instance.id], {"Name": tag})
    
    while instance.state != u'running':
        print(yellow("Instance state: %s" % instance.state))
        time.sleep(10)
        instance.update()

    print(green("Instance state: %s" % instance.state))
    print(green("Public dns: %s" % instance.public_dns_name))
    print(green("Waiting 30 seconds for server to boot"))
    
    time.sleep(30)

    return instance.public_dns_name