yanger: usb: Refactor to only check authorized_default if locked/unlocked

authorized is unreliable on boot.
This commit is contained in:
Mattias Walström
2024-02-23 14:01:23 +01:00
parent ddd0fc5a35
commit acc39b1b15
+12 -11
View File
@@ -167,17 +167,18 @@ def get_usb_ports(usb_ports):
continue
path = usb_port["path"]
if os.path.exists(path):
names.append(usb_port["name"])
with open(path, "r") as f:
data=int(f.readline().strip())
enabled="unlocked" if data == 1 else "locked"
port["state"] = {}
port["state"]["admin-state"] = enabled
port["name"] = usb_port["name"]
port["class"] = "infix-hardware:usb"
port["state"]["oper-state"] = "enabled"
ports.append(port)
if os.path.basename(path) == "authorized_default":
if os.path.exists(path):
with open(path, "r") as f:
names.append(usb_port["name"])
data=int(f.readline().strip())
enabled="unlocked" if data == 1 else "locked"
port["state"] = {}
port["state"]["admin-state"] = enabled
port["name"] = usb_port["name"]
port["class"] = "infix-hardware:usb"
port["state"]["oper-state"] = "enabled"
ports.append(port)
return ports