Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- ################################
- #
- # Name: test.py
- #
- # Description:
- #
- # Version: 1.0
- #
- # Date User Changes
- # ====== ========= =======
- #
- ################################
- """
- test.py
- Usage: python test.py [options]
- Options:
- -h, --help Show this help
- -f, --file Name of file containing list of MMs or AMMs. ONE per line
- Examples:
- test.py -h (shows this help information)
- test.py -f mm.txt (full path to file contain the list of AMMs to be looked at)
- """
- # Modules to import
- #====================#
- import os
- import sys
- import getopt
- import telnetlib
- import string
- import re
- import socket
- ######################
- # Try and open the file supplied on the command line.
- def checkInputfile( filename ):
- try:
- f = open('%s' % filename, 'r')
- except IOError:
- print "Error: can\'t find file %s or read data" % filename
- else:
- processInfo()
- f.close()
- # Print out how you use the script
- def usage():
- print __doc__
- # Process the information gathered from the MM
- def processInfo():
- try:
- dclayout = open('layout.txt', 'a')
- except IOError:
- print "Unable to create the output file."
- else:
- for i, line in enumerate(open("mminfo.txt", 'r'), 1):
- # for line in open("mminfo.txt", 'r'):
- # Find the name assigned to the AMM and substitute any '_' for '.'.
- if re.search("^Hostname:", line):
- hostfull = line.strip()
- host = string.replace(hostfull, '_', '.')
- hos = host[28:]
- print "\n"
- dclayout.write("\n")
- print "\t %s" % hos
- dclayout.write("\t %s\n" % hos)
- # Find the IP of the AMM.
- if re.search("Static IP", line):
- IP = line[23:].strip()
- #IP = ip[23:]
- print "\t %s" % IP
- dclayout.write("\t %s\n" % IP)
- # Find the number of the slot.
- if re.search("system> info", line):
- slot = line.strip()
- #num = line[22:len(line) -1].strip()
- num = slot[22:len(slot) -1]
- # Find the name of the host in a slot and the IP of the host.
- ################
- # TO DO - Use domain part from Hostname above and add as part of dnsname below
- ################
- if re.search("^Name:", line):
- nmixed = line.strip()
- n = nmixed.lower()
- name = n[5:]
- dnsname = name + ".ZONE21.WORK"
- host = dnsname.strip()
- print "%s\t%s" % (num, name)
- dclayout.write("%s\t%s\n" % (num, name))
- ###############
- # Commented as names in internal DNS - DOES WORK
- ###############
- # try:
- # hip = socket.gethostbyname('%s' % host)
- # print "\t %s" % hip
- # dclayout.write("\t %s\n" % hip)
- # #return hip
- # except socket.gaierror:
- # print "\t "
- # dclayout.write("\t \n")
- # Find the serial number of the blade.
- if re.search("Mach serial number:", line):
- serial = line[20:].strip()
- if serial != 'Not Available':
- print "\t %s" % serial
- dclayout.write("\t %s\n" % serial)
- # Find the MAC address of the first MAC.
- if re.search("MAC Address 1:", line):
- mac = line[15:].strip()
- print "\t %s" % mac
- dclayout.close()
- def main(argv):
- try:
- opts, args = getopt.getopt(argv, "hf:", ["help=", "file="])
- except getopt.GetoptError:
- usage()
- sys.exit(2)
- for opt, arg in opts:
- if opt in ("-h", "--help"):
- usage()
- sys.exit()
- elif opt in ("-f", "--file"):
- filename = arg
- checkInputfile( filename )
- #===========================================================
- # Main loop
- #===========================================================
- if __name__ == "__main__":
- if len(sys.argv) < 2:
- usage()
- else:
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment