returned by EC2::Base#describe_security_groups
groupName: stage-app groupDescription: ownerId: "207436219441" ipPermissions: item: - ipRanges: item: - cidrIp: 216.19.182.83/32 - cidrIp: 24.5.71.201/32 - cidrIp: 75.157.176.202/32 - cidrIp: 84.28.52.172/32 - cidrIp: 87.212.145.201/32 - cidrIp: 96.49.129.178/32 groups: item: - groupName: default userId: "207436219441" - groupName: stage-app userId: "207436219441" fromPort: "22" toPort: "22" ipProtocol: tcp
Returns a Rudy::AWS::EC2::Group object
# File lib/rudy/aws/ec2/group.rb, line 211 def self.from_hash(ghash) newg = Rudy::AWS::EC2::Group.new newg.name = ghash['groupName'] newg.description = ghash['groupDescription'] newg.owner_id = ghash['ownerId'] newg.addresses = {} newg.groups = {} return newg unless ghash['ipPermissions'].is_a?(Hash) ghash['ipPermissions']['item'].each do |oldp| newp = Rudy::AWS::EC2::Group::Rule.new newp.ports = Range.new(oldp['fromPort'], oldp['toPort']) newp.protocol = oldp['ipProtocol'] if oldp['groups'].is_a?(Hash) oldp['groups']['item'].each do |oldpg| name = [oldpg['userId'], oldpg['groupName']].join(':') # account_num:name newg.add_group(name, newp) end end if oldp['ipRanges'].is_a?(Hash) oldp['ipRanges']['item'].each do |olda| name = "#{olda['cidrIp']}" newg.add_address(name, newp) # ipaddress/mask/protocol end end end newg end
# File lib/rudy/aws/ec2/group.rb, line 155 def any? groups = list || [] !groups.empty? end
Create a new EC2 security group Returns list of created groups
# File lib/rudy/aws/ec2/group.rb, line 93 def create(name, desc=nil, addresses=[], ports=[], protocols=[], &each_group) desc ||= "Security Group #{name}" ret = @@ec2.create_security_group(:group_name => name, :group_description => desc) return false unless (ret && ret['return'] == 'true') authorize(name, addresses, ports, protocols) get(name, &each_group) end
Delete an EC2 security group Returns true/false whether successful
# File lib/rudy/aws/ec2/group.rb, line 103 def destroy(name, &each_group) list(name, &each_group) if each_group ret = @@ec2.delete_security_group(:group_name => name) (ret && ret['return'] == 'true') end
Does the security group name exist?
# File lib/rudy/aws/ec2/group.rb, line 171 def exists?(name) begin g = list([name.to_s]) rescue ::AWS::InvalidGroupNotFound return false end !g.empty? end
name a string
# File lib/rudy/aws/ec2/group.rb, line 161 def get(name) (list([name]) || []).first end
# File lib/rudy/aws/ec2/group.rb, line 130 def list(group_names=[], &each_group) group_names ||= [] groups = list_as_hash(group_names, &each_group) groups &&= groups.values groups end
group_names is a list of security group names to look for. If it's empty, all groups
associated to the account will be returned.
Returns an Array of Rudy::AWS::EC2::Group objects
# File lib/rudy/aws/ec2/group.rb, line 141 def list_as_hash(group_names=[], &each_group) group_names = [group_names].flatten.compact glist = @@ec2.describe_security_groups(:group_name => group_names) || {} return unless glist['securityGroupInfo'].is_a?(Hash) groups = {} glist['securityGroupInfo']['item'].each do |oldg| g = Groups.from_hash(oldg) groups[g.name] = g end groups.each_value { |g| each_group.call(g) } if each_group groups = nil if groups.empty? groups end
Revoke a port/protocol for a specific IP address Takes the same arguments as authorize
# File lib/rudy/aws/ec2/group.rb, line 117 def revoke(name, addresses=[], ports=[], protocols=[], &each_group) modify_rules(:revoke, name, addresses, ports, protocols, &each_group) end
Generated with the Darkfish Rdoc Generator 2.