Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
e1579453
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e1579453
编写于
12月 08, 2016
作者:
A
Amador Pahim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'narasimhan-v-multipath_v4'
上级
4e4c39ec
aef4039d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
154 addition
and
0 deletion
+154
-0
avocado/utils/multipath.py
avocado/utils/multipath.py
+154
-0
未找到文件。
avocado/utils/multipath.py
0 → 100755
浏览文件 @
e1579453
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2016 IBM
# Author: Narasimhan V <sim@linux.vnet.ibm.com>
"""
Module with multipath related utility functions.
It needs root access.
"""
import
time
import
logging
from
.
import
distro
from
.
import
process
from
.
import
service
def
get_svc_name
():
"""
Gets the multipath service name based on distro.
"""
if
distro
.
detect
().
name
==
'Ubuntu'
:
return
"multipath-tools"
else
:
return
"multipathd"
def
form_conf_mpath_file
(
blacklist
=
""
,
defaults_extra
=
""
):
"""
Form a multipath configuration file, and restart multipath service.
:parm blacklist: Entry in conf file to indicate blacklist section.
:parm defaults_extra: Extra entry in conf file in defaults section.
"""
conf_file
=
"/etc/multipath.conf"
with
open
(
conf_file
,
"w"
)
as
mpath_fp
:
mpath_fp
.
write
(
"defaults {
\n
"
)
mpath_fp
.
write
(
" find_multipaths yes
\n
"
)
mpath_fp
.
write
(
" user_friendly_names yes
\n
"
)
if
defaults_extra
:
mpath_fp
.
write
(
" %s
\n
"
%
defaults_extra
)
mpath_fp
.
write
(
"}
\n
"
)
if
blacklist
:
mpath_fp
.
write
(
"blacklist {
\n
"
)
mpath_fp
.
write
(
" %s
\n
"
%
blacklist
)
mpath_fp
.
write
(
"}
\n
"
)
logging
.
debug
(
open
(
conf_file
,
"r"
).
read
())
# The reason for sleep here is to give some time for change in
# multipath.conf file to take effect.
time
.
sleep
(
5
)
service
.
SpecificServiceManager
(
get_svc_name
()).
restart
()
def
device_exists
(
path
):
"""
Checks if a given path exists.
:return: True if path exists, False if does not exist.
"""
cmd
=
"multipath -l %s"
%
path
if
process
.
system
(
cmd
,
ignore_status
=
True
,
sudo
=
True
)
!=
0
:
return
False
return
True
def
get_mpath_name
(
wwid
):
"""
Get multipath name for a given wwid.
:parm wwid: wwid of multipath device.
:return: Name of multipath device.
"""
if
device_exists
(
wwid
):
cmd
=
"multipath -l %s"
%
wwid
return
process
.
system_output
(
cmd
,
sudo
=
True
).
split
()[
0
]
def
get_multipath_wwids
():
"""
Get list of multipath wwids.
:return: List of multipath wwids.
"""
cmd
=
"egrep -v '^($|#)' /etc/multipath/wwids"
wwids
=
process
.
system_output
(
cmd
,
ignore_status
=
True
,
sudo
=
True
)
wwids
=
wwids
.
strip
(
"
\n
"
).
replace
(
"/"
,
""
).
split
(
"
\n
"
)
return
wwids
def
get_paths
(
wwid
):
"""
Get list of paths, given a multipath wwid.
:return: List of paths.
"""
if
not
device_exists
(
wwid
):
return
cmd
=
"multipath -ll %s"
%
wwid
lines
=
process
.
system_output
(
cmd
,
sudo
=
True
).
strip
(
"
\n
"
)
paths
=
[]
for
line
in
lines
.
split
(
"
\n
"
):
if
not
((
'size'
in
line
)
or
(
'policy'
in
line
)
or
(
wwid
in
line
)):
paths
.
append
(
line
.
split
()[
-
5
])
return
paths
def
get_policy
(
wwid
):
"""
Gets path_checker policy, given a multipath wwid.
:return: path checker policy.
"""
if
device_exists
(
wwid
):
cmd
=
"multipath -ll %s"
%
wwid
lines
=
process
.
system_output
(
cmd
,
sudo
=
True
).
strip
(
"
\n
"
)
for
line
in
lines
.
split
(
"
\n
"
):
if
'policy'
in
line
:
return
line
.
split
(
"'"
)[
1
].
split
()[
0
]
def
get_size
(
wwid
):
"""
Gets size of device, given a multipath wwid.
:return: size of multipath device.
"""
if
device_exists
(
wwid
):
cmd
=
"multipath -ll %s"
%
wwid
lines
=
process
.
system_output
(
cmd
,
sudo
=
True
).
strip
(
"
\n
"
)
for
line
in
lines
.
split
(
"
\n
"
):
if
'size'
in
line
:
return
line
.
split
(
"="
)[
1
].
split
()[
0
]
def
flush_path
(
path_name
):
"""
Flushes the given multipath.
:return: Returns False if command fails, True otherwise.
"""
cmd
=
"multipath -f %s"
%
path_name
if
process
.
system
(
cmd
,
ignore_status
=
True
,
sudo
=
True
)
!=
0
:
return
False
return
True
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录