Class: AWS::EC2::ElasticIp
- Inherits:
-
Resource
- Object
- Core::Resource
- Resource
- AWS::EC2::ElasticIp
- Defined in:
- lib/aws/ec2/elastic_ip.rb
Instance Attribute Summary collapse
-
#allocation_id ⇒ String?
readonly
The ID representing the allocation of the address for use with Amazon VPC.
-
#association_id ⇒ String?
readonly
The ID of the association between this elastic ip address and an EC2 VPC instance (VPC only).
-
#domain ⇒ String
readonly
Indicates whether this elastic ip address is for EC2 instances ('standard') or VPC instances ('vpc').
-
#instance_id ⇒ String?
readonly
Returns the instance id if assigned to an EC2 instance, nil otherwise.
-
#network_interface_id ⇒ String?
readonly
The ID of the network interface (VPC only).
-
#network_interface_owner_id ⇒ String?
readonly
The ID of the AWS account that owns the network interface (VPC only).
-
#public_ip ⇒ String
(also: #ip_address)
readonly
The public IP address.
Instance Method Summary collapse
-
#associate(options) ⇒ String
Associates this elastic IP address with an instance or a network interface.
-
#associated? ⇒ Boolean
(also: #attached?)
Returns true if this IP address is associated with an EC2 instance or a network interface.
-
#delete ⇒ nil
(also: #release)
Releases the elastic IP address.
-
#disassociate ⇒ nil
Disassociates this elastic IP address from an EC2 instance.
-
#exists? ⇒ Boolean
Returns true the elastic ip address exists in your account.
-
#initialize(public_ip, options = {}) ⇒ ElasticIp
constructor
A new instance of ElasticIp.
-
#instance ⇒ Instance?
If associated, returns the Instance this elastic IP address is associated to, nil otherwise.
-
#network_interface ⇒ NetworkInterface?
Returns the network interface this elastic ip is associated with.
-
#to_s ⇒ String
Returns the public IP address.
-
#vpc? ⇒ Boolean
Returns true if this is an EC2 VPC Elastic IP.
Constructor Details
#initialize(public_ip, options = {}) ⇒ ElasticIp
Returns a new instance of ElasticIp.
38 39 40 41 |
# File 'lib/aws/ec2/elastic_ip.rb', line 38 def initialize public_ip, = {} @public_ip = public_ip super end |
Instance Attribute Details
#allocation_id ⇒ String? (readonly)
The ID representing the allocation of the address for use with Amazon VPC.
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def allocation_id @allocation_id end |
#association_id ⇒ String? (readonly)
The ID of the association between this elastic ip address and an EC2 VPC instance (VPC only).
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def association_id @association_id end |
#domain ⇒ String (readonly)
Indicates whether this elastic ip address is for EC2 instances ('standard') or VPC instances ('vpc').
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def domain @domain end |
#instance_id ⇒ String? (readonly)
Returns the instance id if assigned to an EC2 instance, nil otherwise.
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def instance_id @instance_id end |
#network_interface_id ⇒ String? (readonly)
The ID of the network interface (VPC only).
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def network_interface_id @network_interface_id end |
#network_interface_owner_id ⇒ String? (readonly)
The ID of the AWS account that owns the network interface (VPC only).
36 37 38 |
# File 'lib/aws/ec2/elastic_ip.rb', line 36 def network_interface_owner_id @network_interface_owner_id end |
#public_ip ⇒ String (readonly) Also known as: ip_address
Returns The public IP address.
44 45 46 |
# File 'lib/aws/ec2/elastic_ip.rb', line 44 def public_ip @public_ip end |
Instance Method Details
#associate(options) ⇒ String
Associates this elastic IP address with an instance or a network
interface. You may provide :instance
or :network_interface
but not both options.
# associate with an instance
eip.associate :instance => 'i-12345678'
# associate with a network interface
eip.associate :network_interface => 'ni-12345678'
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/aws/ec2/elastic_ip.rb', line 132 def associate client_opts = {} [:instance,:network_interface].each do |opt| if value = [opt] client_opts[:"#{opt}_id"] = value.is_a?(Resource) ? value.id : value end end if vpc? client_opts[:allocation_id] = allocation_id else client_opts[:public_ip] = public_ip end resp = client.associate_address(client_opts) resp.data[:association_id] end |
#associated? ⇒ Boolean Also known as: attached?
Returns true if this IP address is associated with an EC2 instance or a network interface.
73 74 75 |
# File 'lib/aws/ec2/elastic_ip.rb', line 73 def associated? !!(instance_id || association_id) end |
#delete ⇒ nil Also known as: release
Releases the elastic IP address.
(For non-VPC elastic ips) Releasing an IP address automatically disassociates it from any instance it's associated with.
102 103 104 105 106 107 108 109 |
# File 'lib/aws/ec2/elastic_ip.rb', line 102 def delete if vpc? client.release_address(:allocation_id => allocation_id) else client.release_address(:public_ip => public_ip) end nil end |
#disassociate ⇒ nil
Disassociates this elastic IP address from an EC2 instance. Raises an exception if this elastic IP is not currently associated with an instance.
157 158 159 160 161 162 163 164 |
# File 'lib/aws/ec2/elastic_ip.rb', line 157 def disassociate if vpc? client.disassociate_address(:association_id => association_id) else client.disassociate_address(:public_ip => public_ip) end nil end |
#exists? ⇒ Boolean
Returns true the elastic ip address exists in your account.
168 169 170 171 172 173 174 175 |
# File 'lib/aws/ec2/elastic_ip.rb', line 168 def exists? begin get_resource true rescue Errors::InvalidAddress::NotFound false end end |
#instance ⇒ Instance?
Returns If associated, returns the Instance this elastic IP address is associated to, nil otherwise.
81 82 83 84 85 |
# File 'lib/aws/ec2/elastic_ip.rb', line 81 def instance if instance_id = self.instance_id Instance.new(instance_id, :config => config) end end |
#network_interface ⇒ NetworkInterface?
Returns the network interface this
elastic ip is associated with. Returns nil
if this is not
associated with an elastic ip address.
90 91 92 93 94 |
# File 'lib/aws/ec2/elastic_ip.rb', line 90 def network_interface if nid = network_interface_id NetworkInterface.new(nid, :config => config) end end |
#to_s ⇒ String
Returns the public IP address
178 179 180 |
# File 'lib/aws/ec2/elastic_ip.rb', line 178 def to_s public_ip.to_s end |
#vpc? ⇒ Boolean
Returns true if this is an EC2 VPC Elastic IP.
67 68 69 |
# File 'lib/aws/ec2/elastic_ip.rb', line 67 def vpc? domain == 'vpc' end |