Improve drive detection when block devices appear but have no disk
This commit is contained in:
parent
459dd6ecf4
commit
a4c7bbc999
|
@ -33,6 +33,9 @@ def reset_clone_error():
|
|||
def reset_clone_confirm():
|
||||
os.system("rm /tmp/.clone_confirm")
|
||||
|
||||
def reset_clone_rescan():
|
||||
os.system("rm /tmp/.clone_rescan")
|
||||
|
||||
def set_clone_error(error_msg):
|
||||
print_and_log("Clone Error: {}".format(error_msg))
|
||||
try:
|
||||
|
@ -93,6 +96,16 @@ def find_partitions_for_drive(drive):
|
|||
pass
|
||||
return partitions
|
||||
|
||||
def is_drive_detected_by_fdisk(d):
|
||||
detected = False
|
||||
try:
|
||||
# Command fails and throws exception if not mounted
|
||||
ls_output = subprocess.check_output(f"fdisk -l /dev/{d}", shell=True).decode("utf-8")
|
||||
detected = True
|
||||
except:
|
||||
pass
|
||||
return detected
|
||||
|
||||
def is_drive_mounted(d):
|
||||
mounted = True
|
||||
try:
|
||||
|
@ -110,7 +123,7 @@ def find_drives():
|
|||
|
||||
# Only return drives that are not mounted (VM may have /dev/sda as OS drive)
|
||||
for d in all_drives:
|
||||
if not is_drive_mounted(d):
|
||||
if is_drive_detected_by_fdisk(d) and not is_drive_mounted(d):
|
||||
drives.append(d)
|
||||
except:
|
||||
pass
|
||||
|
@ -121,6 +134,7 @@ def main():
|
|||
set_clone_state("detecting")
|
||||
reset_clone_error()
|
||||
reset_clone_confirm()
|
||||
reset_clone_rescan()
|
||||
os.system("umount /mnt/hdd")
|
||||
os.system("rm /tmp/.clone_target_drive_has_mynode")
|
||||
|
||||
|
@ -204,9 +218,14 @@ def main():
|
|||
os.system(f"echo {mynode_drive} > /tmp/.clone_source")
|
||||
os.system(f"echo {target_drive} > /tmp/.clone_target")
|
||||
set_clone_state("need_confirm")
|
||||
while not os.path.isfile("/tmp/.clone_confirm"):
|
||||
while not os.path.isfile("/tmp/.clone_confirm") and not os.path.isfile("/tmp/.clone_rescan"):
|
||||
time.sleep(1)
|
||||
|
||||
# User asked for rescan - recursively call main
|
||||
if os.path.isfile("/tmp/.clone_rescan"):
|
||||
main()
|
||||
return
|
||||
|
||||
# Clone drives
|
||||
set_clone_state("in_progress")
|
||||
os.system("echo 'Starting clone.' > /tmp/.clone_progress")
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
$("#format-confirm").on("click", function() {
|
||||
window.location.href="/?clone_confirm=1"
|
||||
});
|
||||
$("#rescan-drives").on("click", function() {
|
||||
window.location.href="/?clone_rescan=1"
|
||||
});
|
||||
$("#reboot-device").on("click", function() {
|
||||
window.location.href="/settings/reboot-device"
|
||||
});
|
||||
|
@ -81,9 +84,11 @@
|
|||
<p>It is highly recommended that both drives be externally powered. Running two drives from USB power on the device can cause clone failures.</p>
|
||||
|
||||
<br/>
|
||||
<button id="format-confirm" value="Login" class="ui-button ui-widget ui-corner-all format_button">Confirm Clone</button>
|
||||
<button id="format-confirm" value="Confirm Clone" class="ui-button ui-widget ui-corner-all format_button">Confirm Clone</button>
|
||||
<br/><br/>
|
||||
<button id="reboot-device" value="Login" class="ui-button ui-widget ui-corner-all format_button">Reboot</button>
|
||||
<button id="rescan-drives" value="Rescan Drives" class="ui-button ui-widget ui-corner-all format_button">Rescan Drives</button>
|
||||
<br/><br/>
|
||||
<button id="reboot-device" value="Reboot" class="ui-button ui-widget ui-corner-all format_button">Reboot</button>
|
||||
|
||||
<br/><br/>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user