Class: AWS::EC2::ElasticIp

Inherits:
Resource
  • Object
show all
Defined in:
lib/aws/ec2/elastic_ip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_ip, options = {}) ⇒ ElasticIp

Returns a new instance of ElasticIp.



20
21
22
23
24
# File 'lib/aws/ec2/elastic_ip.rb', line 20

def initialize public_ip, options = {}
  @public_ip = public_ip
  @instance_id = options[:instance_id]
  super
end

Instance Attribute Details

#public_ipString (readonly) Also known as: ip_address

Returns The public IP address.

Returns:

  • (String)

    The public IP address.



33
34
35
# File 'lib/aws/ec2/elastic_ip.rb', line 33

def public_ip
  @public_ip
end

Instance Method Details

#associated?Boolean Also known as: attached?

Returns true if this IP address is attached to an EC2 instance.

Returns:

  • (Boolean)

    Returns true if this IP address is attached to an EC2 instance.



44
45
46
# File 'lib/aws/ec2/elastic_ip.rb', line 44

def associated?
  !!instance_id
end

#deletetrue 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.

Returns:

  • (true)


61
62
63
64
# File 'lib/aws/ec2/elastic_ip.rb', line 61

def delete
  client.release_address(:public_ip => public_ip)
  true
end

#disassociatetrue

Disassociates this elastic IP address from an EC2 instance. Raises an exception if this elastic IP is not currently associated with an instance.

Returns:

  • (true)


72
73
74
75
# File 'lib/aws/ec2/elastic_ip.rb', line 72

def disassociate
  client.disassociate_address(:public_ip => public_ip)
  true
end

#instanceInstance?

Returns If associated, returns the Instance this elastic IP address is associated to, nil otherwise.

Returns:

  • (Instance, nil)

    If associated, returns the Instance this elastic IP address is associated to, nil otherwise.



51
52
53
# File 'lib/aws/ec2/elastic_ip.rb', line 51

def instance
  associated? ? Instance.new(instance_id, :config => config) : nil
end

#instance_idString?

Returns the instance id if assigned to an EC2 instance

Returns:

  • (String, nil)

    Returns the instance id if assigned to an EC2 instance



39
# File 'lib/aws/ec2/elastic_ip.rb', line 39

def instance_id; end