Class: AWS::EC2::ElasticIp

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

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

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(public_ip, options = {}) ⇒ ElasticIp

Returns a new instance of ElasticIp.


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

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

Instance Attribute Details

#allocation_idObject (readonly)

vpc related attributes


35
36
37
# File 'lib/aws/ec2/elastic_ip.rb', line 35

def allocation_id
  @allocation_id
end

#IndicatesString (readonly)

whether this elastic ip address is for EC2 instances ('standard') or VPC instances ('vpc').

Returns:

  • (String)

    the current value of Indicates


35
36
37
# File 'lib/aws/ec2/elastic_ip.rb', line 35

def Indicates
  @Indicates
end

#instance_idString? (readonly)

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

Returns:

  • (String, nil)

    the current value of instance_id


35
36
37
# File 'lib/aws/ec2/elastic_ip.rb', line 35

def instance_id
  @instance_id
end

#network_interface_owner_idString? (readonly)

The ID of the AWS account that owns the network interface (VPC only).

Returns:

  • (String, nil)

    the current value of network_interface_owner_id


35
36
37
# File 'lib/aws/ec2/elastic_ip.rb', line 35

def network_interface_owner_id
  @network_interface_owner_id
end

#public_ipString (readonly) Also known as: ip_address

Returns The public IP address.

Returns:

  • (String)

    The public IP address.


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

def public_ip
  @public_ip
end

#TheString? (readonly)

ID of the association between this elastic ip address and an EC2 VPC instance (VPC only).

Returns:

  • (String, nil)

    the current value of The


35
36
37
# File 'lib/aws/ec2/elastic_ip.rb', line 35

def The
  @The
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.


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

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)

92
93
94
95
96
97
98
99
# File 'lib/aws/ec2/elastic_ip.rb', line 92

def delete
  if vpc?
    client.release_address(:allocation_id => allocation_id)
  else
    client.release_address(:public_ip => public_ip)
  end
  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)

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

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.

Returns:

  • (Boolean)

    Returns true the elastic ip address exists in your account.


117
118
119
120
121
122
123
124
# File 'lib/aws/ec2/elastic_ip.rb', line 117

def exists?
  begin
    get_resource
    true
  rescue Errors::InvalidAddress::NotFound
    false
  end
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.


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

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


127
128
129
# File 'lib/aws/ec2/elastic_ip.rb', line 127

def to_s
  public_ip.to_s
end

#vpc?Boolean

Returns true if this is an EC2 VPC Elastic IP.

Returns:

  • (Boolean)

    Returns true if this is an EC2 VPC Elastic IP.


66
67
68
# File 'lib/aws/ec2/elastic_ip.rb', line 66

def vpc?
  domain == 'vpc'
end