-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab414c5
commit 9564d60
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
import re | ||
from dataclasses import dataclass | ||
from typing import List | ||
|
||
from lisa.executable import Tool | ||
from lisa.util import find_patterns_in_lines | ||
|
||
|
||
@dataclass | ||
class PartitionInfo(Tool): | ||
name: str = "" | ||
size: int = 0 | ||
type: str = "" | ||
mountpoint: str = "" | ||
|
||
def __init__(self, name: str, size: int, type: str, mountpoint: str): | ||
self.name = name | ||
self.size = size | ||
self.type = type | ||
self.mountpoint = mountpoint | ||
|
||
|
||
class Lsblk(Tool): | ||
# NAME="loop2" SIZE="34017280" TYPE="loop" MOUNTPOINT="/snap/snapd/13640" | ||
_LSBLK_ENTRY_REGEX = re.compile( | ||
r'NAME="(?P<name>\S+)"\s+SIZE="(?P<size>\d+)"\s+' | ||
r'TYPE="(?P<type>\S+)"\s+MOUNTPOINT="(?P<mountpoint>\S+)"' | ||
) | ||
|
||
@property | ||
def command(self) -> str: | ||
return "lsblk" | ||
|
||
def get_partition_information(self) -> List[PartitionInfo]: | ||
# parse output of lsblk | ||
output = self.run("-b -P -o NAME,SIZE,TYPE,MOUNTPOINT", sudo=True).stdout | ||
partition_info = [] | ||
lsblk_entries = find_patterns_in_lines(output, [self._LSBLK_ENTRY_REGEX])[0] | ||
for lsblk_entry in lsblk_entries: | ||
partition_info.append( | ||
PartitionInfo( | ||
name=lsblk_entry[0], | ||
size=int(lsblk_entry[1]), | ||
type=lsblk_entry[2], | ||
mountpoint=lsblk_entry[3], | ||
) | ||
) | ||
return partition_info |