X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=python%2Fovs%2Fdb%2Fidl.py;h=3a8dec2828cac76e559901dfd47c5d5cbdb648b9;hb=ab678217dd626b1bf3f17f784272438e46190834;hp=36a7bab285efa06063def07b4327c0ecda240ece;hpb=2f92678735d089e2d2a0cb9e5f6ff3aae7ed38c0;p=openvswitch diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 36a7bab2..3a8dec28 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks +# Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -758,6 +758,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 +1200,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 +1235,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 +1253,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 +1269,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