Skip to content
Snippets Groups Projects
Commit 1651cc11 authored by Nicholas Chammas's avatar Nicholas Chammas Committed by Reynold Xin
Browse files

[EC2] Cleanup Python parens and disk dict

Minor fixes:
* Remove unnecessary parens (Python style)
* Sort `disks_by_instance` dict and remove duplicate `t1.micro` key

Author: Nicholas Chammas <nicholas.chammas@gmail.com>

Closes #2571 from nchammas/ec2-polish and squashes the following commits:

9d203d5 [Nicholas Chammas] paren and dict cleanup
parent 0dc2b636
No related branches found
No related tags found
No related merge requests found
...@@ -508,7 +508,7 @@ def tag_instance(instance, name): ...@@ -508,7 +508,7 @@ def tag_instance(instance, name):
break break
except: except:
print "Failed attempt %i of 5 to tag %s" % ((i + 1), name) print "Failed attempt %i of 5 to tag %s" % ((i + 1), name)
if (i == 5): if i == 5:
raise "Error - failed max attempts to add name tag" raise "Error - failed max attempts to add name tag"
time.sleep(5) time.sleep(5)
...@@ -530,7 +530,7 @@ def get_existing_cluster(conn, opts, cluster_name, die_on_error=True): ...@@ -530,7 +530,7 @@ def get_existing_cluster(conn, opts, cluster_name, die_on_error=True):
for res in reservations: for res in reservations:
active = [i for i in res.instances if is_active(i)] active = [i for i in res.instances if is_active(i)]
for instance in active: for instance in active:
if (instance.tags.get(u'Name') is None): if instance.tags.get(u'Name') is None:
tag_instance(instance, name) tag_instance(instance, name)
# Now proceed to detect master and slaves instances. # Now proceed to detect master and slaves instances.
reservations = conn.get_all_instances() reservations = conn.get_all_instances()
...@@ -545,7 +545,7 @@ def get_existing_cluster(conn, opts, cluster_name, die_on_error=True): ...@@ -545,7 +545,7 @@ def get_existing_cluster(conn, opts, cluster_name, die_on_error=True):
elif name.startswith(cluster_name + "-slave"): elif name.startswith(cluster_name + "-slave"):
slave_nodes.append(inst) slave_nodes.append(inst)
if any((master_nodes, slave_nodes)): if any((master_nodes, slave_nodes)):
print ("Found %d master(s), %d slaves" % (len(master_nodes), len(slave_nodes))) print "Found %d master(s), %d slaves" % (len(master_nodes), len(slave_nodes))
if master_nodes != [] or not die_on_error: if master_nodes != [] or not die_on_error:
return (master_nodes, slave_nodes) return (master_nodes, slave_nodes)
else: else:
...@@ -626,43 +626,43 @@ def wait_for_cluster(conn, wait_secs, master_nodes, slave_nodes): ...@@ -626,43 +626,43 @@ def wait_for_cluster(conn, wait_secs, master_nodes, slave_nodes):
def get_num_disks(instance_type): def get_num_disks(instance_type):
# From http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html # From http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html
# Updated 2014-6-20 # Updated 2014-6-20
# For easy maintainability, please keep this manually-inputted dictionary sorted by key.
disks_by_instance = { disks_by_instance = {
"m1.small": 1,
"m1.medium": 1,
"m1.large": 2,
"m1.xlarge": 4,
"t1.micro": 1,
"c1.medium": 1, "c1.medium": 1,
"c1.xlarge": 4, "c1.xlarge": 4,
"m2.xlarge": 1, "c3.2xlarge": 2,
"m2.2xlarge": 1, "c3.4xlarge": 2,
"m2.4xlarge": 2, "c3.8xlarge": 2,
"c3.large": 2,
"c3.xlarge": 2,
"cc1.4xlarge": 2, "cc1.4xlarge": 2,
"cc2.8xlarge": 4, "cc2.8xlarge": 4,
"cg1.4xlarge": 2, "cg1.4xlarge": 2,
"hs1.8xlarge": 24,
"cr1.8xlarge": 2, "cr1.8xlarge": 2,
"g2.2xlarge": 1,
"hi1.4xlarge": 2, "hi1.4xlarge": 2,
"m3.medium": 1, "hs1.8xlarge": 24,
"m3.large": 1,
"m3.xlarge": 2,
"m3.2xlarge": 2,
"i2.xlarge": 1,
"i2.2xlarge": 2, "i2.2xlarge": 2,
"i2.4xlarge": 4, "i2.4xlarge": 4,
"i2.8xlarge": 8, "i2.8xlarge": 8,
"c3.large": 2, "i2.xlarge": 1,
"c3.xlarge": 2, "m1.large": 2,
"c3.2xlarge": 2, "m1.medium": 1,
"c3.4xlarge": 2, "m1.small": 1,
"c3.8xlarge": 2, "m1.xlarge": 4,
"r3.large": 1, "m2.2xlarge": 1,
"r3.xlarge": 1, "m2.4xlarge": 2,
"m2.xlarge": 1,
"m3.2xlarge": 2,
"m3.large": 1,
"m3.medium": 1,
"m3.xlarge": 2,
"r3.2xlarge": 1, "r3.2xlarge": 1,
"r3.4xlarge": 1, "r3.4xlarge": 1,
"r3.8xlarge": 2, "r3.8xlarge": 2,
"g2.2xlarge": 1, "r3.large": 1,
"t1.micro": 0 "r3.xlarge": 1,
"t1.micro": 0,
} }
if instance_type in disks_by_instance: if instance_type in disks_by_instance:
return disks_by_instance[instance_type] return disks_by_instance[instance_type]
...@@ -785,7 +785,7 @@ def ssh(host, opts, command): ...@@ -785,7 +785,7 @@ def ssh(host, opts, command):
ssh_command(opts) + ['-t', '-t', '%s@%s' % (opts.user, host), ssh_command(opts) + ['-t', '-t', '%s@%s' % (opts.user, host),
stringify_command(command)]) stringify_command(command)])
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
if (tries > 5): if tries > 5:
# If this was an ssh failure, provide the user with hints. # If this was an ssh failure, provide the user with hints.
if e.returncode == 255: if e.returncode == 255:
raise UsageError( raise UsageError(
...@@ -820,18 +820,18 @@ def ssh_read(host, opts, command): ...@@ -820,18 +820,18 @@ def ssh_read(host, opts, command):
ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)]) ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)])
def ssh_write(host, opts, command, input): def ssh_write(host, opts, command, arguments):
tries = 0 tries = 0
while True: while True:
proc = subprocess.Popen( proc = subprocess.Popen(
ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)], ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)],
stdin=subprocess.PIPE) stdin=subprocess.PIPE)
proc.stdin.write(input) proc.stdin.write(arguments)
proc.stdin.close() proc.stdin.close()
status = proc.wait() status = proc.wait()
if status == 0: if status == 0:
break break
elif (tries > 5): elif tries > 5:
raise RuntimeError("ssh_write failed with error %s" % proc.returncode) raise RuntimeError("ssh_write failed with error %s" % proc.returncode)
else: else:
print >> stderr, \ print >> stderr, \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment