Sha256: 08fbd0adc908c5c529b6c557b22924b48ed3c7ad1337843955c12e439c83291f

Contents?: true

Size: 1.75 KB

Versions: 22

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

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

22 entries across 20 versions & 2 rubygems

Version Path
fog-aliyun-0.4.0 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.19 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.18 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.17 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.16 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.15 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.13 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.12 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.11 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.10 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.9 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.8 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.7 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.6 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.5 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.4 lib/fog/aliyun/models/compute/eip_address.rb
fog-aliyun-0.3.3 lib/fog/aliyun/models/compute/eip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/eip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/eip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/eip_address.rb