Commit 33b03a5a authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

eiger_flash: add DirectEthernetConnection restart support (needs sudo ifconfig)

parent 67ad5002
......@@ -24,6 +24,27 @@ def get_eiger_executables_dir():
def get_domain_name():
return socket.getfqdn().strip(socket.gethostname())
def get_route_table():
route = Popen(['/sbin/route', '-n'], stdout=PIPE)
ip_re_str = '([0-9]{1,3}\\.){3}[0-9]{1,3}'
route_re_str = ('(?P<dest>{0}){1}(?P<gw>{0}){1}(?P<mask>{0}){1}'
'(?P<flags_metric_ref_use>({2}{1}){{4}})'
'(?P<iface>{2})').format(ip_re_str, '[ \t]+', '[^ \t]+')
route_re = re.compile(route_re_str)
route_table = {}
for l in route.stdout.readlines():
m = route_re.match(l.strip())
if not m:
continue
d = [(k, socket.inet_pton(socket.AF_INET, m.group(k)))
for k in ['dest', 'gw', 'mask']]
route_table[m.group('iface')] = dict(d)
return route_table
def get_masked_ip(addr, mask):
masked_ip = map(lambda x, y: '%c' % (ord(x) & ord(y)), addr, mask)
return ''.join(masked_ip)
class Connection(object):
......@@ -38,7 +59,26 @@ class Connection(object):
class DirectEthernetConnection(Connection):
pass
def __init__(self, name):
super(DirectEthernetConnection, self).__init__(name)
ip = socket.inet_pton(socket.AF_INET, self.addr)
null = '\x00' * 4
for iface, d in get_route_table().items():
if d['dest'] != null and get_masked_ip(ip, d['mask']) == d['dest']:
self.iface = iface
break
else:
raise RuntimeError('%s is not directly connected' % name)
def restart(self):
print '[%s] Disabling %s ...' % (self.name, self.iface)
os.system('sudo ifconfig %s down' % self.iface)
gevent.sleep(4)
print '[%s] Enabling %s ...' % (self.name, self.iface)
os.system('sudo ifconfig %s up' % self.iface)
class ExtremeSwitchConnection(Connection):
......@@ -419,9 +459,12 @@ class Eiger:
(['beb074', 'beb071', 'beb064', 'beb102',
'beb072', 'beb073', 'beb087', 'beb088'],
ExtremeSwitchConnection)),
('Eiger-500k',
('Eiger-500k-ISG',
(['beb021', 'beb020'],
DirectEthernetConnection)),
('Eiger-500k-ID02',
(['beb024', 'beb025'],
DirectEthernetConnection)),
])
def __init__(self, host_list):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment