Sha256: ac555b0ee097f1bbc00381957ffcba2351c6a3c2c858df1891f254857d06b5be

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

require 'fog/core/model'
module Fog
  module Compute
    class Aliyun
      class EipAddress < Fog::Model
        identity :id,             aliases: 'AllocationId'

        attribute :allocated_at,  aliases: 'AllocationTime'
        attribute :bandwidth,     aliases: 'Bandwidth'
        attribute :server_id,     aliases: 'InstanceId'
        attribute :charge_type,   aliases: 'InternetChargeType'
        attribute :ip_address,    aliases: %w(IpAddress EipAddress)
        attribute :opertion_locks, aliases: 'OperationLocks'
        attribute :region_id,     aliases: 'RegionId'
        attribute :state,         aliases: 'Status'

        def destroy
          requires :id
          service.release_eip_address(id)
          true
        end

        def ready?
          requires :state
          state == 'Available'
        end

        def save(options = {})
          # raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
          # requires :availability_zone
          options[:bandwidth] = bandwidth if bandwidth
          options[:internet_charge_type] = charge_type if charge_type

          data = Fog::JSON.decode(service.allocate_eip_address(options).body)
          merge_attributes(data)
          true
        end

        def associate(new_server, options = {})
          if persisted?
            @server = nil
            self.server_id = new_server.id
            service.associate_eip_address(server_id, id, options)
          else
            @server = new_server
          end
        end

        def disassociate(new_server, options = {})
          @server = nil
          self.server_id = new_server.id
          service.unassociate_eip_address(server_id, id, options) if persisted?
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fog-aliyun-0.3.0 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.2.2 lib/fog/aliyun/models/compute/eip_address.rb
fog-xiaozhu-0.2.2 lib/fog/aliyun/models/compute/eip_address.rb
fog-xiaozhu-0.2.1 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.2.1 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.2.0 lib/fog/aliyun/models/compute/eip_address.rb