simplify mark_gateway

legacy
Nils Schneider 2014-09-21 22:18:31 +02:00
parent 878267ca0e
commit 6e101bc6de
3 changed files with 18 additions and 31 deletions

View File

@ -29,6 +29,7 @@ parser.add_argument('-a', '--aliases',
metavar='FILE')
parser.add_argument('-m', '--mesh', action='append',
default=["bat0"],
help='batman mesh interface')
parser.add_argument('-A', '--alfred', action='store_true',
@ -43,17 +44,11 @@ options = vars(args)
db = NodeDB(int(time.time()))
if options['mesh']:
for mesh_interface in options['mesh']:
bm = batman(mesh_interface)
db.parse_vis_data(bm.vis_data(options['alfred']))
for gw in bm.gateway_list():
db.mark_gateways(gw['mac'])
else:
bm = batman()
db.parse_vis_data(bm.vis_data(options['alfred']))
for gw in bm.gateway_list():
db.mark_gateways([gw['mac']])
db.mark_gateway(gw)
if options['aliases']:
for aliases in options['aliases']:

View File

@ -45,22 +45,20 @@ class batman:
"""
output = subprocess.check_output(["batctl","-m",self.mesh_interface,"gwl","-n"])
output_utf8 = output.decode("utf-8")
# TODO Parse information
lines = output_utf8.splitlines()
own_mac = re.match(r"^.*MainIF/MAC: [^/]+/([0-9a-f:]+).*$", lines[0]).group(1)
# Remove header line
del lines[0]
# Fill gateway list
gw = []
gw_mode = self.gateway_mode()
if gw_mode['mode'] == 'server':
gw.append({'mac': own_mac, 'bandwidth': gw_mode['bandwidth']})
gw.append(own_mac)
for line in lines:
gw_line = line.split()
if (gw_line[0] == 'No'):
continue
# When in client gateway mode maybe gw_line[0] is not the right.
gw.append({'mac':gw_line[0], 'bandwidth': gw_line[-1]})
gw_line = re.match(r"^(?:=>)? +([0-9a-f:]+) ", line)
if gw_line:
gw.append(gw_line.group(1))
return gw
def gateway_mode(self):

View File

@ -224,18 +224,12 @@ class NodeDB:
if 'id' in alias:
node.id = alias['id']
# list of macs
# if options['gateway']:
# mark_gateways(options['gateway'])
def mark_gateways(self, gateways):
for gateway in gateways:
def mark_gateway(self, gateway):
try:
node = self.maybe_node_by_mac((gateway, ))
except:
print("WARNING: did not find gateway '",gateway,"' in node list")
continue
node.flags['gateway'] = True
except KeyError:
print("WARNING: did not find gateway ", gateway, " in node list")
def update_vpn_links(self):
changes = 1