Coverage for sm/core/mpath_cli.py : 31%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Fake mpath cli module"""
3import re
4from . import util
5from . import f_exceptions
7mpathcmd = ["multipathd","-k"]
9def mpexec(cmd):
10 util.SMlog("mpath cmd: %s" % cmd)
11 (rc,stdout,stderr) = util.doexec(mpathcmd,cmd)
12 if stdout != "multipathd> ok\nmultipathd> " \
13 and stdout != "multipathd> "+cmd+"\nok\nmultipathd> ":
14 msg = 'rc: %d, stdout: %s, stderr: %s' % (ret, stdout, stderr)
15 raise f_exceptions.XenError('MPCliFailure', msg)
17def add_path(path):
18 mpexec("add path %s" % path)
20def remove_path(path):
21 mpexec("remove path %s" % path)
23def remove_map(m):
24 mpexec("remove map %s" % m)
26def resize_map(m):
27 mpexec("resize map %s" % m)
29def reconfigure():
30 mpexec("reconfigure")
32regex = re.compile("[0-9]+:[0-9]+:[0-9]+:[0-9]+\s*([a-z]*)")
33regex2 = re.compile("multipathd>(\s*[^:]*:)?\s+(.*)")
34regex3 = re.compile("switchgroup")
36def do_get_topology(cmd):
37 util.SMlog("mpath cmd: %s" % cmd)
38 (rc,stdout,stderr) = util.doexec(mpathcmd,cmd)
39 util.SMlog("mpath output: %s" % stdout)
40 lines = stdout.split('\n')[:-1]
41 if len(lines):
42 m=regex2.search(lines[0])
43 lines[0]=str(m.group(2))
44 return lines
46def get_topology(scsi_id):
47 cmd="show map %s topology" % scsi_id
48 return do_get_topology(cmd)
50def list_paths(scsi_id):
51 lines = get_topology(scsi_id)
52 matches = []
53 for line in lines:
54 m=regex.search(line)
55 if(m):
56 matches.append(m.group(1))
57 return matches