You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::EC2::NetworkInterface

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

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = {}) ⇒ NetworkInterface #initialize(options = {}) ⇒ NetworkInterface

Returns a new instance of NetworkInterface

Overloads:

  • #initialize(id, options = {}) ⇒ NetworkInterface

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ NetworkInterface

    Options Hash (options):

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


19
20
21
22
23
24
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 19

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

Instance Method Details

#assign_private_ip_addresses(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.assign_private_ip_addresses({
  allow_reassignment: false,
  private_ip_addresses: ["String"],
  secondary_private_ip_address_count: 1,
})

Parameters:

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

    ({})

Options Hash (options):

  • :allow_reassignment (Boolean)

    Indicates whether to allow an IP address that is already assigned to another network interface or instance to be reassigned to the specified network interface.

  • :private_ip_addresses (Array<String>)

    One or more IP addresses to be assigned as a secondary private IP address to the network interface. You can't specify this parameter when also specifying a number of secondary IP addresses.

    If you don't specify an IP address, Amazon EC2 automatically selects an IP address within the subnet range.

  • :secondary_private_ip_address_count (Integer)

    The number of secondary IP addresses to assign to the network interface. You can't specify this parameter when also specifying private IP addresses.

Returns:

  • (EmptyStructure)


204
205
206
207
208
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 204

def assign_private_ip_addresses(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.assign_private_ip_addresses(options)
  resp.data
end

#associationNetworkInterfaceAssociation?

Returns:



420
421
422
423
424
425
426
427
428
429
430
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 420

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

#attach(options = {}) ⇒ Types::AttachNetworkInterfaceResult

Examples:

Request syntax with placeholder values


network_interface.attach({
  device_index: 1, # required
  dry_run: false,
  instance_id: "String", # required
})

Parameters:

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

    ({})

Options Hash (options):

  • :device_index (required, Integer)

    The index of the device for the network interface attachment.

  • :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.

  • :instance_id (required, String)

    The ID of the instance.

Returns:



228
229
230
231
232
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 228

def attach(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.attach_network_interface(options)
  resp.data
end

#attachmentTypes::NetworkInterfaceAttachment

The network interface attachment.



36
37
38
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 36

def attachment
  data.attachment
end

#availability_zoneString

The Availability Zone.

Returns:

  • (String)


42
43
44
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 42

def availability_zone
  data.availability_zone
end

#clientClient

Returns:



146
147
148
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 146

def client
  @client
end

#create_tags(options = {}) ⇒ Tag::Collection

Examples:

Request syntax with placeholder values


tag = network_interface.create_tags({
  dry_run: false,
  tags: [ # required
    {
      key: "String",
      value: "String",
    },
  ],
})

Parameters:

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

    ({})

Options Hash (options):

  • :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.

  • :tags (required, Array<Types::Tag>)

    One or more tags. The value parameter is required, but if you don't want the tag to have a value, specify the parameter with no value, and we set the value to an empty string.

Returns:



256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 256

def create_tags(options = {})
  batch = []
  options = Aws::Util.deep_merge(options, resources: [@id])
  resp = @client.create_tags(options)
  options[:tags].each do |t|
    batch << Tag.new(
      resource_id: @id,
      key: t[:key],
      value: t[:value],
      client: @client
    )
  end
  Tag::Collection.new([batch], size: batch.size)
end

#dataTypes::NetworkInterface

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

Returns:



166
167
168
169
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 166

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.



174
175
176
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 174

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.delete({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :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)


283
284
285
286
287
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 283

def delete(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.delete_network_interface(options)
  resp.data
end

#describe_attribute(options = {}) ⇒ Types::DescribeNetworkInterfaceAttributeResult

Examples:

Request syntax with placeholder values


network_interface.describe_attribute({
  attribute: "description", # accepts description, groupSet, sourceDestCheck, attachment
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (String)

    The attribute of the network interface. This parameter is required.

  • :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:



304
305
306
307
308
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 304

def describe_attribute(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.describe_network_interface_attribute(options)
  resp.data
end

#descriptionString

A description.

Returns:

  • (String)


48
49
50
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 48

def description
  data.description
end

#detach(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.detach({
  dry_run: false,
  force: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :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.

  • :force (Boolean)

    Specifies whether to force a detachment.

Returns:

  • (EmptyStructure)


325
326
327
328
329
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 325

def detach(options = {})
  options = options.merge(attachment_id: data.attachment.attachment_id)
  resp = @client.detach_network_interface(options)
  resp.data
end

#groupsArray<Types::GroupIdentifier>

Any security groups for the network interface.

Returns:



54
55
56
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 54

def groups
  data.groups
end

#idString Also known as: network_interface_id

Returns:

  • (String)


29
30
31
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 29

def id
  @id
end

#interface_typeString

The type of interface.

Returns:

  • (String)


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

def interface_type
  data.interface_type
end

#ipv_6_addressesArray<Types::NetworkInterfaceIpv6Address>

The IPv6 addresses associated with the network interface.



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

def ipv_6_addresses
  data.ipv_6_addresses
end

#loadself Also known as: reload

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

network_interface.reload.data

Returns:

  • (self)


156
157
158
159
160
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 156

def load
  resp = @client.describe_network_interfaces(network_interface_ids: [@id])
  @data = resp.network_interfaces[0]
  self
end

#mac_addressString

The MAC address.

Returns:

  • (String)


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

def mac_address
  data.mac_address
end

#modify_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.modify_attribute({
  attachment: {
    attachment_id: "String",
    delete_on_termination: false,
  },
  description: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  dry_run: false,
  groups: ["String"],
  source_dest_check: {
    value: false,
  },
})

Parameters:

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

    ({})

Options Hash (options):

  • :attachment (Types::NetworkInterfaceAttachmentChanges)

    Information about the interface attachment. If modifying the 'delete on termination' attribute, you must specify the ID of the interface attachment.

  • :description (Types::AttributeValue)

    A description for the network interface.

  • :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.

  • :groups (Array<String>)

    Changes the security groups for the network interface. The new set of groups you specify replaces the current set. You must specify at least one group, even if it's just the default security group in the VPC. You must specify the ID of the security group, not the name.

  • :source_dest_check (Types::AttributeBooleanValue)

    Indicates whether source/destination checking is enabled. A value of true means checking is enabled, and false means checking is disabled. This value must be false for a NAT instance to perform NAT. For more information, see NAT Instances in the Amazon Virtual Private Cloud User Guide.

Returns:

  • (EmptyStructure)


373
374
375
376
377
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 373

def modify_attribute(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.modify_network_interface_attribute(options)
  resp.data
end

#owner_idString

The AWS account ID of the owner of the network interface.

Returns:

  • (String)


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

def owner_id
  data.owner_id
end

#private_dns_nameString

The private DNS name.

Returns:

  • (String)


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

def private_dns_name
  data.private_dns_name
end

#private_ip_addressString

The IPv4 address of the network interface within the subnet.

Returns:

  • (String)


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

def private_ip_address
  data.private_ip_address
end

#private_ip_addressesArray<Types::NetworkInterfacePrivateIpAddress>

The private IPv4 addresses associated with the network interface.



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

def private_ip_addresses
  data.private_ip_addresses
end

#requester_idString

The ID of the entity that launched the instance on your behalf (for example, AWS Management Console or Auto Scaling).

Returns:

  • (String)


103
104
105
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 103

def requester_id
  data.requester_id
end

#requester_managedBoolean

Indicates whether the network interface is being managed by AWS.

Returns:

  • (Boolean)


109
110
111
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 109

def requester_managed
  data.requester_managed
end

#reset_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.reset_attribute({
  dry_run: false,
  source_dest_check: "String",
})

Parameters:

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

    ({})

Options Hash (options):

  • :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.

  • :source_dest_check (String)

    The source/destination checking attribute. Resets the value to true.

Returns:

  • (EmptyStructure)


394
395
396
397
398
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 394

def reset_attribute(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.reset_network_interface_attribute(options)
  resp.data
end

#source_dest_checkBoolean

Indicates whether traffic to or from the instance is validated.

Returns:

  • (Boolean)


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

def source_dest_check
  data.source_dest_check
end

#statusString

The status of the network interface.

Returns:

  • (String)


121
122
123
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 121

def status
  data.status
end

#subnetSubnet?

Returns:



433
434
435
436
437
438
439
440
441
442
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 433

def subnet
  if data.subnet_id
    Subnet.new(
      id: data.subnet_id,
      client: @client
    )
  else
    nil
  end
end

#subnet_idString

The ID of the subnet.

Returns:

  • (String)


127
128
129
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 127

def subnet_id
  data.subnet_id
end

#tag_setArray<Types::Tag>

Any tags assigned to the network interface.

Returns:



133
134
135
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 133

def tag_set
  data.tag_set
end

#unassign_private_ip_addresses(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


network_interface.unassign_private_ip_addresses({
  private_ip_addresses: ["String"], # required
})

Parameters:

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

    ({})

Options Hash (options):

  • :private_ip_addresses (required, Array<String>)

    The secondary private IP addresses to unassign from the network interface. You can specify this option multiple times to unassign more than one IP address.

Returns:

  • (EmptyStructure)


411
412
413
414
415
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 411

def unassign_private_ip_addresses(options = {})
  options = options.merge(network_interface_id: @id)
  resp = @client.unassign_private_ip_addresses(options)
  resp.data
end

#vpcVpc?

Returns:



445
446
447
448
449
450
451
452
453
454
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 445

def vpc
  if data.vpc_id
    Vpc.new(
      id: data.vpc_id,
      client: @client
    )
  else
    nil
  end
end

#vpc_idString

The ID of the VPC.

Returns:

  • (String)


139
140
141
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/network_interface.rb', line 139

def vpc_id
  data.vpc_id
end