Class: Dcmgr::Models::Image

Inherits:
AccountResource show all
Defined in:
lib/dcmgr/models/image.rb

Overview

Metadata catalogs for bootable image file.

Constant Summary collapse

BOOT_DEV_SAN =
1
BOOT_DEV_LOCAL =
2

Constants inherited from BaseNew

BaseNew::LOCK_TABLES_KEY

Instance Method Summary collapse

Methods inherited from AccountResource

#account

Methods inherited from BaseNew

Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?

Instance Method Details

#to_api_document(lookup_account_id) ⇒ Object

note on “lookup_account_id”: the source column sometime contains the information which should not be shown to other accounts. so that the method takes an argument who is looking into then filters the data in source column accordingly.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dcmgr/models/image.rb', line 61

def to_api_document()
  h = to_hash
  if self. == 
  else
    if h[:source][:type] == :http
      # do not show URI for non-owner accounts.
      h[:source][:uri] = nil
    end
  end
  h
end

#to_hashObject



52
53
54
# File 'lib/dcmgr/models/image.rb', line 52

def to_hash
  super.merge({:source=>self.source.dup, :description=>description.to_s})
end

#validateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dcmgr/models/image.rb', line 33

def validate
  unless [BOOT_DEV_SAN, BOOT_DEV_LOCAL].member?(self.boot_dev_type)
    errors.add(:boot_dev_type, "Invalid boot dev type: #{self.boot_dev_type}")
  end
  
  unless HostPool::SUPPORTED_ARCH.member?(self.arch)
    errors.add(:arch, "Unsupported arch type: #{self.arch}")
  end
  
  # validate source
  md = self.source
  case self.boot_dev_type
  when BOOT_DEV_LOCAL
    errors.add(:source, "Unknown image URI") if md[:uri].nil? || md[:uri] == ''
  when BOOT_DEV_SAN
    errors.add(:source, "Unknown snapshot ID") if md[:snapshot_id].nil? || md[:snapshot_id] == '' || VolumeSnapshot[md[:snapshot_id]].nil?
  end
end