Managing multiple storage devices per VM indicates makes the old one-to-one assumptions of the code in `vm_path.rb` obsolete. This patch introduces a similar `storage_path.rb` that is capable of computing paths for multiple storage devices. With the exception of the storage-key-tool interface change -- largely harmless as the key tool is not run automatically -- these rhizome changes are thought to be backwards compatible, and can be deployed first. Hadi wrote the code, but I am taking responsibility for breaking it up and deploying it. Co-authored-by: Hadi Moshayedi <hadi@ubicloud.com>
39 lines
839 B
Ruby
39 lines
839 B
Ruby
# frozen_string_literal: true
|
|
|
|
DEFAULT_STORAGE_DEVICE = "DEFAULT"
|
|
|
|
class StoragePath
|
|
def initialize(vm_name, device, disk_index)
|
|
@vm_name = vm_name
|
|
@device = device
|
|
@disk_index = disk_index
|
|
end
|
|
|
|
def device_path
|
|
@device_path ||=
|
|
(@device == DEFAULT_STORAGE_DEVICE) ?
|
|
File.join("", "var", "storage") :
|
|
File.join("", "var", "storage", "devices", @device)
|
|
end
|
|
|
|
def storage_root
|
|
@storage_root ||= File.join(device_path, @vm_name)
|
|
end
|
|
|
|
def storage_dir
|
|
@storage_dir ||= File.join(storage_root, @disk_index.to_s)
|
|
end
|
|
|
|
def disk_file
|
|
@disk_file ||= File.join(storage_dir, "disk.raw")
|
|
end
|
|
|
|
def data_encryption_key
|
|
@dek_path ||= File.join(storage_dir, "data_encryption_key.json")
|
|
end
|
|
|
|
def vhost_sock
|
|
@vhost_sock ||= File.join(storage_dir, "vhost.sock")
|
|
end
|
|
end
|