How to use the pyroute2.ipdb.exceptions.CommitException function in pyroute2

To help you get started, we’ve selected a few pyroute2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
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))
github svinota / pyroute2 / pyroute2 / ipdb / transactional.py View on Github external
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)
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
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'):
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
# 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 = {}
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
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
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
# 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]
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
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']
github svinota / pyroute2 / pyroute2 / ipdb / interfaces.py View on Github external
# 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))