Class: AWS::EC2::InternetGateway

Inherits:
Resource show all
Includes:
TaggedItem
Defined in:
lib/aws/ec2/internet_gateway.rb,
lib/aws/ec2/internet_gateway/attachment.rb

Defined Under Namespace

Classes: Attachment

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #cached_tags, #clear_tags, #tagging_resource_type, #tags

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(internet_gateway_id, options = {}) ⇒ InternetGateway

Returns a new instance of InternetGateway.


23
24
25
26
# File 'lib/aws/ec2/internet_gateway.rb', line 23

def initialize internet_gateway_id, options = {}
  @internet_gateway_id = internet_gateway_id
  super
end

Instance Attribute Details

#internet_gateway_idString (readonly) Also known as: id

Returns:

  • (String)

29
30
31
# File 'lib/aws/ec2/internet_gateway.rb', line 29

def internet_gateway_id
  @internet_gateway_id
end

Instance Method Details

#attach(vpc) ⇒ nil

Attaches this internet gateway to the given VPC.

Parameters:

  • vpc (VPC, String)

    A VPC object or a vpc id string.

Returns:

  • (nil)

77
78
79
80
81
82
83
# File 'lib/aws/ec2/internet_gateway.rb', line 77

def attach vpc
  client_opts = {}
  client_opts[:internet_gateway_id] = internet_gateway_id
  client_opts[:vpc_id] = vpc_id_option(vpc)
  client.attach_internet_gateway(client_opts)
  nil
end

#attachmentsArray<InternetGateway::Attachment>

Returns:


46
47
48
# File 'lib/aws/ec2/internet_gateway.rb', line 46

def attachments
  attachment_set.map {|details| Attachment.new(self, details) }
end

#deletenil

Deletes this internet gateway.

Returns:

  • (nil)

98
99
100
101
102
103
# File 'lib/aws/ec2/internet_gateway.rb', line 98

def delete
  client_opts = {}
  client_opts[:internet_gateway_id] = internet_gateway_id
  client.delete_internet_gateway(client_opts)
  nil
end

#detach(vpc) ⇒ nil

Detaches this internet gateway from the given VPC.

Parameters:

  • vpc (VPC, String)

    A VPC object or a vpc id string.

Returns:

  • (nil)

88
89
90
91
92
93
94
# File 'lib/aws/ec2/internet_gateway.rb', line 88

def detach vpc
  client_opts = {}
  client_opts[:internet_gateway_id] = internet_gateway_id
  client_opts[:vpc_id] = vpc_id_option(vpc)
  client.detach_internet_gateway(client_opts)
  nil
end

#exists?Boolean

Returns true if the gateway exists.

Returns:

  • (Boolean)

    Returns true if the gateway exists.


106
107
108
109
110
111
112
113
# File 'lib/aws/ec2/internet_gateway.rb', line 106

def exists?
  begin
    get_resource
    true
  rescue Errors::InvalidInternetGatewayID::NotFound
    false
  end
end

#vpcVPC?

Returns the currently attached VPC, or nil if this gateway has not been attached.

Returns:

  • (VPC, nil)

    Returns the currently attached VPC, or nil if this gateway has not been attached.


52
53
54
55
56
# File 'lib/aws/ec2/internet_gateway.rb', line 52

def vpc
  if attachment = attachments.first  
    attachment.vpc
  end
end

#vpc=(vpc) ⇒ Object

Attaches this internet gateway to the given VPC. If this gateway is already attached to a different VPC, it will be detached from that one first. If you pass nil, then this internet gateway will

internet_gateway.vpc = 'vpc-123'

Parameters:

  • vpc (VPC, String)

    A VPC object or a vpc id string.


67
68
69
70
71
72
# File 'lib/aws/ec2/internet_gateway.rb', line 67

def vpc= vpc
  if attachment = attachments.first
    attachment.delete
  end
  attach(vpc) if vpc
end