Sha256: fd019ff1eb568c82599e74bddf0521115dcfeb19d707a8db643c64eef5377061

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*-

module Dcmgr::Models
  class InstanceSpec < AccountResource
    taggable 'is'

    inheritable_schema do
      String :hypervisor, :null=>false
      String :arch, :null=>false
      
      Fixnum :cpu_cores, :null=>false, :unsigned=>true
      Fixnum :memory_size, :null=>false, :unsigned=>true
      Text :config, :null=>false, :default=>''
    end
    with_timestamps

    # serialization plugin must be defined at the bottom of all class
    # method calls.
    # Possible column data:
    #   hypervisor=kvm:
    # {:block_driver=>'virtio', :nic_driver=>'virtio'}
    plugin :serialization
    serialize_attributes :yaml, :config

    def before_validate
      default_config =
        case self.hypervisor
        when HostPool::HYPERVISOR_KVM
          {:block_driver=>'virtio', :nic_driver=>'virtio'}
        end

      self.config = default_config.merge(self.config || {})
      super
    end

    def to_hash
      super.merge({:config=>self.config, # yaml -> Hash
                  })
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
wakame-vdc-dcmgr-10.12.0 lib/dcmgr/models/instance_spec.rb
wakame-vdc-agents-10.12.0 lib/dcmgr/models/instance_spec.rb