Sha256: 16d39418cce7aaac33a88c2a2e5b055df5e66eae93f8a4f2366bf6b134240cd5

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

module Fog
  module AWS
    class EC2

      def addresses
        Fog::AWS::EC2::Addresses.new(:connection => self)
      end

      class Addresses < Fog::Collection

        attribute :public_ip
        attribute :instance_id

        def initialize(attributes)
          @public_ip ||= []
          super
        end

        def all(public_ip = [])
          data = connection.describe_addresses(public_ip).body
          addresses = Fog::AWS::EC2::Addresses.new({
            :connection => connection,
            :public_ip  => public_ip
          }.merge!(attributes))
          data['addressesSet'].each do |address|
            addresses << Fog::AWS::EC2::Address.new({
              :addresses  => addresses,
              :connection => connection
            }.merge!(address))
          end
          if instance_id
            addresses = addresses.select {|address| address.instance_id == instance_id}
          end
          addresses
        end

        def create
          address = new
          address.save
          address
        end

        def get(public_ip)
          all(public_ip).first
        rescue Fog::Errors::BadRequest
          nil
        end

        def new
          Fog::AWS::EC2::Address.new(
            :addresses  => self,
            :connection => connection
          )
        end

        def reload
          all(public_ip)
        end

      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fog-0.0.22 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.21 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.20 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.19 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.18 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.17 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.16 lib/fog/aws/models/ec2/addresses.rb
fog-0.0.15 lib/fog/aws/models/ec2/addresses.rb