Skip to content

Commit

Permalink
activate LV before SSA if inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
nasark committed Jun 20, 2024
1 parent 1dc3fb6 commit f3a9263
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/MiqVm/MiqRhevmVm.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'awesome_spawn'
require 'MiqVm/MiqVm'

class MiqRhevmVm < MiqVm
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit f3a9263

Please sign in to comment.