lib/dcmgr/models/instance_spec.rb in wakame-vdc-agents-10.11.0 vs lib/dcmgr/models/instance_spec.rb in wakame-vdc-agents-10.12.0
- old
+ new
@@ -12,10 +12,30 @@
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=>config.to_s})
+ super.merge({:config=>self.config, # yaml -> Hash
+ })
end
end
end