-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
42 lines (35 loc) · 1.22 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
This module contains various utility functions
"""
import re
def csi_node_id_to_sp_node_id(csi_node_id: str) -> int:
"""
Converts CSI node_id to a StorPool node id
:param csi_node_id: CSI node_id as reported by the NodeService
:type csi_node_id: str
:return: StorPool Node id, value used in SP_OURID
:rtype: int
"""
return int(csi_node_id.split(".").pop())
def csi_node_id_to_sp_cluster_id(csi_node_id: str) -> str:
return re.match(r"^[a-z0-9]+\.[a-z0-9]+", csi_node_id).group(0)
def get_mounted_devices() -> list[dict]:
"""
Returns all mounts currently present on the node
:return: A list containing dictionaries with information about a mount
:rtype: list
"""
result = []
with open("/proc/mounts") as file:
mounts = [mount.strip("\n") for mount in file.readlines()]
for mount in mounts:
attributes = mount.split(" ")
result.append(
{
"device": attributes[0],
"target": attributes[1],
"filesystem": attributes[2],
"options": attributes[3],
}
)
return result