Class: Aws::EC2::SecurityGroup
- Inherits:
-
Object
- Object
- Aws::EC2::SecurityGroup
- Defined in:
- gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#description ⇒ String
A description of the security group.
-
#group_name ⇒ String
The name of the security group.
-
#id ⇒ String
(also: #group_id)
-
#ip_permissions ⇒ Array<Types::IpPermission>
The inbound rules associated with the security group.
-
#ip_permissions_egress ⇒ Array<Types::IpPermission>
The outbound rules associated with the security group.
-
#owner_id ⇒ String
The Amazon Web Services account ID of the owner of the security group.
-
#security_group_arn ⇒ String
The ARN of the security group.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the security group.
-
#vpc_id ⇒ String
The ID of the VPC for the security group.
Actions collapse
-
#authorize_egress(options = {}) ⇒ Types::AuthorizeSecurityGroupEgressResult
-
#authorize_ingress(options = {}) ⇒ Types::AuthorizeSecurityGroupIngressResult
-
#create_tags(options = {}) ⇒ Tag::Collection
-
#delete(options = {}) ⇒ Types::DeleteSecurityGroupResult
-
#delete_tags(options = {}) ⇒ Tag::Collection
-
#revoke_egress(options = {}) ⇒ Types::RevokeSecurityGroupEgressResult
-
#revoke_ingress(options = {}) ⇒ Types::RevokeSecurityGroupIngressResult
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::SecurityGroup
Returns the data for this SecurityGroup.
-
#data_loaded? ⇒ Boolean
Returns
true
if this resource is loaded. -
#initialize(*args) ⇒ SecurityGroup
constructor
A new instance of SecurityGroup.
-
#load ⇒ self
(also: #reload)
Loads, or reloads #data for the current SecurityGroup.
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
Constructor Details
#initialize(id, options = {}) ⇒ SecurityGroup #initialize(options = {}) ⇒ SecurityGroup
Returns a new instance of SecurityGroup.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#authorize_egress(options = {}) ⇒ Types::AuthorizeSecurityGroupEgressResult
305 306 307 308 309 310 311 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 305 def ( = {}) = .merge(group_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end resp.data end |
#authorize_ingress(options = {}) ⇒ Types::AuthorizeSecurityGroupIngressResult
453 454 455 456 457 458 459 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 453 def ( = {}) = .merge(group_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end resp.data end |
#client ⇒ Client
89 90 91 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 89 def client @client end |
#create_tags(options = {}) ⇒ Tag::Collection
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 483 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [:tags].each do |t| batch << Tag.new( resource_id: @id, key: t[:key], value: t[:value], client: @client ) end Tag::Collection.new([batch], size: batch.size) end |
#data ⇒ Types::SecurityGroup
Returns the data for this Aws::EC2::SecurityGroup. Calls
Client#describe_security_groups if #data_loaded? is false
.
111 112 113 114 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 111 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
119 120 121 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 119 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteSecurityGroupResult
564 565 566 567 568 569 570 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 564 def delete( = {}) = .merge(group_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_security_group() end resp.data end |
#delete_tags(options = {}) ⇒ Tag::Collection
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 530 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [:tags].each do |t| batch << Tag.new( resource_id: @id, key: t[:key], value: t[:value], client: @client ) end Tag::Collection.new([batch], size: batch.size) end |
#description ⇒ String
A description of the security group.
76 77 78 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 76 def description data[:description] end |
#group_name ⇒ String
The name of the security group.
70 71 72 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 70 def group_name data[:group_name] end |
#id ⇒ String Also known as: group_id
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 33 def id @id end |
#ip_permissions ⇒ Array<Types::IpPermission>
The inbound rules associated with the security group.
82 83 84 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 82 def data[:ip_permissions] end |
#ip_permissions_egress ⇒ Array<Types::IpPermission>
The outbound rules associated with the security group.
40 41 42 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 40 def data[:ip_permissions_egress] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::EC2::SecurityGroup.
Returns self
making it possible to chain methods.
security_group.reload.data
99 100 101 102 103 104 105 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 99 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_security_groups(group_ids: [@id]) end @data = resp.security_groups[0] self end |
#owner_id ⇒ String
The Amazon Web Services account ID of the owner of the security group.
64 65 66 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 64 def owner_id data[:owner_id] end |
#revoke_egress(options = {}) ⇒ Types::RevokeSecurityGroupEgressResult
647 648 649 650 651 652 653 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 647 def revoke_egress( = {}) = .merge(group_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.revoke_security_group_egress() end resp.data end |
#revoke_ingress(options = {}) ⇒ Types::RevokeSecurityGroupIngressResult
746 747 748 749 750 751 752 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 746 def revoke_ingress( = {}) = .merge(group_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.revoke_security_group_ingress() end resp.data end |
#security_group_arn ⇒ String
The ARN of the security group.
58 59 60 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 58 def security_group_arn data[:security_group_arn] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the security group.
46 47 48 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 46 def data[:tags] end |
#vpc_id ⇒ String
The ID of the VPC for the security group.
52 53 54 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 52 def vpc_id data[:vpc_id] end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::EC2::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success
or :failure
from these callbacks,
it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/security_group.rb', line 203 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |