This makes it easier for developers new to the codebase to easily get important information on the model's table in the same file as the model code. To ensure the model annotations stay accurate, run them on test_up/test_down. In CI, regenerate the annotations, and check for no changes, similar to how the linters work.
54 lines
2.0 KiB
Ruby
54 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../model"
|
|
|
|
class VmStorageVolume < Sequel::Model
|
|
many_to_one :vm
|
|
many_to_one :spdk_installation
|
|
many_to_one :storage_device
|
|
many_to_one :key_encryption_key_1, class: :StorageKeyEncryptionKey
|
|
many_to_one :key_encryption_key_2, class: :StorageKeyEncryptionKey
|
|
many_to_one :boot_image
|
|
|
|
plugin :association_dependencies, key_encryption_key_1: :destroy, key_encryption_key_2: :destroy
|
|
|
|
include ResourceMethods
|
|
|
|
def device_id
|
|
"#{vm.inhost_name}_#{disk_index}"
|
|
end
|
|
|
|
def device_path
|
|
"/dev/disk/by-id/virtio-#{device_id}"
|
|
end
|
|
|
|
def spdk_version
|
|
spdk_installation.version
|
|
end
|
|
end
|
|
|
|
# Table: vm_storage_volume
|
|
# Columns:
|
|
# id | uuid | PRIMARY KEY
|
|
# vm_id | uuid | NOT NULL
|
|
# boot | boolean | NOT NULL
|
|
# size_gib | bigint | NOT NULL
|
|
# disk_index | integer | NOT NULL
|
|
# key_encryption_key_1_id | uuid |
|
|
# key_encryption_key_2_id | uuid |
|
|
# spdk_installation_id | uuid | NOT NULL
|
|
# use_bdev_ubi | boolean | NOT NULL DEFAULT false
|
|
# skip_sync | boolean | NOT NULL DEFAULT false
|
|
# storage_device_id | uuid | NOT NULL
|
|
# boot_image_id | uuid |
|
|
# Indexes:
|
|
# vm_storage_volume_pkey | PRIMARY KEY btree (id)
|
|
# vm_storage_volume_vm_id_disk_index_key | UNIQUE btree (vm_id, disk_index)
|
|
# Foreign key constraints:
|
|
# vm_storage_volume_boot_image_id_fkey | (boot_image_id) REFERENCES boot_image(id)
|
|
# vm_storage_volume_key_encryption_key_1_id_fkey | (key_encryption_key_1_id) REFERENCES storage_key_encryption_key(id)
|
|
# vm_storage_volume_key_encryption_key_2_id_fkey | (key_encryption_key_2_id) REFERENCES storage_key_encryption_key(id)
|
|
# vm_storage_volume_spdk_installation_id_fkey | (spdk_installation_id) REFERENCES spdk_installation(id)
|
|
# vm_storage_volume_storage_device_id_fkey | (storage_device_id) REFERENCES storage_device(id)
|
|
# vm_storage_volume_vm_id_fkey | (vm_id) REFERENCES vm(id)
|