Class: AWS::EC2::NetworkInterface

Inherits:
Resource
  • Object
show all
Includes:
TaggedItem
Defined in:
lib/aws/ec2/network_interface.rb,
lib/aws/ec2/network_interface/attachment.rb

Overview

Represents a network interface in EC2.

Defined Under Namespace

Classes: Attachment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #clear_tags, #tags

Constructor Details

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

Returns a new instance of NetworkInterface.



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

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

Instance Attribute Details

#associationHash? (readonly)

Returns a hash of details about the association between this network interface and an elastic ip address.

Returns:

  • (Hash, nil)

    the current value of association



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def association
  @association
end

#availability_zone_nameString (readonly)

Returns the current value of availability_zone_name.

Returns:

  • (String)

    the current value of availability_zone_name



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def availability_zone_name
  @availability_zone_name
end

#descriptionString

Returns the current value of description.

Returns:

  • (String)

    the current value of description



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def description
  @description
end

#mac_addressString (readonly)

Returns the current value of mac_address.

Returns:

  • (String)

    the current value of mac_address



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def mac_address
  @mac_address
end

#network_interface_idString (readonly) Also known as: id

Returns:

  • (String)


57
58
59
# File 'lib/aws/ec2/network_interface.rb', line 57

def network_interface_id
  @network_interface_id
end

#owner_idString (readonly)

Returns the current value of owner_id.

Returns:

  • (String)

    the current value of owner_id



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def owner_id
  @owner_id
end

#private_dns_nameString (readonly)

Returns the current value of private_dns_name.

Returns:

  • (String)

    the current value of private_dns_name



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def private_dns_name
  @private_dns_name
end

#private_ip_addressString (readonly)

Returns the current value of private_ip_address.

Returns:

  • (String)

    the current value of private_ip_address



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def private_ip_address
  @private_ip_address
end

#requester_managedBoolean Also known as: requester_managed?

Returns the current value of requester_managed.

Returns:

  • (Boolean)

    the current value of requester_managed



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def requester_managed
  @requester_managed
end

#source_dest_checkBoolean Also known as: source_dest_check?

Returns the current value of source_dest_check.

Returns:

  • (Boolean)

    the current value of source_dest_check



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def source_dest_check
  @source_dest_check
end

#statusSymbol (readonly)

Returns the current value of status.

Returns:

  • (Symbol)

    the current value of status



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def status
  @status
end

#subnet_idString (readonly)

Returns the current value of subnet_id.

Returns:

  • (String)

    the current value of subnet_id



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def subnet_id
  @subnet_id
end

#vpc_idString (readonly)

Returns the current value of vpc_id.

Returns:

  • (String)

    the current value of vpc_id



47
48
49
# File 'lib/aws/ec2/network_interface.rb', line 47

def vpc_id
  @vpc_id
end

Instance Method Details

#attach(instance, options = {}) ⇒ nil

Parameters:

  • instance (Instance, String)

    The instance to attach this network interface to, may be an Instance object or an instance id string.

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

Options Hash (options):

  • :device_index (Integer) — default: 1

    The index of the device for the network interface attachment on the instance. Defaults to 1.

Returns:

  • (nil)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/aws/ec2/network_interface.rb', line 180

def attach instance, options = {}

  instance_id = instance.is_a?(Instance) ? instance.instance_id : instance

  client_opts = {}
  client_opts[:network_interface_id] = network_interface_id
  client_opts[:instance_id] = instance_id
  client_opts[:device_index] = options[:device_index] || 1

  client.attach_network_interface(client_opts)

  nil

end

#attachmentAttachment?

Returns:



164
165
166
167
168
# File 'lib/aws/ec2/network_interface.rb', line 164

def attachment
  if details = attachment_details
    Attachment.new(self, details)
  end
end

#availability_zoneAvailabilityZone

Returns:



129
130
131
# File 'lib/aws/ec2/network_interface.rb', line 129

def availability_zone
  AvailabilityZone.new(availability_zone_name, :config => config)
end

#deletenil

Deletes this network interface.

Returns:

  • (nil)


209
210
211
212
213
214
# File 'lib/aws/ec2/network_interface.rb', line 209

def delete
  client_opts = {}
  client_opts[:network_interface_id] = network_interface_id
  client.delete_network_interface(client_opts)
  nil
end

#detach(options = {}) ⇒ nil

Detaches this network interface.

Parameters:

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

Options Hash (options):

  • :force (Boolean) — default: false

    Set true to force a detachment.

Returns:

  • (nil)


199
200
201
202
203
204
205
# File 'lib/aws/ec2/network_interface.rb', line 199

def detach options = {}
  if attachment = self.attachment
    attachment.detach(options)
  else
    raise 'unable to detach network interface, no attachment present'
  end
end

#elastic_ipElasticIp?

Returns:



121
122
123
124
125
126
# File 'lib/aws/ec2/network_interface.rb', line 121

def elastic_ip
  if association = self.association
    opts = association.merge(:config => config)
    ElasticIp.new(association[:public_ip], opts)
  end
end

#exists?Boolean

Returns true if this network interface exists.

Returns:

  • (Boolean)

    Returns true if this network interface exists.



217
218
219
220
221
222
223
224
# File 'lib/aws/ec2/network_interface.rb', line 217

def exists?
  begin
    get_resource
    true
  rescue Errors::InvalidNetworkInterfaceID::NotFound
    false
  end
end

#instanceInstance?

Returns the instance this network interface is attached to. If it has not been attached, then nil is returned.

Returns:

  • (Instance, nil)

    Returns the instance this network interface is attached to. If it has not been attached, then nil is returned.



157
158
159
160
161
# File 'lib/aws/ec2/network_interface.rb', line 157

def instance
  if attachment = self.attachment
    attachment.instance
  end
end

#security_groupsArray<SecurityGroup>

Returns:



134
135
136
137
138
# File 'lib/aws/ec2/network_interface.rb', line 134

def security_groups
  groups.collect do |g|
    SecurityGroup.new(g.group_id, :name => g.group_name, :config => config)
  end
end

#set_security_groups(*groups) ⇒ nil Also known as: security_groups=

Parameters:

  • groups (Array<SecurityGroup>, Array<String>)

    A list of security groups objects or security group ids. This replaces the security group set on this network interface.

Returns:

  • (nil)


146
147
148
149
150
151
# File 'lib/aws/ec2/network_interface.rb', line 146

def set_security_groups *groups
  self.groups = [groups].flatten.collect do |g|
    g.is_a?(SecurityGroup) ? g.security_group_id : g
  end
  nil
end

#subnetSubnet

Returns the Subnet this network interface belongs to.

Returns:

  • (Subnet)

    Returns the Subnet this network interface belongs to.



116
117
118
# File 'lib/aws/ec2/network_interface.rb', line 116

def subnet
  Subnet.new(subnet_id, :vpc_id => vpc_id, :config => config)
end

#vpcVPC

Returns the VPC this network interface belongs to.

Returns:

  • (VPC)

    Returns the VPC this network interface belongs to.



110
111
112
# File 'lib/aws/ec2/network_interface.rb', line 110

def vpc
  VPC.new(vpc_id, :config => config)
end