Represents a network interface in EC2.
@return [String]
@return [String]
# File lib/aws/ec2/network_interface.rb, line 24 def initialize network_interface_id, options = {} @network_interface_id = network_interface_id super end
@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 126 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
# File lib/aws/ec2/network_interface.rb, line 110 def attachment if details = attachment_details Attachment.new(self, details) end end
Deletes this network interface. @return [nil]
# File lib/aws/ec2/network_interface.rb, line 155 def delete client_opts = {} client_opts[:network_interface_id] = network_interface_id client.delete_network_interface(client_opts) nil end
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 145 def detach options = {} if attachment = self.attachment attachment.detach(options) else raise 'unable to detach network interface, no attachment present' end end
@return [Boolean] Returns true if this network interface exists.
# File lib/aws/ec2/network_interface.rb, line 163 def exists? begin get_resource true rescue Errors::InvalidNetworkInterfaceID::NotFound false end end
@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 104 def instance if attachment = self.attachment attachment.instance end end
@return [Array<SecurityGroup>]
# File lib/aws/ec2/network_interface.rb, line 81 def security_groups groups.collect do |g| SecurityGroup.new(g.group_id, :name => g.group_name, :config => config) end end
@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 93 def set_security_groups *groups self.groups = [groups].flatten.collect do |g| g.is_a?(SecurityGroup) ? g.security_group_id : g end nil end
@return [Subnet] Returns the Subnet this network interface
belongs to.
# File lib/aws/ec2/network_interface.rb, line 76 def subnet Subnet.new(subnet_id, :vpc_id => vpc_id, :config => config) end
@return [VPC] Returns the VPC this network interface belongs to.
# File lib/aws/ec2/network_interface.rb, line 70 def vpc VPC.new(vpc_id, :config => config) end