lib/MiqVm/MiqRhevmVm.rb in manageiq-smartstate-0.9.0 vs lib/MiqVm/MiqRhevmVm.rb in manageiq-smartstate-0.10.0

- old
+ new

@@ -1,5 +1,6 @@ +require 'awesome_spawn' require 'MiqVm/MiqVm' class MiqRhevmVm < MiqVm RHEV_NFS_UID = 36 @@ -49,26 +50,30 @@ end storage_id = storage_domain.id 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 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 lun_file_path(storage_obj, disk) end @@ -174,7 +179,22 @@ FileUtils.rm_rf(nfs_mount_root) @ost.nfs_storage_mounted = false rescue $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