Sha256: 06bc7baefe602108d35d067313018d6f8e251faa485c66987f2a6e20a8b02ba3

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module Fog
  module AWS
    class EC2

      class Address < Fog::Model

        identity  :public_ip,   'publicIp'

        attribute :instance_id, 'instanceId'

        def destroy
          requires :public_ip

          connection.release_address(@public_ip)
          true
        end

        def instance=(new_instance)
          if new_instance
            associate(new_instance)
          else
            disassociate
          end
        end

        def save
          data = connection.allocate_address
          @public_ip = data.body['publicIp']
          if @instance
            self.instance = @instance
          end
          true
        end

        private

        def associate(new_instance)
          if new_record?
            @instance = new_instance
          else
            @instance = nil
            @instance_id = new_instance.id
            connection.associate_address(@instance_id, @public_ip)
          end
        end

        def disassociate
          @instance = nil
          @instance_id = nil
          unless new_record?
            connection.disassociate_address(@public_ip)
          end
        end

      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fog-0.0.39 lib/fog/aws/models/ec2/address.rb
fog-0.0.38 lib/fog/aws/models/ec2/address.rb
fog-0.0.37 lib/fog/aws/models/ec2/address.rb
fog-0.0.36 lib/fog/aws/models/ec2/address.rb
fog-0.0.35 lib/fog/aws/models/ec2/address.rb
fog-0.0.34 lib/fog/aws/models/ec2/address.rb
fog-0.0.33 lib/fog/aws/models/ec2/address.rb