Sha256: f1eea6539e731e9b41800b38037bd5a41893b13429d516cfff7c362e3b23cfec

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

module Fog
  module AWS
    class EC2

      class Address < Fog::Model

        identity  :public_ip,   'publicIp'

        attribute :server_id, 'instanceId'

        def destroy
          requires :public_ip

          connection.release_address(@public_ip)
          true
        end

        def server=(new_server)
          if new_server
            associate(new_server)
          else
            disassociate
          end
        end

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

        private

        def associate(new_server)
          if new_record?
            @server = new_server
          else
            @server = nil
            @server_id = new_server.id
            connection.associate_address(@server_id, @public_ip)
          end
        end

        def disassociate
          @server = nil
          @server_id = nil
          unless new_record?
            connection.disassociate_address(@public_ip)
          end
        end

      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fog-0.0.56 lib/fog/aws/models/ec2/address.rb
fog-0.0.55 lib/fog/aws/models/ec2/address.rb
fog-0.0.54 lib/fog/aws/models/ec2/address.rb
fog-0.0.53 lib/fog/aws/models/ec2/address.rb
fog-0.0.52 lib/fog/aws/models/ec2/address.rb
fog-0.0.51 lib/fog/aws/models/ec2/address.rb
fog-0.0.50 lib/fog/aws/models/ec2/address.rb
fog-0.0.49 lib/fog/aws/models/ec2/address.rb
fog-0.0.48 lib/fog/aws/models/ec2/address.rb
fog-0.0.47 lib/fog/aws/models/ec2/address.rb
fog-0.0.46 lib/fog/aws/models/ec2/address.rb
fog-0.0.45 lib/fog/aws/models/ec2/address.rb
fog-0.0.44 lib/fog/aws/models/ec2/address.rb
fog-0.0.43 lib/fog/aws/models/ec2/address.rb
fog-0.0.42 lib/fog/aws/models/ec2/address.rb
fog-0.0.41 lib/fog/aws/models/ec2/address.rb
fog-0.0.40 lib/fog/aws/models/ec2/address.rb