mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-01 04:41:38 +00:00
Refactor line rendering logic, and add support for conditional displaying of LUN; Made some variables more generic, not explicitly RaSCSI. (#999)
This commit is contained in:
parent
8e6be9856e
commit
2645656199
|
@ -66,21 +66,21 @@ parser.add_argument(
|
||||||
type=str,
|
type=str,
|
||||||
default="",
|
default="",
|
||||||
action="store",
|
action="store",
|
||||||
help="Token password string for authenticating with RaSCSI",
|
help="Token password string for authenticating with the backend",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--rascsi-host",
|
"--host",
|
||||||
type=str,
|
type=str,
|
||||||
default="localhost",
|
default="localhost",
|
||||||
action="store",
|
action="store",
|
||||||
help="RaSCSI host. Default: localhost",
|
help="Backend hostname. Default: localhost",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--rascsi-port",
|
"--port",
|
||||||
type=str,
|
type=str,
|
||||||
default=6868,
|
default=6868,
|
||||||
action="store",
|
action="store",
|
||||||
help="RaSCSI port. Default: 6868",
|
help="Backend port number. Default: 6868",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ elif args.height == 32:
|
||||||
|
|
||||||
TOKEN = args.password
|
TOKEN = args.password
|
||||||
|
|
||||||
sock_cmd = SocketCmds(host=args.rascsi_host, port=args.rascsi_port)
|
sock_cmd = SocketCmds(host=args.host, port=args.port)
|
||||||
ractl_cmd = RaCtlCmds(sock_cmd=sock_cmd, token=TOKEN)
|
ractl_cmd = RaCtlCmds(sock_cmd=sock_cmd, token=TOKEN)
|
||||||
sys_cmd = SysCmds()
|
sys_cmd = SysCmds()
|
||||||
|
|
||||||
|
@ -171,45 +171,37 @@ def formatted_output():
|
||||||
Formats the strings to be displayed on the Screen
|
Formats the strings to be displayed on the Screen
|
||||||
Returns a (list) of (str) output
|
Returns a (list) of (str) output
|
||||||
"""
|
"""
|
||||||
rascsi_list = ractl_cmd.list_devices()['device_list']
|
device_list = ractl_cmd.list_devices()["device_list"]
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
if not TOKEN and not ractl_cmd.is_token_auth()["status"]:
|
if not TOKEN and not ractl_cmd.is_token_auth()["status"]:
|
||||||
output.append("Permission denied!")
|
output += ["Permission denied!"]
|
||||||
elif rascsi_list:
|
elif device_list:
|
||||||
for line in rascsi_list:
|
has_luns = False
|
||||||
# Transliterate non-Latin characters
|
for line in device_list:
|
||||||
if line["file"]:
|
# If any device is using a LUN > 0 then display LUN for all devices
|
||||||
line["file"] = unidecode(line["file"])
|
if line["unit"] > 0:
|
||||||
if line["device_type"] in REMOVABLE_DEVICE_TYPES:
|
has_luns = True
|
||||||
# Print image file name only when there is an image attached
|
break
|
||||||
if line["file"]:
|
for device in device_list:
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} "
|
line = [str(device["id"])]
|
||||||
f"{line['file']} {line['status']}")
|
if has_luns:
|
||||||
else:
|
line += [str(device["unit"])]
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['status']}")
|
line += [device["device_type"][2:4]]
|
||||||
# Special handling of devices that don't use image files
|
if device["file"]:
|
||||||
elif line["device_type"] in PERIPHERAL_DEVICE_TYPES:
|
# Transliterate non-Latin characters in the file name
|
||||||
if line["vendor"] == "RaSCSI":
|
line += [unidecode(device["file"])]
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['product']}")
|
|
||||||
else:
|
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['vendor']} "
|
|
||||||
f"{line['product']}")
|
|
||||||
# Print only the Vendor/Product info if it's not generic RaSCSI
|
# Print only the Vendor/Product info if it's not generic RaSCSI
|
||||||
elif line["vendor"] not in "RaSCSI":
|
if device["vendor"] not in "RaSCSI":
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['file']} "
|
line += [device["vendor"], device["product"]]
|
||||||
f"{line['vendor']} {line['product']} {line['status']}")
|
output += [" ".join(line)]
|
||||||
else:
|
|
||||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['file']} "
|
|
||||||
f"{line['status']}")
|
|
||||||
else:
|
else:
|
||||||
output.append("No image mounted!")
|
output += ["No device attached!"]
|
||||||
|
|
||||||
if IP_ADDR:
|
if IP_ADDR:
|
||||||
output.append(f"IP {IP_ADDR} - {HOSTNAME}")
|
output += [f"IP {IP_ADDR} - {HOSTNAME}"]
|
||||||
else:
|
else:
|
||||||
output.append("RaSCSI has no IP address")
|
output += ["No IP address assigned", "Check network connection"]
|
||||||
output.append("Check network connection")
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def shutdown():
|
def shutdown():
|
||||||
|
@ -231,7 +223,7 @@ with GracefulInterruptHandler() as handler:
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
# The reference snapshot of attached devices that will be compared against each cycle
|
# The reference snapshot of attached devices that will be compared against each cycle
|
||||||
# to identify changes in RaSCSI backend
|
# to identify changes in the backend
|
||||||
ref_snapshot = formatted_output()
|
ref_snapshot = formatted_output()
|
||||||
# The snapshot updated each cycle that will compared with ref_snapshot
|
# The snapshot updated each cycle that will compared with ref_snapshot
|
||||||
snapshot = ref_snapshot
|
snapshot = ref_snapshot
|
||||||
|
|
Loading…
Reference in New Issue
Block a user