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

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

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

"""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