00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import roslib; roslib.load_manifest('qualification')
00036
00037 import sys, getpass
00038
00039 from wg_invent_client import Invent
00040
00041 from optparse import OptionParser
00042 import subprocess
00043
00044 class GetIDException(Exception): pass
00045
00046 def print_usage():
00047 print 'Loads mac address into Invent for a given basestation'
00048 print
00049 print 'load_basestation_mac_addr.py 10XX USERNAME'
00050 print 'Asks for password'
00051
00052 return
00053
00054 def get_iface_mac(iface):
00055 p = subprocess.Popen(['ifconfig', iface], stdout=subprocess.PIPE,
00056 stderr=subprocess.PIPE)
00057
00058 (o, e) = p.communicate()
00059 if p.returncode != 0:
00060 raise GetIDException("Unable to recover %s mac address" % iface)
00061
00062 lines = o.split('\n')
00063 first = lines[0]
00064
00065 words = first.split()
00066 if len(words) < 5 or not words[3].strip() == 'HWaddr':
00067 raise GetIDException("Unable to parse mac address output: %s. Got: %s. Length: %d" % (first, words[3], len(words)))
00068 mac = words[4].replace(':', '').lower()
00069
00070 if not len(mac) == 12:
00071 raise GetIDException("Unable to parse mac address output: %s. Recovered: %s" % (first, mac))
00072
00073 return mac
00074
00075 if __name__ == '__main__':
00076 if len(sys.argv) != 3:
00077 print_usage()
00078 sys.exit(1)
00079
00080 sn = '68037600' + sys.argv[1]
00081 user = sys.argv[2]
00082
00083 print "Enter Invent password"
00084 passwd = getpass.getpass()
00085
00086 iv = Invent(user, passwd)
00087
00088 if not iv.login():
00089 print >> sys.stderr, "Unable to login to Invent. Try again."
00090 sys.exit(1)
00091
00092 if not iv.check_serial_valid(sn):
00093 print >> sys.stderr, "Serial %s is invalid. Robot must be entered in as '10XX'" % sn
00094 sys.exit(1)
00095
00096 for iface in ('wan0', 'lan0'):
00097 addr = get_iface_mac(iface)
00098 if not iv.addItemReference(sn, iface, addr):
00099 raise Exception("Unable to load address %s to iface %s" % (addr, iface))
00100
00101 print 'Loaded mac address for %s' % sn