Class: AWS::EC2::SecurityGroupCollection

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

Overview

Represents all EC2 security groups in an AWS account.

Instance Attribute Summary

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from TaggedCollection

#tagged, #tagged_values

Methods included from FilteredCollection

#filter, #filtered_request, #initialize

Methods included from Core::Model

#client, #config_prefix, #initialize, #inspect

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:


63
64
65
# File 'lib/aws/ec2/security_group_collection.rb', line 63

def [] group_id
  SecurityGroup.new(group_id, :config => config)
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.

  • :vpc (VPC, String) — default: nil

    A VPC or VPC id string to create the security group in. When specified a VPC security group is created.

Returns:


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws/ec2/security_group_collection.rb', line 36

def create name, options = {}

  description = options[:description] || name

  create_opts = {}
  create_opts[:group_name] = name
  create_opts[:description] = description

  vpc_id = options[:vpc]
  vpc_id ||= options[:vpc_id] # for backwards compatability
  vpc_id ||= filter_value_for('vpc-id')
  vpc_id = vpc_id.id if vpc_id.is_a?(VPC)

  create_opts[:vpc_id] = vpc_id if vpc_id

  response = client.create_security_group(create_opts)

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

end

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

Yields once for each security group in this account.

Yields:

  • (group)

Yield Parameters:

Returns:

  • (nil)

119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/aws/ec2/security_group_collection.rb', line 119

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