fix: probe correct value
This commit is contained in:
@@ -584,7 +584,7 @@ def validate_host_name(name: str) -> None:
|
||||
|
||||
|
||||
def probe_host(ip: str, user: str) -> ProbeFacts:
|
||||
lsblk_cmd = "lsblk -o NAME,SIZE,TYPE,MODEL,FSTYPE,PTTYPE,MOUNTPOINTS"
|
||||
lsblk_cmd = "lsblk -P -o NAME,SIZE,TYPE,MODEL,FSTYPE,PTTYPE,MOUNTPOINTS"
|
||||
boot_cmd = "test -d /sys/firmware/efi && echo UEFI || echo BIOS"
|
||||
root_cmd = "findmnt -no SOURCE /"
|
||||
swap_cmd = "cat /proc/swaps"
|
||||
@@ -635,28 +635,25 @@ def probe_host(ip: str, user: str) -> ProbeFacts:
|
||||
|
||||
|
||||
def parse_lsblk_output(output: str) -> list[dict[str, str]]:
|
||||
lines = [line.rstrip("\n") for line in output.splitlines() if line.strip()]
|
||||
if len(lines) < 2:
|
||||
lines = [line.strip() for line in output.splitlines() if line.strip()]
|
||||
if not lines:
|
||||
raise NodeiwestError("Unexpected lsblk output: not enough lines to parse.")
|
||||
|
||||
header = lines[0]
|
||||
columns = ["NAME", "SIZE", "TYPE", "MODEL", "FSTYPE", "PTTYPE", "MOUNTPOINTS"]
|
||||
starts = []
|
||||
for column in columns:
|
||||
index = header.find(column)
|
||||
if index == -1:
|
||||
raise NodeiwestError(f"Unexpected lsblk output: missing {column} column.")
|
||||
starts.append(index)
|
||||
starts.append(len(header) + 20)
|
||||
|
||||
rows: list[dict[str, str]] = []
|
||||
for line in lines[1:]:
|
||||
row: dict[str, str] = {}
|
||||
for idx, column in enumerate(columns):
|
||||
start = starts[idx]
|
||||
end = starts[idx + 1] if idx + 1 < len(columns) else len(line)
|
||||
row[column] = line[start:end].strip()
|
||||
row["NAME"] = re.sub(r"^[^0-9A-Za-z]+", "", row["NAME"])
|
||||
for line in lines:
|
||||
tokens = shlex.split(line)
|
||||
row = {}
|
||||
for token in tokens:
|
||||
if "=" not in token:
|
||||
continue
|
||||
key, value = token.split("=", 1)
|
||||
row[key] = value
|
||||
missing = [column for column in columns if column not in row]
|
||||
if missing:
|
||||
raise NodeiwestError(
|
||||
f"Unexpected lsblk output: missing columns {', '.join(missing)} in line {line!r}."
|
||||
)
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
|
||||
Reference in New Issue
Block a user