Esempio n. 1
0
        def commit_f():
            operation = None
            while True:
                txn = idl.Transaction(self.idl)
                if bgp_path['is_withdraw']:
                    operation = 'del'
                    rows = self.idl.tables['BGP_Route'].rows.values()
                    for row in rows:
                        if utils.get_column_value(
                                row, 'prefix') == bgp_path['prefix']:
                            operation = 'del'
                            prefix_uuid = utils.get_column_value(row, '_uuid')
                            self.idl.tables['BGP_Route'].rows[
                                prefix_uuid].delete()

                else:
                    operation = 'add'
                    row_nh = utils.row_by_value(self.idl, 'BGP_Nexthop',
                                                'ip_address',
                                                bgp_path['nexthop'])
                    if not row_nh:
                        row_nh = txn.insert(self.idl.tables['BGP_Nexthop'])
                        row_nh.ip_address = bgp_path['nexthop']
                        row_nh.type = 'unicast'

                    row_path = txn.insert(self.idl.tables['BGP_Route'])
                    row_path.address_family = 'ipv4'
                    row_path.bgp_nexthops = row_nh
                    row_path.distance = []
                    row_path.metric = 0
                    row_path.path_attributes = bgp_path['bgp_pathattr']
                    row_path.peer = 'Remote announcement'
                    row_path.prefix = bgp_path['prefix']
                    row_path.sub_address_family = 'unicast'
                    row_path.vrf = self.idl.tables['VRF'].rows.values()[0]

                status = txn.commit_block()
                seqno = self.idl.change_seqno
                if status == txn.TRY_AGAIN:
                    log.error("OVSDB transaction returned TRY_AGAIN, retrying")
                    utils.wait_for_change(self.idl, self.timeout, seqno)
                    continue
                elif status == txn.ERROR:
                    log.error("OVSDB transaction returned ERROR: {0}".format(
                        txn.get_error()))
                elif status == txn.ABORTED:
                    log.error("Transaction aborted")
                    return
                elif status == txn.UNCHANGED:
                    log.error("Transaction caused no change")

                break

            if operation is None:
                log.warn('route is not exist in ops: prefix={0}'.format(
                    bgp_path['prefix']))
            else:
                log.debug('Send bgp route to ops: type={0}, prefix={1}'.format(
                    operation, bgp_path['prefix']))
Esempio n. 2
0
        def conn():
            log.info('Connecting to OpenSwitch...')
            helper = utils.get_schema_helper(self.ovsdb, self.schema_name)
            helper.register_all()
            self.idl = idl.Idl(self.ovsdb, helper)
            utils.wait_for_change(self.idl, self.timeout)
            self.poller = poller.Poller()

            self.hdr = handle.OpsHandler(self.idl, self)
Esempio n. 3
0
        def conn():
            log.info('Connecting to OpenSwitch...')
            helper = utils.get_schema_helper(self.ovsdb, self.schema_name)
            helper.register_all()
            self.idl = idl.Idl(self.ovsdb, helper)
            utils.wait_for_change(self.idl, self.timeout)
            self.poller = poller.Poller()

            self.hdr = handle.OpsHandler(self.idl, self)