Class: AWS::EC2::SecurityGroupCollection

Inherits:
Collection
  • Object
show all
Defined in:
lib/aws/ec2/security_group_collection.rb

Overview

Represents all EC2 security groups in an AWS account.

Instance Method Summary collapse

Instance Method Details

#[](group_id) ⇒ SecurityGroup

Returns The group with the given id.

Parameters:

  • group_id (String)

    The group id of a security group.

Returns:



52
53
54
# File 'lib/aws/ec2/security_group_collection.rb', line 52

def [] group_id
  super
end

#create(name, options = {}) ⇒ SecurityGroup

Creates a new

Parameters:

  • name (String)

    The name of the security group to create.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :description (String)

    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.

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aws/ec2/security_group_collection.rb', line 35

def create name, options = {}

  description = options[:description] || name

  response = client.create_security_group(
    :group_name => name, 
    :description => description)

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

end

#each {|group| ... } ⇒ nil

Yields once for each security group in this account.

Yields:

  • (group)

Yield Parameters:

Returns:

  • (nil)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/aws/ec2/security_group_collection.rb', line 108

def each &block

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

    group = SecurityGroup.new(info.group_id,
      :name => info.group_name,
      :description => info.group_description,
      :owner_id => info.owner_id,
      :config => config)

    yield(group)

  end
  nil
end