Hide keyboard shortcuts

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#!/usr/bin/python3 

2# 

3# Copyright (C) Citrix Systems Inc. 

4# 

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

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

7# by the Free Software Foundation; version 2.1 only. 

8# 

9# This program is distributed in the hope that it will be useful, 

10# but WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12# GNU Lesser General Public License for more details. 

13# 

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

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

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

17 

18import sys 

19import util 

20import re 

21import glob 

22 

23 

24def get_luninfo(scsi_id): 

25 luninfo = {} 

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

27 if (len(links)): 

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

29 luninfo['targetID'] = alist[0] 

30 luninfo['lunnum'] = alist[1] 

31 return luninfo 

32 

33 

34def query_pathdata(scsi_id, luninfo): 

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

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

37 pathlistcmd.append(cmd_option_str) 

38 return util.doexec(pathlistcmd) 

39 

40 

41def query_hbtl(scsi_id): 

42 luninfo = get_luninfo(scsi_id) 

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

44 if rc != 1: 

45 util.SMlog("Failed to query SCSIid") 

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

47 lines = stdout.split('\n') 

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

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

50 

51 

52def get_pathinfo(scsi_id, verbose=False): 

53 luninfo = get_luninfo(scsi_id) 

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

55 if verbose: 

56 print(stdout) 

57 return 

58 lines = stdout.split('\n') 

59 for line in lines: 

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

61 mt = regex.search(line) 

62 if (mt): 

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

64 continue 

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

66 mu = regex.search(line) 

67 if (mu): 

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

69 continue 

70 

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

72 

73 

74def usage(): 

75 print("Usage:") 

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

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

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

79 

80 

81def main(): 

82 if len(sys.argv) < 3: 

83 usage() 

84 sys.exit(-1) 

85 

86 mode = sys.argv[1] 

87 scsi_id = sys.argv[2] 

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

89 if not (len(testlinks)): 

90 return 

91 if mode == "luninfo": 

92 luninfo = get_luninfo(scsi_id) 

93 if luninfo: 

94 print(luninfo['lunnum']) 

95 else: 

96 if mode == "pathinfo": 

97 if len(sys.argv) < 4: 

98 usage() 

99 sys.exit(-1) 

100 submode = sys.argv[3] 

101 if (submode == "Counts"): 

102 (total_count, active_count) = get_pathinfo(scsi_id) 

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

104 elif (submode == "HBTL"): 

105 print(query_hbtl(scsi_id)) 

106 elif (submode == "Status"): 

107 get_pathinfo(scsi_id, verbose=True) 

108 else: 

109 usage() 

110 sys.exit(-1) 

111 

112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true

113 main()