Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if i != 1:
# remove vlan from the port
run(nl.vlan_filter, 'del',
index=self['index'],
vlan_info=self['vlans'][i])
for i in added['vlans']:
if i != 1:
# add vlan to the port
run(nl.vlan_filter, 'add',
index=self['index'],
vlan_info=transaction['vlans'][i])
self['vlans'].target.wait(SYNC_TIMEOUT)
if not self['vlans'].target.is_set():
raise CommitException('vlans target is not set')
# 8<---------------------------------------------
# Ports
if removed['ports'] or added['ports']:
self['ports'].set_target(transaction['ports'])
for i in removed['ports']:
# detach port
if i in self.ipdb.interfaces:
(self.ipdb.interfaces[i]
.set_target('master', None)
.mirror_target('master', 'link'))
run(nl.link, 'set', index=i, master=0)
else:
transaction.errors.append(KeyError(i))
def wait_all_targets(self):
for key, target in self._targets.items():
if key not in self._virtual_fields:
target.wait(SYNC_TIMEOUT)
if not target.is_set():
raise CommitException('target %s is not set' % key)
for i in list(added['ports']) + list(removed['ports']):
port = self.ipdb.interfaces[i]
# port update
target = port._local_targets['master']
target.wait(SYNC_TIMEOUT)
with port._write_lock:
del port._local_targets['master']
del port._local_targets['link']
if not target.is_set():
raise CommitException('master target failed')
if i in added['ports']:
if port.if_master != self['index']:
raise CommitException('master set failed')
else:
if port.if_master == self['index']:
raise CommitException('master unset failed')
# master update
if self['kind'] == 'bridge' and self['mtu'] > port['mtu']:
self.set_target('mtu', port['mtu'])
self.wait_target('mtu')
# 8<---------------------------------------------
# Interface changes
request = {}
brequest = {}
prequest = {}
# preseed requests with the interface kind
request['kind'] = self['kind']
brequest['kind'] = self['kind']
wait_all = False
for key in added:
if (key not in self._virtual_fields) and (key != 'kind'):
# 2. wait for mtu sync
#
# the bridge mtu is set from the port, if the latter is smaller
# the bond mtu sets the port mtu, if the latter is smaller
#
# FIXME: team interfaces?
for i in list(added['ports']) + list(removed['ports']):
port = self.ipdb.interfaces[i]
# port update
target = port._local_targets['master']
target.wait(SYNC_TIMEOUT)
with port._write_lock:
del port._local_targets['master']
del port._local_targets['link']
if not target.is_set():
raise CommitException('master target failed')
if i in added['ports']:
if port.if_master != self['index']:
raise CommitException('master set failed')
else:
if port.if_master == self['index']:
raise CommitException('master unset failed')
# master update
if self['kind'] == 'bridge' and self['mtu'] > port['mtu']:
self.set_target('mtu', port['mtu'])
self.wait_target('mtu')
# 8<---------------------------------------------
# Interface changes
request = {}
brequest = {}
prequest = {}
transaction.errors.append(KeyError(i))
self['ports'].target.wait(SYNC_TIMEOUT)
if not self['ports'].target.is_set():
raise CommitException('ports target is not set')
# wait for proper targets on ports
for i in list(added['ports']) + list(removed['ports']):
port = self.ipdb.interfaces[i]
target = port._local_targets['master']
target.wait(SYNC_TIMEOUT)
with port._write_lock:
del port._local_targets['master']
del port._local_targets['link']
if not target.is_set():
raise CommitException('master target failed')
if i in added['ports']:
if port.if_master != self['index']:
raise CommitException('master set failed')
else:
if port.if_master == self['index']:
raise CommitException('master unset failed')
# 8<---------------------------------------------
# Interface changes
request = {}
brequest = {}
prequest = {}
# preseed requests with the interface kind
request['kind'] = self['kind']
brequest['kind'] = self['kind']
wait_all = False
# wait for proper targets on ports
for i in list(added['ports']) + list(removed['ports']):
port = self.ipdb.interfaces[i]
target = port._local_targets['master']
target.wait(SYNC_TIMEOUT)
with port._write_lock:
del port._local_targets['master']
del port._local_targets['link']
if not target.is_set():
raise CommitException('master target failed')
if i in added['ports']:
if port.if_master != self['index']:
raise CommitException('master set failed')
else:
if port.if_master == self['index']:
raise CommitException('master unset failed')
# 8<---------------------------------------------
# Interface changes
request = {}
brequest = {}
prequest = {}
# preseed requests with the interface kind
request['kind'] = self['kind']
brequest['kind'] = self['kind']
wait_all = False
for key in added:
if (key not in self._virtual_fields) and (key != 'kind'):
if key[:3] == 'br_':
brequest[key] = added[key]
elif key[:7] == 'brport_':
prequest[key[7:]] = added[key]
for i in added['ports']:
# attach port
if i in self.ipdb.interfaces:
(self.ipdb.interfaces[i]
.set_target('master', self['index'])
.mirror_target('master', 'link'))
run(nl.link, 'update', index=i, master=self['index'])
else:
transaction.errors.append(KeyError(i))
self['ports'].target.wait(SYNC_TIMEOUT)
if self['ports'].target.is_set():
for msg in self.nl.get_vlans(index=self['index']):
self.load_netlink(msg)
else:
raise CommitException('ports target is not set')
# 1. wait for proper targets on ports
# 2. wait for mtu sync
#
# the bridge mtu is set from the port, if the latter is smaller
# the bond mtu sets the port mtu, if the latter is smaller
#
# FIXME: team interfaces?
for i in list(added['ports']) + list(removed['ports']):
port = self.ipdb.interfaces[i]
# port update
target = port._local_targets['master']
target.wait(SYNC_TIMEOUT)
with port._write_lock:
del port._local_targets['master']
del port._local_targets['link']
# add vlan to the port
vinfo = transaction['vlans'][i][0]
flags = transaction['vlans'][i][1]
req = {'index': self['index'],
'vlan_info': vinfo}
if flags == 'self':
req['vlan_flags'] = flags
# this request will NOT give echo,
# so bypass the check
with self._direct_state:
self.add_vlan(vinfo['vid'])
run(nl.vlan_filter, 'add', **req)
self['vlans'].target.wait(SYNC_TIMEOUT)
if not self['vlans'].target.is_set():
raise CommitException('vlans target is not set')
# 8<---------------------------------------------
# Ports
if removed['ports'] or added['ports']:
self['ports'].set_target(transaction['ports'])
for i in removed['ports']:
# detach port
if i in self.ipdb.interfaces:
(self.ipdb.interfaces[i]
.set_target('master', None)
.mirror_target('master', 'link'))
run(nl.link, 'update', index=i, master=0)
else:
transaction.errors.append(KeyError(i))