Coverage for sm/core/mpath_cli : 0%

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
"""Fake mpath cli module"""
import re from . import util from . import f_exceptions
mpathcmd = ["multipathd","-k"]
def mpexec(cmd): util.SMlog("mpath cmd: %s" % cmd) (rc,stdout,stderr) = util.doexec(mpathcmd,cmd) if stdout != "multipathd> ok\nmultipathd> " \ and stdout != "multipathd> "+cmd+"\nok\nmultipathd> ": msg = 'rc: %d, stdout: %s, stderr: %s' % (ret, stdout, stderr) raise f_exceptions.XenError('MPCliFailure', msg)
def add_path(path): mpexec("add path %s" % path)
def remove_path(path): mpexec("remove path %s" % path)
def remove_map(m): mpexec("remove map %s" % m)
def resize_map(m): mpexec("resize map %s" % m)
def reconfigure(): mpexec("reconfigure")
regex = re.compile("[0-9]+:[0-9]+:[0-9]+:[0-9]+\s*([a-z]*)") regex2 = re.compile("multipathd>(\s*[^:]*:)?\s+(.*)") regex3 = re.compile("switchgroup")
def do_get_topology(cmd): util.SMlog("mpath cmd: %s" % cmd) (rc,stdout,stderr) = util.doexec(mpathcmd,cmd) util.SMlog("mpath output: %s" % stdout) lines = stdout.split('\n')[:-1] if len(lines): m=regex2.search(lines[0]) lines[0]=str(m.group(2)) return lines
def get_topology(scsi_id): cmd="show map %s topology" % scsi_id return do_get_topology(cmd)
def list_paths(scsi_id): lines = get_topology(scsi_id) matches = [] for line in lines: m=regex.search(line) if(m): matches.append(m.group(1)) return matches |