Class: Aws::EC2::VpcAddress

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(allocation_id, options = {}) ⇒ VpcAddress #initialize(options = {}) ⇒ VpcAddress

Returns a new instance of VpcAddress.

Overloads:

  • #initialize(allocation_id, options = {}) ⇒ VpcAddress

    Parameters:

    • allocation_id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ VpcAddress

    Options Hash (options):

    • :allocation_id (required, String)
    • :client (Client)


22
23
24
25
26
27
28
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 22

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @allocation_id = extract_allocation_id(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
  @waiter_block_warned = false
end

Instance Method Details

#allocation_idString

Returns:

  • (String)


33
34
35
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 33

def allocation_id
  @allocation_id
end

#associate(options = {}) ⇒ Types::AssociateAddressResult

Examples:

Request syntax with placeholder values


vpc_address.associate({
  instance_id: "InstanceId",
  public_ip: "String",
  allow_reassociation: false,
  dry_run: false,
  network_interface_id: "NetworkInterfaceId",
  private_ip_address: "String",
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :instance_id (String)

    The ID of the instance. This is required for EC2-Classic. For EC2-VPC, you can specify either the instance ID or the network interface ID, but not both. The operation fails if you specify an instance ID unless exactly one network interface is attached.

  • :public_ip (String)

    The Elastic IP address to associate with the instance. This is required for EC2-Classic.

  • :allow_reassociation (Boolean)

    [EC2-VPC] For a VPC in an EC2-Classic account, specify true to allow an Elastic IP address that is already associated with an instance or network interface to be reassociated with the specified instance or network interface. Otherwise, the operation fails. In a VPC in an EC2-VPC-only account, reassociation is automatic, therefore you can specify false to ensure the operation fails if the Elastic IP address is already associated with another resource.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :network_interface_id (String)

    [EC2-VPC] The ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID.

    For EC2-VPC, you can specify either the instance ID or the network interface ID, but not both.

  • :private_ip_address (String)

    [EC2-VPC] The primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.

Returns:



289
290
291
292
293
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 289

def associate(options = {})
  options = options.merge(allocation_id: @allocation_id)
  resp = @client.associate_address(options)
  resp.data
end

#associationNetworkInterfaceAssociation?

Returns:



337
338
339
340
341
342
343
344
345
346
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 337

def association
  if data[:association_id]
    NetworkInterfaceAssociation.new(
      id: data[:association_id],
      client: @client
    )
  else
    nil
  end
end

#association_idString

The ID representing the association of the address with an instance in a VPC.

Returns:

  • (String)


52
53
54
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 52

def association_id
  data[:association_id]
end

#clientClient

Returns:



114
115
116
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 114

def client
  @client
end

#customer_owned_ipString

The customer-owned IP address.

Returns:

  • (String)


101
102
103
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 101

def customer_owned_ip
  data[:customer_owned_ip]
end

#customer_owned_ipv_4_poolString

The ID of the customer-owned address pool.

Returns:

  • (String)


107
108
109
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 107

def customer_owned_ipv_4_pool
  data[:customer_owned_ipv_4_pool]
end

#dataTypes::Address

Returns the data for this Aws::EC2::VpcAddress. Calls Client#describe_addresses if #data_loaded? is false.

Returns:



134
135
136
137
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 134

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



142
143
144
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 142

def data_loaded?
  !!@data
end

#domainString

Indicates whether this Elastic IP address is for use with instances in EC2-Classic (standard) or instances in a VPC (vpc).

Returns:

  • (String)


59
60
61
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 59

def domain
  data[:domain]
end

#instance_idString

The ID of the instance that the address is associated with (if any).

Returns:

  • (String)


39
40
41
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 39

def instance_id
  data[:instance_id]
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::EC2::VpcAddress. Returns self making it possible to chain methods.

vpc_address.reload.data

Returns:

  • (self)


124
125
126
127
128
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 124

def load
  resp = @client.describe_addresses(allocation_ids: [@allocation_id])
  @data = resp.addresses[0]
  self
end

#network_border_groupString

The name of the location from which the IP address is advertised.

Returns:

  • (String)


95
96
97
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 95

def network_border_group
  data[:network_border_group]
end

#network_interface_idString

The ID of the network interface.

Returns:

  • (String)


65
66
67
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 65

def network_interface_id
  data[:network_interface_id]
end

#network_interface_owner_idString

The ID of the AWS account that owns the network interface.

Returns:

  • (String)


71
72
73
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 71

def network_interface_owner_id
  data[:network_interface_owner_id]
end

#private_ip_addressString

The private IP address associated with the Elastic IP address.

Returns:

  • (String)


77
78
79
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 77

def private_ip_address
  data[:private_ip_address]
end

#public_ipString

The Elastic IP address.

Returns:

  • (String)


45
46
47
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 45

def public_ip
  data[:public_ip]
end

#public_ipv_4_poolString

The ID of an address pool.

Returns:

  • (String)


89
90
91
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 89

def public_ipv_4_pool
  data[:public_ipv_4_pool]
end

#release(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


vpc_address.release({
  public_ip: "String",
  network_border_group: "String",
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :public_ip (String)

    [EC2-Classic] The Elastic IP address. Required for EC2-Classic.

  • :network_border_group (String)

    The location that the IP address is released from.

    If you provide an incorrect network border group, you will receive an InvalidAddress.NotFound error. For more information, see Error Codes.

    You cannot use a network border group with EC2 Classic. If you attempt this operation on EC2 classic, you will receive an InvalidParameterCombination error. For more information, see Error Codes.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


328
329
330
331
332
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 328

def release(options = {})
  options = options.merge(allocation_id: data[:allocation_id])
  resp = @client.release_address(options)
  resp.data
end

#tagsArray<Types::Tag>

Any tags assigned to the Elastic IP address.

Returns:



83
84
85
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 83

def tags
  data[:tags]
end

#wait_until(options = {}) {|resource| ... } ⇒ Resource

Deprecated.

Use [Aws::EC2::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged.

Waiter polls an API operation until a resource enters a desired state.

Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

Example

instance.wait_until(max_attempts:10, delay:5) do |instance|
  instance.state.name == 'running'
end

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Yield Parameters:

  • resource (Resource)

    to be used in the waiting condition.

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/vpc_address.rb', line 226

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Waiters::Waiter.new(options).wait({})
end