Skip to content

Commit

Permalink
Added (incomplete) first crack at customer facing ec2 start scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkraljevic committed Sep 22, 2013
1 parent db1e76e commit 2c0911e
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ec2/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

This directory contains scripts to help launch an H2O cluster in EC2.
You must install the boto python library.

http://boto.readthedocs.org/en/latest/
http://www.amazon.com/Python-and-AWS-Cookbook-ebook/dp/B005ZTO0UW/ref=sr_1_1?ie=UTF8&qid=1379879111&sr=8-1&keywords=python+aws

Work in progress...

110 changes: 110 additions & 0 deletions ec2/h2o-cluster-launch-instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python

import os
import time
import boto
import boto.ec2


# Environment variables you MUST set.
# -----------------------------------
#
# os.environ['AWS_ACCESS_KEY_ID'] = '...'
# os.environ['AWS_SECRET_ACCESS_KEY'] = '...'


# Options you MUST tailor to your own AWS account.
# ------------------------------------------------

# SSH key pair name.
keyName = '0xdata_Big'

# AWS security group name.
# Note:
# H2O uses TCP and UDP ports 54321 and 54322.
# RStudio uses TCP port 8787.
securityGroupName = 'SecurityDisabled'


# Options you might want to change.
# ---------------------------------

numInstancesToLaunch = 2
instanceType = 'm1.large'
instanceNameRoot = 'H2ORStudioDemo'


# Options to help debugging.
# --------------------------

debug = 0
# debug = 1
dryRun = False
# dryRun = True


# Options you should not change unless you really mean to.
# --------------------------------------------------------

regionName = 'us-east-1'
amiId = 'ami-634f050a'


#--------------------------------------------------------------------------
# No need to change anything below here.
#--------------------------------------------------------------------------

publicFileName = 'nodes-public'
privateFileName = 'nodes-private'

if not dryRun:
fpublic = open(publicFileName, 'w')
fprivate = open(privateFileName, 'w')

print 'Using boto version', boto.Version
if (debug):
boto.set_stream_logger('h2o-ec2')
ec2 = boto.ec2.connect_to_region(regionName, debug=debug)

print 'Launching', numInstancesToLaunch, 'instances.'

reservation = ec2.run_instances(
image_id=amiId,
min_count=numInstancesToLaunch,
max_count=numInstancesToLaunch,
key_name=keyName,
instance_type=instanceType,
security_groups=[securityGroupName],
dry_run=dryRun
)

for i in range(numInstancesToLaunch):
instance = reservation.instances[i]
print 'Waiting for instance', i, '...'
while instance.state != 'running':
print ' .'
time.sleep(5)
instance.update()
print ' instance', i, 'is up.'
name = instanceNameRoot + str(i)
instance.add_tag('Name', value=name)

print
print 'Creating output files: ', publicFileName, privateFileName
print

for i in range(numInstancesToLaunch):
instance = reservation.instances[i]
instanceName = ''
if 'Name' in instance.tags:
instanceName = instance.tags['Name'];
print 'Instance', i
print ' Name: ', instanceName
print ' PUBLIC: ', instance.public_dns_name
print ' PRIVATE:', instance.private_ip_address
print
fpublic.write(instance.public_dns_name + '\n')
fprivate.write(instance.private_ip_address + '\n')

fpublic.close()
fprivate.close()
57 changes: 57 additions & 0 deletions ec2/h2o-cluster-print-info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

import os
import time
import boto
import boto.ec2


# Environment variables you MUST set.
# -----------------------------------
#
# os.environ['AWS_ACCESS_KEY_ID'] = '...'
# os.environ['AWS_SECRET_ACCESS_KEY'] = '...'


# Options you might want to change.
# ---------------------------------

instanceNameRoot = 'H2ORStudioDemo'


# Options to help debugging.
# --------------------------

debug = 0
# debug = 1


# Options you should not change unless you really mean to.
# --------------------------------------------------------

regionName = 'us-east-1'


#--------------------------------------------------------------------------
# No need to change anything below here.
#--------------------------------------------------------------------------

print 'Using boto version', boto.Version
if (debug):
boto.set_stream_logger('h2o-ec2')
ec2 = boto.ec2.connect_to_region(regionName, debug=debug)

reservations = ec2.get_all_instances()
for reservation in reservations:
instances = reservation.instances
for instance in instances:
instanceName = '(empty)'
if 'Name' in instance.tags:
instanceName = instance.tags['Name'];
if instanceName.startswith(instanceNameRoot):
print ' ', instance
print ' ', instanceName
print ' ', instance.public_dns_name
print ' ', instance.ip_address
print ' ', instance.private_dns_name
print ' ', instance.private_ip_address

0 comments on commit 2c0911e

Please sign in to comment.