~ubuntu-branches/ubuntu/wily/openvswitch/wily

« back to all changes in this revision

Viewing changes to python/ovs/db/idl.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-10 11:35:15 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20150810113515-575vj06oq29emxsn
Tags: 2.4.0~git20150810.97bab95-0ubuntu1
* New upstream snapshot from 2.4 branch:
  - d/*: Align any relevant packaging changes with upstream.
* d/*: wrap-and-sort.
* d/openvswitch-{common,vswitch}.install: Correct install location for
  bash completion files.
* d/tests/openflow.py: Explicitly use ovs-testcontroller as provided
  by 2.4.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
__pychecker__ = 'no-classattr no-objattrs'
28
28
 
29
 
 
30
 
class Idl:
 
29
ROW_CREATE = "create"
 
30
ROW_UPDATE = "update"
 
31
ROW_DELETE = "delete"
 
32
 
 
33
 
 
34
class Idl(object):
31
35
    """Open vSwitch Database Interface Definition Language (OVSDB IDL).
32
36
 
33
37
    The OVSDB IDL maintains an in-memory replica of a database.  It issues RPC
264
268
            self.lock_name = lock_name
265
269
            self.__send_lock_request()
266
270
 
 
271
    def notify(self, event, row, updates=None):
 
272
        """Hook for implementing create/update/delete notifications
 
273
 
 
274
        :param event:   The event that was triggered
 
275
        :type event:    ROW_CREATE, ROW_UPDATE, or ROW_DELETE
 
276
        :param row:     The row as it is after the operation has occured
 
277
        :type row:      Row
 
278
        :param updates: For updates, a Row object with just the changed columns
 
279
        :type updates:  Row
 
280
        """
 
281
 
267
282
    def __clear(self):
268
283
        changed = False
269
284
 
386
401
            if row:
387
402
                del table.rows[uuid]
388
403
                changed = True
 
404
                self.notify(ROW_DELETE, row)
389
405
            else:
390
406
                # XXX rate-limit
391
407
                vlog.warn("cannot delete missing row %s from table %s"
401
417
                          % (uuid, table.name))
402
418
            if self.__row_update(table, row, new):
403
419
                changed = True
 
420
                self.notify(ROW_CREATE, row)
404
421
        else:
 
422
            op = ROW_UPDATE
405
423
            if not row:
406
424
                row = self.__create_row(table, uuid)
407
425
                changed = True
 
426
                op = ROW_CREATE
408
427
                # XXX rate-limit
409
428
                vlog.warn("cannot modify missing row %s in table %s"
410
429
                          % (uuid, table.name))
411
430
            if self.__row_update(table, row, new):
412
431
                changed = True
 
432
                self.notify(op, row, Row.from_json(self, table, uuid, old))
413
433
        return changed
414
434
 
415
435
    def __row_update(self, table, row, row_json):
570
590
            return
571
591
        self._idl.txn._write(self, column, datum)
572
592
 
 
593
    @classmethod
 
594
    def from_json(cls, idl, table, uuid, row_json):
 
595
        data = {}
 
596
        for column_name, datum_json in row_json.iteritems():
 
597
            column = table.columns.get(column_name)
 
598
            if not column:
 
599
                # XXX rate-limit
 
600
                vlog.warn("unknown column %s in table %s"
 
601
                          % (column_name, table.name))
 
602
                continue
 
603
            try:
 
604
                datum = ovs.db.data.Datum.from_json(column.type, datum_json)
 
605
            except error.Error, e:
 
606
                # XXX rate-limit
 
607
                vlog.warn("error parsing column %s in table %s: %s"
 
608
                          % (column_name, table.name, e))
 
609
                continue
 
610
            data[column_name] = datum
 
611
        return cls(idl, table, uuid, data)
 
612
 
573
613
    def verify(self, column_name):
574
614
        """Causes the original contents of column 'column_name' in this row to
575
615
        be verified as a prerequisite to completing the transaction.  That is,
835
875
            return self._status
836
876
 
837
877
        # If we need a lock but don't have it, give up quickly.
838
 
        if self.idl.lock_name and not self.idl.has_lock():
 
878
        if self.idl.lock_name and not self.idl.has_lock:
839
879
            self._status = Transaction.NOT_LOCKED
840
880
            self.__disassemble()
841
881
            return self._status
1034
1074
        # transaction only does writes of existing values, without making any
1035
1075
        # real changes, we will drop the whole transaction later in
1036
1076
        # ovsdb_idl_txn_commit().)
1037
 
        if not column.alert and row._data.get(column.name) == datum:
 
1077
        if not column.alert and row._data and row._data.get(column.name) == datum:
1038
1078
            new_value = row._changes.get(column.name)
1039
1079
            if new_value is None or new_value == datum:
1040
1080
                return