in selftest/selftest.py [0:0]
def parse_azure_nvme_id_json_output(output: str) -> Dict[str, AzureNvmeIdDevice]:
"""Parse azure-nvme-id --format json output.
Example output:
[
{
"path": "/dev/nvme0n33",
"model": "MSFT NVMe Accelerator v1.0",
"properties": {
"type": "data",
"lun": 31
},
"vs": ""
},
{
"path": "/dev/nvme1n1",
"model": "Microsoft NVMe Direct Disk v2",
"properties": {
"type": "local",
"index": 1,
"name": "nvme-440G-1"
},
"vs": "type=local,index=1,name=nvme-440G-1"
}
]
"""
devices = {}
for device in json.loads(output):
device_path = device["path"]
model = device["model"]
properties = device["properties"]
device_type = properties.pop("type", None)
device_index = (
int(properties.pop("index")) if "index" in properties else None
)
device_lun = int(properties.pop("lun")) if "lun" in properties else None
device_name = properties.pop("name", None)
azure_nvme_id_device = AzureNvmeIdDevice(
device=device_path,
model=model,
nvme_id=",".join([f"{k}={v}" for k, v in properties.items()]),
type=device_type,
index=device_index,
lun=device_lun,
name=device_name,
extra=properties,
)
key = device_path.split("/")[-1]
devices[key] = azure_nvme_id_device
return devices