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.



25
26
27
28
# File 'lib/aws/ec2/elastic_ip.rb', line 25

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

Instance Attribute Details

#instance_idString? (readonly)

Returns the instance id if assigned to an EC2 instance, nil otherwise.

Returns:

  • (String, nil)

    the current value of instance_id



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

def instance_id
  @instance_id
end

#public_ipString (readonly) Also known as: ip_address

Returns The public IP address.

Returns:

  • (String)

    The public IP address.



31
32
33
# File 'lib/aws/ec2/elastic_ip.rb', line 31

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.



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

def associated?
  !!instance_id
end

#deletenil 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:

  • (nil)


63
64
65
66
# File 'lib/aws/ec2/elastic_ip.rb', line 63

def delete
  client.release_address(resource_options)
  nil
end

#disassociatenil

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

Returns:

  • (nil)


74
75
76
77
# File 'lib/aws/ec2/elastic_ip.rb', line 74

def disassociate
  client.disassociate_address(resource_options)
  nil
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
54
55
# File 'lib/aws/ec2/elastic_ip.rb', line 51

def instance
  if instance_id = self.instance_id
    Instance.new(instance_id, :config => config)
  end
end

#to_sString

Returns the public IP address

Returns:

  • (String)

    Returns the public IP address



80
81
82
# File 'lib/aws/ec2/elastic_ip.rb', line 80

def to_s
  public_ip.to_s
end