Skip to content
Browse files

Integrating with fabric.

  • Loading branch information...
1 parent f73e69c commit f5985be760930a969792e0c6150349cd511bae29 @mnielsen committed Jul 5, 2012
Showing with 11 additions and 5 deletions.
  1. +10 −4 ec2.py
  2. +1 −1 fabfile.py
View
14 ec2.py
@@ -126,6 +126,15 @@ def check_environment_variables_exist(*args):
ec2_conn = EC2Connection(os.environ["AWS_ACCESS_KEY_ID"],
os.environ["AWS_SECRET_ACCESS_KEY"])
+def public_dns_names(cluster_name):
+ if cluster_name not in clusters:
+ print ("Cluster name %s not recognized. Exiting ec2.ec2_hosts()." %
+ cluster_name)
+ sys.exit()
+ else:
+ cluster = clusters[cluster_name]
+ return [instance["public_dns_name"] for instance in cluster]
+
def create(cluster_name, n, instance_type):
"""
Create an EC2 cluster with name `cluster_name`, and `n` instances
@@ -179,13 +188,10 @@ def shutdown(cluster_name):
print "No cluster with the name %s exists. Exiting." % cluster_name
sys.exit()
print "Shutting down cluster %s." % cluster_name
- cluster = clusters[cluster_name]
- cluster_public_dns_names = [instance["public_dns_name"]
- for instance in cluster]
all_running_instances = get_running_instances()
all_public_dns_names = [instance.public_dns_name
for instance in all_running_instances]
- for public_dns_name in cluster_public_dns_names:
+ for public_dns_name in public_dns_names(cluster_name):
j = all_public_dns_names.index(public_dns_name)
instance = all_running_instances[j]
ec2_conn.terminate_instances([instance.id ])
View
2 fabfile.py
@@ -22,7 +22,7 @@
import config
import ec2
-env.hosts = [ec2.get_running_instance().public_dns_name]
+env.hosts = ec2.public_dns_names("mini_qa")
env.user = 'ubuntu'
env.key_filename = ["%s/%s.pem" % \
(os.environ["AWS_HOME"], os.environ["AWS_KEYPAIR"])]

0 comments on commit f5985be

Please sign in to comment.
Something went wrong with that request. Please try again.