Commit 4e2b6531 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

Merge branch 'eiger_flash' into 'master'

parents 67ad5002 a40a6d78
......@@ -8,6 +8,7 @@ import re
import time
import errno
import socket
import functools
from getopt import getopt
from telnetlib import Telnet
......@@ -24,6 +25,31 @@ def get_eiger_executables_dir():
def get_domain_name():
return socket.getfqdn().strip(socket.gethostname())
get_inet_ip = functools.partial(socket.inet_pton, socket.AF_INET)
def get_route_table():
route = Popen(['/sbin/route', '-n'], stdout=PIPE)
ip_re_str = '\\.'.join(['[0-9]{1,3}'] * 4)
route_ip_group = ['dest', 'gw', 'mask']
route_str_group = ['flags', 'metric', 'ref', 'use', 'iface']
route_re_list = [('(?P<%s>{0})' % k) for k in route_ip_group]
route_re_list += [('(?P<%s>{1})' % k) for k in route_str_group]
route_re_format = '{2}'.join(route_re_list)
route_re_str = route_re_format.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 m:
d = dict([(k, for k in route_str_group])
d.update([(k, get_inet_ip( for k in route_ip_group])
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 +64,25 @@ class Connection(object):
class DirectEthernetConnection(Connection):
def __init__(self, name):
super(DirectEthernetConnection, self).__init__(name)
ip = get_inet_ip(self.addr)
default_gw = lambda d: d['dest'] == get_inet_ip('')
good_subnet = lambda d: get_masked_ip(ip, d['mask']) == d['dest']
ifaces = [d['iface'] for d in get_route_table()
if not default_gw(d) and good_subnet(d)]
if not ifaces:
raise RuntimeError('Cannot find direct link to %s' % name)
self.iface = ifaces[0]
def restart(self):
print '[%s] Disabling %s ...' % (, self.iface)
os.system('sudo ifconfig %s down' % self.iface)
print '[%s] Enabling %s ...' % (, self.iface)
os.system('sudo ifconfig %s up' % self.iface)
class ExtremeSwitchConnection(Connection):
......@@ -419,9 +463,12 @@ class Eiger:
(['beb074', 'beb071', 'beb064', 'beb102',
'beb072', 'beb073', 'beb087', 'beb088'],
(['beb021', 'beb020'],
(['beb024', 'beb025'],
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