Last active
August 29, 2015 14:02
-
-
Save jonaslejon/f45dc0352eba33b0ae64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
## | |
## Jonas Lejon 2014 | |
## | |
## sudo pip install apache-libcloud names | |
import os, sys, time | |
import names | |
from libcloud.compute.types import Provider | |
from libcloud.compute.providers import get_driver | |
import libcloud.security | |
libcloud.security.CA_CERTS_PATH = ['ca-bundle.crt'] # from Mozilla | |
EC2_ACCESS_ID = '' # Paste your Amazon EC2 credentials here | |
EC2_SECRET_KEY = '' | |
userdata = """#cloud-config | |
coreos: | |
etcd: | |
# generate a new token for each unique cluster from https://discovery.etcd.io/new | |
discovery: https://discovery.etcd.io/unique_token_here | |
# multi-region and multi-cloud deployments need to use $public_ipv4 | |
addr: $public_ipv4:4001 | |
peer-addr: $public_ipv4:7001 | |
units: | |
- name: etcd.service | |
command: start | |
- name: fleet.service | |
command: start | |
""" | |
#EC2Driver = get_driver(Provider.EC2) | |
EC2Driver = get_driver(Provider.EC2_EU_WEST) | |
conn = EC2Driver(EC2_ACCESS_ID, EC2_SECRET_KEY) | |
hostname = "coreos-" + names.get_first_name(gender='female').lower() | |
print "# Starting EC2 server with hostname",hostname | |
MY_SIZE = 't1.micro' | |
#MY_IMAGE = "ami-8f30fff8" # CoreOS beta at eu-west-1 | |
MY_IMAGE = "ami-87a769f0" # CoreOS alpha at eu-west-1 | |
sizes = conn.list_sizes() | |
images = conn.list_images() | |
size = [s for s in sizes if s.id == MY_SIZE][0] | |
image = [i for i in images if i.id == MY_IMAGE][0] | |
node = conn.create_node(name=hostname, image=image, size=size, ex_keyname="coreos", ex_userdata=userdata, ex_securitygroup="coreos") | |
nodes = conn.list_nodes() | |
time.sleep(5) | |
while nodes[-1].state != 0: | |
time.sleep(5) | |
print " - Wait.." | |
nodes = conn.list_nodes() | |
print "Found IP:",nodes[-1].public_ips[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment