Class: Dcmgr::Models::Image
- Inherits:
-
AccountResource
- Object
- Sequel::Model
- BaseNew
- AccountResource
- Dcmgr::Models::Image
- 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
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #get_feature(key) ⇒ Object
-
#set_feature(key, value) ⇒ Object
TODO: more proper key&value validation.
-
#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.
- #to_hash ⇒ Object
- #validate ⇒ Object
Methods inherited from AccountResource
Methods inherited from BaseNew
Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?
Instance Method Details
#after_initialize ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dcmgr/models/image.rb', line 19 def after_initialize super unless self.features.is_a?(Hash) self.features = {} end end |
#get_feature(key) ⇒ Object
82 83 84 |
# File 'lib/dcmgr/models/image.rb', line 82 def get_feature(key) self.features[key] end |
#set_feature(key, value) ⇒ Object
TODO: more proper key&value validation. Handles the feature blob column.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dcmgr/models/image.rb', line 70 def set_feature(key, value) case key.to_sym when :virtio self.features[:virtio] = value else raise "Unsupported feature: #{key}" end self.changed_columns << :features self end |
#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.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dcmgr/models/image.rb', line 56 def to_api_document(lookup_account_id) h = super() if self.account_id == lookup_account_id else if h[:source][:type] == :http # do not show URI for non-owner accounts. h[:source][:uri] = nil end end h end |
#to_hash ⇒ Object
47 48 49 |
# File 'lib/dcmgr/models/image.rb', line 47 def to_hash super.merge({:source=>self.source, :description=>self.description.to_s, :features=>self.features}) end |
#validate ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dcmgr/models/image.rb', line 26 def validate super 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 HostNode::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 |