You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Class: AWS::EC2::SecurityGroupCollection
- Inherits:
-
Collection
- Object
- Collection
- AWS::EC2::SecurityGroupCollection
- Includes:
- TaggedCollection
- Defined in:
- lib/aws/ec2/security_group_collection.rb
Overview
Represents all EC2 security groups in an AWS account.
Instance Method Summary collapse
-
#[](group_id) ⇒ SecurityGroup
The group with the given id.
-
#create(name, options = {}) ⇒ SecurityGroup
Creates a new.
-
#each {|group| ... } ⇒ SecurityGroupCollection?
Specify one or more criteria to filter security groups by.
Methods included from TaggedCollection
#tagged, #tagged_values, #with_tag
Methods included from FilteredCollection
Instance Method Details
#[](group_id) ⇒ SecurityGroup
Returns The group with the given id.
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
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, = {} description = [:description] || name create_opts = {} create_opts[:group_name] = name create_opts[:description] = description vpc_id = [:vpc] vpc_id ||= [: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| ... } ⇒ SecurityGroupCollection?
Specify one or more criteria to filter security groups by. A subsequent call to #each will limit the security groups returned by the set of filters.
If you supply multiple values to #filter then these values are treated as an OR condition. To return security groups named 'test' or 'fake':
security_groups.filter('group-name', 'test', 'fake')
If you want to and conditions together you need to chain calls to filter. To limit security groups to those with a name like 'test' and like 'ruby':
security_groups.
filter('group-name', '*test*').
filter('group-name', '*ruby*').each do |group|
#...
end
Note that * matches one or more characters and ? matches any one character.
Valid Filters
- description - Description of the security group.
- group-id - ID of the security group.
- group-name - Name of the security group.
- ip-permission.cidr - CIDR range that has been granted the permission.
- ip-permission.from-port - Start of port range for the TCP and UDP protocols, or an ICMP type number.
- ip-permission.group-name - Name of security group that has been granted the permission.
- ip-permission.protocol - IP protocol for the permission. Valid values include 'tcp', 'udp', 'icmp' or a protocol number.
- ip-permission.to-port - End of port range for the TCP and UDP protocols, or an ICMP code.
- ip-permission.user-id - ID of AWS account that has been granted the permission.
- owner-id - AWS account ID of the owner of the security group.
- tag-key - Key of a tag assigned to the security group.
- tag-value - Value of a tag assigned to the security group.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/aws/ec2/security_group_collection.rb', line 117 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 |