Skip to content

Instantly share code, notes, and snippets.

@JoshRosen
Created December 2, 2012 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshRosen/4187604 to your computer and use it in GitHub Desktop.
Save JoshRosen/4187604 to your computer and use it in GitHub Desktop.
spark-ec2 security group deletion
diff --git a/ec2/spark_ec2.py b/ec2/spark_ec2.py
index 2ab11db..b29d0c3 100755
--- a/ec2/spark_ec2.py
+++ b/ec2/spark_ec2.py
@@ -557,18 +557,18 @@ def main():
inst.terminate()
# Delete security groups as well
group_names = [cluster_name + "-master", cluster_name + "-slaves", cluster_name + "-zoo"]
- groups = conn.get_all_security_groups()
+ groups = [g for g in conn.get_all_security_groups() if g.name in group_names]
+ print "Deleting security groups " + str(group_names)
+ # Delete individual rules before deleting group to remove dependencies
for group in groups:
- if group.name in group_names:
- print "Deleting security group " + group.name
- # Delete individual rules before deleting group to remove dependencies
- for rule in group.rules:
- for grant in rule.grants:
- group.revoke(ip_protocol=rule.ip_protocol,
- from_port=rule.from_port,
- to_port=rule.to_port,
- src_group=grant)
- conn.delete_security_group(group.name)
+ for rule in group.rules:
+ for grant in rule.grants:
+ group.revoke(ip_protocol=rule.ip_protocol,
+ from_port=rule.from_port,
+ to_port=rule.to_port,
+ src_group=grant)
+ for group in groups:
+ conn.delete_security_group(group.name)
elif action == "login":
(master_nodes, slave_nodes, zoo_nodes) = get_existing_cluster(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment