Class: AwsUtils::Ec2DeleteSecurityGroup
Instance Method Summary
collapse
#assigned?, #connection, #current_groups, #exist?, #groups
Constructor Details
66
67
68
|
# File 'lib/awsutils/ec2delsg.rb', line 66
def initialize( args )
@opts = Ec2SecurityGroup.parse_opts( args )
end
|
Instance Method Details
#delete_group_refs ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/awsutils/ec2delsg.rb', line 51
def delete_group_refs
references.each do |ref|
puts "Removing rule: " + ref.inspect
connection.revoke_security_group_ingress(
ref["group_name"],
ref["options"]
)
end
end
|
#name ⇒ Object
70
71
72
|
# File 'lib/awsutils/ec2delsg.rb', line 70
def name
@opts[:security_group]
end
|
#references ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/awsutils/ec2delsg.rb', line 9
def references
@references ||= begin
references = []
connection.security_groups.each do |group|
group.ip_permissions.each do |ip_perm|
ip_perm["groups"].each do |src_grp|
if src_grp["groupName"] == @opts[:security_group]
options = {
"IpPermissions" => [
{
"FromPort" => ip_perm["fromPort"],
"Groups" => [
{
"GroupName" => @opts[:security_group],
"UserId" => @opts[:owner_group_id]
}
],
"IpProtocol" => ip_perm["ipProtocol"],
"IpRanges" => [],
"ToPort" => ip_perm["toPort"]
}
]
}
references << {
"group_name" => group.name,
"options" => options
}
end
end
end
end
references
end
end
|
#run ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/awsutils/ec2delsg.rb', line 74
def run
if ! exist?
puts "Specified group does not exist."
exit 1
end
if assigned?
puts "Group is still assigned to one or more instances."
exit 1
end
delete_group_refs
puts "Deleting group #{@opts[:security_group]}."
connection.delete_security_group( nil,
connection.security_groups.get(@opts[:security_group]).group_id )
end
|