From f3a92632706878f3281bfeae3f5558b6d828f491 Mon Sep 17 00:00:00 2001 From: Nasar Khan Date: Mon, 18 Mar 2024 11:15:03 -0400 Subject: [PATCH] activate LV before SSA if inactive --- lib/MiqVm/MiqRhevmVm.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/MiqVm/MiqRhevmVm.rb b/lib/MiqVm/MiqRhevmVm.rb index 8898510..4923857 100644 --- a/lib/MiqVm/MiqRhevmVm.rb +++ b/lib/MiqVm/MiqRhevmVm.rb @@ -1,3 +1,4 @@ +require 'awesome_spawn' require 'MiqVm/MiqVm' class MiqRhevmVm < MiqVm @@ -51,12 +52,17 @@ def getCfg(_snap = nil) storage_obj = storage_domains_by_id[storage_id] file_path = file_path_for_storage_type(storage_obj, disk) + file_path_s = file_path.to_s tag = "scsi0:#{idx}" cfg_hash["#{tag}.present"] = "true" cfg_hash["#{tag}.devicetype"] = "disk" - cfg_hash["#{tag}.filename"] = file_path.to_s + cfg_hash["#{tag}.filename"] = file_path_s cfg_hash["#{tag}.format"] = disk.format + + if storage_type_block?(storage_obj.storage.type) && !lv_active?(file_path_s) + AwesomeSpawn.run!("sudo lvchange", :params => [:activate, "y", file_path_s]) + end end cfg_hash end @@ -65,8 +71,7 @@ def file_path_for_storage_type(storage_obj, disk) storage_type = storage_obj&.storage&.type # TODO: account for other storage types here. - case storage_type - when "nfs", "glusterfs" + if storage_type_file?(storage_type) add_fs_mount(storage_obj) fs_file_path(storage_obj, disk) else @@ -177,4 +182,19 @@ def unmount_storage $log.warn "#{log_header} Failed to unmount all items from <#{nfs_mount_root}>. Reason: <#{$!}>" end end + + private + + # Output attributes of LV in column format and parse to retrieve active status + def lv_active?(lv_path) + AwesomeSpawn.run!("sudo lvs", :params => [:noheadings, :o, "lv_active", lv_path]).output.strip == "active" + end + + def storage_type_block?(storage_type) + ["ISCSI", "FCP"].include?(storage_type.upcase) + end + + def storage_type_file?(storage_type) + ["NFS", "GLUSTERFS"].include?(storage_type.upcase) + end end