lib/dcmgr/models/volume.rb in wakame-vdc-dcmgr-10.11.0 vs lib/dcmgr/models/volume.rb in wakame-vdc-dcmgr-10.12.0

- old
+ new

@@ -25,10 +25,11 @@ Fixnum :storage_pool_id, :null=>false String :status, :null=>false, :default=>STATUS_TYPE_REGISTERING String :state, :null=>false, :default=>STATE_TYPE_REGISTERING Fixnum :size, :null=>false Fixnum :instance_id + Fixnum :boot_dev, :null=>false, :default=>0 String :snapshot_id String :host_device_name String :guest_device_name String :export_path, :null=>false Text :transport_information @@ -39,20 +40,22 @@ index :instance_id index :snapshot_id end with_timestamps + many_to_one :storage_pool + many_to_one :instance + + plugin ArchiveChangedColumn, :histories + # serialization plugin must be defined at the bottom of all class # method calls. # Possible column data: # iscsi: # {:iqn=>'iqn.1986-03.com.sun:02:a1024afa-775b-65cf-b5b0-aa17f3476bfc', :lun=>0} plugin :serialization, :yaml, :transport_information - many_to_one :storage_pool - many_to_one :instance - class DiskError < RuntimeError; end class RequestError < RuntimeError; end def before_create # check the volume size @@ -91,11 +94,11 @@ data[:filter] end vl = vl.grep(data[:target].to_sym, "%#{filter}%") end vl.all.map{|row| - row.to_hash_document + row.to_api_document } end def self.delete_volume(account_id, uuid) v = self.dataset.where(:account_id=>account_id).where(:uuid=>uuid.split('-').last).first @@ -106,19 +109,33 @@ v.save_changes v end def merge_pool_data - v = self.to_hash_document - v.merge(:storage_pool=>storage_pool.to_hash_document) + v = self.to_hash + v.merge(:storage_pool=>storage_pool.to_hash) end - def to_hash_document - h = self.values.dup - h[:id] = h[:uuid] = h[:export_path] = self.canonical_uuid + def to_hash + h = super # yaml -> hash translation h[:transport_information]=self.transport_information h + end + + # Hash data for API response. + def to_api_document + h = { + :id => self.canonical_uuid, + :uuid => self.canonical_uuid, + :size => self.size, + :snapshot_id => self.snapshot_id, + :created_at => self.created_at, + :attached_at => self.attached_at, + :state => self.state, + :instance_id => (self.instance && self.instance.canonical_uuid), + :deleted_at => self.deleted_at, + } end def create_snapshot(account_id) vs = VolumeSnapshot.create(:account_id=>account_id, :storage_pool_id=>self.storage_pool_id,