Sha256: 48b6ed3b862e6870416475286866ff74c521c6739169f628e87a4f4bed5a7629

Contents?: true

Size: 1.51 KB

Versions: 32

Compression:

Stored size: 1.51 KB

Contents

module Awspec::Type
  class NetworkInterface < Base
    def initialize(id)
      super
      @resource_via_client = find_network_interface(id)
      @id = @resource_via_client.network_interface_id if @resource_via_client
    end

    STATES = %w(
      available attaching in-use detaching
    )

    STATES.each do |state|
      define_method state.tr('-', '_') + '?' do
        @resource_via_client.status == state
      end
    end

    def attached_to?(instance_id, device_index = 0)
      instance = find_ec2(instance_id)
      return false unless instance
      return false unless @resource_via_client.attachment
      @resource_via_client.attachment.instance_id == instance.instance_id && \
        @resource_via_client.attachment.status == 'attached' && \
        @resource_via_client.attachment.device_index == device_index
    end

    def has_private_ip_address?(ip_address, primary = nil)
      @resource_via_client.private_ip_addresses.find do |i|
        next false if !primary.nil? && i.primary != primary
        i.private_ip_address == ip_address
      end
    end

    def has_security_group?(sg_id)
      sgs = @resource_via_client.groups
      ret = sgs.find do |sg|
        sg.group_id == sg_id || sg.group_name == sg_id
      end
      return true if ret
      sg2 = find_security_group(sg_id)
      return false unless sg2.tag_name == sg_id
      sgs.find do |sg|
        sg.group_id == sg2.group_id
      end
    end

    def private_ip_addresses_count
      @resource_via_client.private_ip_addresses.count
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
awspec-0.55.0 lib/awspec/type/network_interface.rb
awspec-0.54.0 lib/awspec/type/network_interface.rb
awspec-0.52.4 lib/awspec/type/network_interface.rb
awspec-0.52.3 lib/awspec/type/network_interface.rb
awspec-0.52.2 lib/awspec/type/network_interface.rb
awspec-0.52.1 lib/awspec/type/network_interface.rb
awspec-0.52.0 lib/awspec/type/network_interface.rb
awspec-0.51.0 lib/awspec/type/network_interface.rb
awspec-0.50.0 lib/awspec/type/network_interface.rb
awspec-0.49.0 lib/awspec/type/network_interface.rb
awspec-0.48.0 lib/awspec/type/network_interface.rb
awspec-0.47.0 lib/awspec/type/network_interface.rb
awspec-0.46.0 lib/awspec/type/network_interface.rb
awspec-0.45.0 lib/awspec/type/network_interface.rb
awspec-0.44.0 lib/awspec/type/network_interface.rb
awspec-0.43.0 lib/awspec/type/network_interface.rb
awspec-0.42.0 lib/awspec/type/network_interface.rb
awspec-0.41.0 lib/awspec/type/network_interface.rb
awspec-0.40.0 lib/awspec/type/network_interface.rb
awspec-0.39.0 lib/awspec/type/network_interface.rb