提交 3a5cc6f5 编写于 作者: N Narasimhan V

Added the following functions to multipath library:

* get_multipath_details
* is_path_a_multipath
* get_path_status
Signed-off-by: NNarasimhan V <sim@linux.vnet.ibm.com>
上级 63004ef5
......@@ -19,6 +19,7 @@ It needs root access.
import time
import logging
import ast
from . import distro
from . import process
from . import service
......@@ -114,6 +115,52 @@ def get_paths(wwid):
return paths
def get_multipath_details():
"""
Get multipath details as a dictionary, as given by the command:
multipathd show maps json
:return: Dictionary of multipath output in json format.
"""
mpath_op = process.system_output("multipathd show maps jsons", sudo=True)
if 'multipath-tools v' in mpath_op:
return ''
mpath_op = ast.literal_eval(mpath_op.replace("\n", '').replace(' ', ''))
return mpath_op
def is_path_a_multipath(disk_path):
"""
Check if given disk path is part of a multipath.
:param disk_path: disk path. Example: sda, sdb.
:return: True if part of multipath, else False.
"""
if not process.system("multipath -c /dev/%s" % disk_path, sudo=True,
ignore_status=True):
return True
return False
def get_path_status(disk_path):
"""
Return the status of a path in multipath.
:param disk_path: disk path. Example: sda, sdb.
:return: Tuple in the format of (dm status, dev status, checker status)
"""
mpath_op = get_multipath_details()
if not mpath_op:
return ('', '', '')
for maps in mpath_op['maps']:
for path_groups in maps['path_groups']:
for paths in path_groups['paths']:
if paths['dev'] == disk_path:
return(paths['dm_st'], paths['dev_st'], paths['chk_st'])
def get_policy(wwid):
"""
Gets path_checker policy, given a multipath wwid.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册