class AWS::EC2::NetworkInterface

Represents a network interface in EC2.

@attr [String] description

@attr_reader [String] vpc_id

@attr_reader [String] subnet_id

@attr_reader [String] owner_id

@attr_reader [Symbol] status

@attr_reader [String] private_ip_address

@attr_reader [String] private_dns_name

@attr_reader [String] availability_zone_name

@attr_reader [String] mac_address

@attr_reader [Hash,nil] association Returns a hash of

details about the association between this network interface
and an elastic ip address.

@attr [Boolean] source_dest_check

@attr [Boolean] requester_managed

Attributes

id[R]

@return [String]

network_interface_id[R]

@return [String]

Public Class Methods

new(network_interface_id, options = {}) click to toggle source
# File lib/aws/ec2/network_interface.rb, line 51
def initialize network_interface_id, options = {}
  @network_interface_id = network_interface_id
  super
end

Public Instance Methods

attach(instance, options = {}) click to toggle source

@param [Instance,String] instance The instance to attach this network

interface to, may be an {Instance} object or an instance id string.

@param [Hash] options

@option options [Integer] :device_index (1) The index of the device

for the network interface attachment on the instance.  Defaults to 1.

@return [nil]

# 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
attachment() click to toggle source

@return [Attachment,nil]

# File lib/aws/ec2/network_interface.rb, line 164
def attachment
  if details = attachment_details
    Attachment.new(self, details)
  end
end
availability_zone() click to toggle source

@return [AvailabilityZone]

# File lib/aws/ec2/network_interface.rb, line 129
def availability_zone
  AvailabilityZone.new(availability_zone_name, :config => config)
end
delete() click to toggle source

Deletes this network interface. @return [nil]

# 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 = {}) click to toggle source

Detaches this network interface. @param [Hash] options @option (see AWS::EC2::NetworkInterface::Attachment#detach) @return (see AWS::EC2::NetworkInterface::Attachment#detach)

# 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_ip() click to toggle source

@return [ElasticIp,nil]

# 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?() click to toggle source

@return [Boolean] Returns true if this network interface exists.

# File lib/aws/ec2/network_interface.rb, line 217
def exists?
  begin
    get_resource
    true
  rescue Errors::InvalidNetworkInterfaceID::NotFound
    false
  end
end
instance() click to toggle source

@return [Instance,nil] Returns the instance this network interface

is attached to.  If it has not been attached, then nil is
returned.
# File lib/aws/ec2/network_interface.rb, line 157
def instance
  if attachment = self.attachment
    attachment.instance
  end
end
security_groups() click to toggle source

@return [Array<SecurityGroup>]

# 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
security_groups=(*groups) click to toggle source
Alias for: set_security_groups
set_security_groups(*groups) click to toggle source

@param [Array<SecurityGroup>,Array<String>] groups A list of

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

@return [nil]

# 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
Also aliased as: security_groups=
subnet() click to toggle source

@return [Subnet] Returns the Subnet this network interface

belongs to.
# File lib/aws/ec2/network_interface.rb, line 116
def subnet
  Subnet.new(subnet_id, :vpc_id => vpc_id, :config => config)
end
vpc() click to toggle source

@return [VPC] Returns the VPC this network interface belongs to.

# File lib/aws/ec2/network_interface.rb, line 110
def vpc
  VPC.new(vpc_id, :config => config)
end