Merge branch 'mainstream'
[sliver-openvswitch.git] / python / ovs / db / idl.py
index e4b98e8..9e9bf0f 100644 (file)
@@ -548,6 +548,9 @@ class Row(object):
 
         datum = self._changes.get(column_name)
         if datum is None:
+            if self._data is None:
+                raise AttributeError("%s instance has no attribute '%s'" %
+                                     (self.__class__.__name__, column_name))
             datum = self._data[column_name]
 
         return datum.to_python(_uuid_to_row)
@@ -758,6 +761,8 @@ class Transaction(object):
                 row = self._txn_rows.get(uuid, None)
                 if row and row._data is None:
                     return ["named-uuid", _uuid_name_from_uuid(uuid)]
+            else:
+                return [self._substitute_uuids(elem) for elem in json]
         return json
 
     def __disassemble(self):
@@ -1198,13 +1203,22 @@ class SchemaHelper(object):
     The location on disk of the schema used may be found in the
     'schema_location' variable."""
 
-    def __init__(self, location=None):
-        """Creates a new Schema object."""
+    def __init__(self, location=None, schema_json=None):
+        """Creates a new Schema object.
+
+        'location' file path to ovs schema. None means default location
+        'schema_json' schema in json preresentation in memory
+        """
 
-        if location is None:
-            location = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR
+        if location and schema_json:
+            raise ValueError("both location and schema_json can't be "
+                             "specified. it's ambiguous.")
+        if schema_json is None:
+            if location is None:
+                location = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR
+            schema_json = ovs.json.from_file(location)
 
-        self.schema_location = location
+        self.schema_json = schema_json
         self._tables = {}
         self._all = False
 
@@ -1224,6 +1238,15 @@ class SchemaHelper(object):
         columns = set(columns) | self._tables.get(table, set())
         self._tables[table] = columns
 
+    def register_table(self, table):
+        """Registers interest in the given all columns of 'table'. Future calls
+        to get_idl_schema() will include all columns of 'table'.
+
+        'table' must be a string
+        """
+        assert type(table) is str
+        self._tables[table] = set()  # empty set means all columns in the table
+
     def register_all(self):
         """Registers interest in every column of every table."""
         self._all = True
@@ -1233,8 +1256,8 @@ class SchemaHelper(object):
         object based on columns registered using the register_columns()
         function."""
 
-        schema = ovs.db.schema.DbSchema.from_json(
-            ovs.json.from_file(self.schema_location))
+        schema = ovs.db.schema.DbSchema.from_json(self.schema_json)
+        self.schema_json = None
 
         if not self._all:
             schema_tables = {}
@@ -1249,6 +1272,10 @@ class SchemaHelper(object):
         assert table_name in schema.tables
         table = schema.tables[table_name]
 
+        if not columns:
+            # empty set means all columns in the table
+            return table
+
         new_columns = {}
         for column_name in columns:
             assert type(column_name) is str