class AWS::EC2::SecurityGroupCollection

Represents all EC2 security groups in an AWS account.

Public Instance Methods

[](group_id) click to toggle source

@param [String] group_id The group id of a security group. @return [SecurityGroup] The group with the given id.

# File lib/aws/ec2/security_group_collection.rb, line 55
def [] group_id
  super
end
create(name, options = {}) click to toggle source

Creates a new @param [String] name The name of the security group to create. @param [Hash] options @option options [String] :description An informal description

of this security group.  Accepts alphanumeric characters, spaces,
dashes, and underscores. If left blank the description will be set
to the name.

@option options [String] :vpc_id (nil) The ID of a VPC to create

a security group in.  If this option is left blank then an 
EC2 security group is created.  If this option is provided a VPC
security group will be created.

@return [SecurityGroup]

# File lib/aws/ec2/security_group_collection.rb, line 34
def create name, options = {}

  description = options[:description] || name

  create_opts = {}
  create_opts[:group_name] = name
  create_opts[:description] = description
  create_opts[:vpc_id] = options[:vpc_id] if options[:vpc_id]

  response = client.create_security_group(create_opts)

  SecurityGroup.new(response.group_id, {
    :name => name,
    :description => description,
    :vpc_id => options[:vpc_id],
    :config => config })

end
each() { |group| ... } click to toggle source

Yields once for each security group in this account.

@yield [group] @yieldparam [SecurityGroup] group @return [nil]

# File lib/aws/ec2/security_group_collection.rb, line 111
def each &block

  response = filtered_request(:describe_security_groups)
  response.security_group_info.each do |info|

    group = SecurityGroup.new_from(:describe_security_groups, info, 
      info.group_id, :config => config)

    yield(group)

  end
  nil
end

Protected Instance Methods

member_class() click to toggle source
# File lib/aws/ec2/security_group_collection.rb, line 126
def member_class
  SecurityGroup
end