load_basestation_mac_addr.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2010, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
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


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34