Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import re
  5. import sys
  6.  
  7. binarypath = "/usr/sbin/hpacucli"
  8.  
  9. if len(sys.argv) > 2:
  10. print 'Usage: hpacucli-status [-d]'
  11. sys.exit(1)
  12.  
  13. printarray = True
  14. if len(sys.argv) > 1:
  15. if sys.argv[1] == '-d':
  16. printarray = False
  17. else:
  18. print 'Usage: hpacucli-status [-d]'
  19. sys.exit(1)
  20.  
  21. # Check binary exists (and +x), if not print an error message
  22. if os.path.exists(binarypath) and os.access(binarypath, os.X_OK):
  23. pass
  24. else:
  25. sys.exit(3)
  26.  
  27. # Get command output
  28. def getOutput(cmd):
  29. output = os.popen(cmd)
  30. lines = []
  31. for line in output:
  32. if not re.match(r'^$',line.strip()):
  33. lines.append(line.strip())
  34. return lines
  35.  
  36. def returnDiskList(output):
  37. lines = []
  38.  
  39. enclid=''
  40. slotid=''
  41. diskstatus=''
  42. realid=['','']
  43.  
  44. # physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SATA, 160.0 GB, OK)
  45. for line in output:
  46. groups = re.match('.*?(box).*?(\d+).*?(bay).*?(\d+).*?((?:[a-z][a-z]+)).*?(\d+).*?(\d+).*?((?:[a-z][a-z]+)).*?((?:[a-z][a-z]+))', line, re.IGNORECASE)
  47. if groups:
  48. diskstatus = groups.group(9)
  49. enclid = groups.group(2)
  50. slotid = groups.group(4)
  51. size = groups.group(6)+"."+groups.group(7)+" "+groups.group(8)
  52. lines.append([enclid,slotid,size,diskstatus])
  53.  
  54. return lines
  55.  
  56. def returnArrayList(output):
  57. lines = []
  58.  
  59. id=''
  60. type=''
  61. size=''
  62. status=''
  63.  
  64. for line in output:
  65. groups = re.match('(logicaldrive).*?(\d+).*?([+-]?\d*\.\d+)(?![-+0-9\.]).*?((?:[a-z][a-z]+)).*?(RAID).*?(\d+).*?((?:[a-z][a-z]+))', line, re.IGNORECASE)
  66. if groups:
  67. id = groups.group(2)
  68. type = groups.group(5)+" "+groups.group(6)
  69. size = groups.group(3)+" "+groups.group(4)
  70. status = groups.group(7)
  71. lines.append([id,type,size,status])
  72.  
  73. return lines
  74.  
  75. cmd = binarypath+' ctrl all show config'
  76. output = getOutput(cmd)
  77. disklist = returnDiskList(output)
  78. arraylist = returnArrayList(output)
  79.  
  80. if printarray:
  81. print '-- Arrays informations --'
  82. print '-- ID | Type | Size | Status'
  83. for array in arraylist:
  84. print array[0]+' | '+array[2]+' '+array[3]+' | '+array[1]+' | '+array[-1]
  85. print ''
  86.  
  87. print '-- Disks informations'
  88. print '-- Enclosure | Slot | Size | Status'
  89. for disk in disklist:
  90. print disk[0]+' | '+disk[1]+' | '+disk[2]+' | '+disk[3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement