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

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

#!/usr/bin/env python 

# 

# Copyright (C) Citrix Systems Inc. 

# 

# This program is free software; you can redistribute it and/or modify  

# it under the terms of the GNU Lesser General Public License as published  

# by the Free Software Foundation; version 2.1 only. 

# 

# 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 the  

# GNU Lesser General Public License for more details. 

# 

# You should have received a copy of the GNU Lesser General Public License 

# along with this program; if not, write to the Free Software Foundation, Inc., 

# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 

 

import sys 

import os 

import util 

import re 

import glob 

 

def get_luninfo(scsi_id): 

    luninfo = {} 

    links=glob.glob('/dev/disk/mpInuse/%s-*' % scsi_id) 

    if (len(links)): 

        alist = links[0].split('/')[-1].split('-')[-1].split(':') 

        luninfo['targetID'] = alist[0] 

        luninfo['lunnum'] = alist[1] 

    return luninfo 

 

def query_pathdata(scsi_id, luninfo): 

    pathlistcmd = ["/usr/sbin/mppUtil", "-P"] 

    cmd_option_str = luninfo['targetID'] + "," + luninfo['lunnum'] 

    pathlistcmd.append(cmd_option_str) 

    return util.doexec(pathlistcmd) 

 

def query_hbtl(scsi_id): 

    luninfo = get_luninfo(scsi_id) 

    (rc,stdout,stderr) = query_pathdata(scsi_id, luninfo) 

    if rc != 1: 

        util.SMlog("Failed to query SCSIid") 

        return "-1:-1:-1:-1" 

    lines = stdout.split('\n') 

    id = re.sub("[H,C,T]"," ",lines[0].split()[0]).split() 

    return "%s:%s:%s:%s" % (id[0],id[1],id[2],luninfo['lunnum']) 

 

def get_pathinfo(scsi_id, verbose = False): 

    luninfo = get_luninfo(scsi_id) 

    (rc,stdout,stderr) = query_pathdata(scsi_id, luninfo) 

    if verbose: 

        print stdout 

        return 

    lines = stdout.split('\n') 

    for line in lines: 

            regex = re.compile("TOTAL PATHS:") 

            mt = regex.search(line) 

            if (mt): 

                total_count = line.split(':')[1].strip() 

                continue 

            regex = re.compile("PATHS UP:") 

            mu = regex.search(line) 

            if (mu): 

                active_count = line.split(':')[1].strip() 

                continue 

 

    return (int(total_count), int(active_count)) 

 

def usage(): 

    print "Usage:"; 

    print "%s pathinfo <scsi_id> Counts" % sys.argv[0] 

    print "%s pathinfo <scsi_id> Status" % sys.argv[0] 

    print "%s luninfo <scsi_id>" % sys.argv[0] 

 

 

def main(): 

    if len(sys.argv) < 3: 

        usage() 

        sys.exit(-1) 

 

    mode=sys.argv[1] 

    scsi_id = sys.argv[2] 

    testlinks=glob.glob('/dev/disk/mpInuse/%s-*' % scsi_id) 

    if not (len(testlinks)): 

        return 

    if mode == "luninfo": 

        luninfo =  get_luninfo(scsi_id) 

        if luninfo: 

            print luninfo['lunnum'] 

    else: 

        if mode == "pathinfo": 

            if len(sys.argv) < 4: 

                usage() 

                sys.exit(-1) 

            submode = sys.argv[3] 

            if (submode == "Counts"): 

                (total_count, active_count) = get_pathinfo(scsi_id) 

                print "Total: %s, Active: %s" % (total_count, active_count) 

            elif (submode == "HBTL"): 

                print query_hbtl(scsi_id) 

            elif (submode == "Status"): 

                get_pathinfo(scsi_id, verbose=True) 

            else: 

                usage() 

                sys.exit(-1) 

 

if __name__ == "__main__": 

    main()