self.entries.remove(remote_ip)
-def keep_table_columns(schema, table_name, column_types):
- table = schema.tables.get(table_name)
- if not table:
- raise error.Error("schema has no %s table" % table_name)
-
- new_columns = {}
- for column_name, column_type in column_types.iteritems():
- column = table.columns.get(column_name)
- if not column:
- raise error.Error("%s table schema lacks %s column"
- % (table_name, column_name))
- if column.type != column_type:
- raise error.Error("%s column in %s table has type \"%s\", "
- "expected type \"%s\""
- % (column_name, table_name,
- column.type.toEnglish(),
- column_type.toEnglish()))
- new_columns[column_name] = column
- table.columns = new_columns
- return table
-
-
-def prune_schema(schema):
- string_type = types.Type(types.BaseType(types.StringType))
- optional_ssl_type = types.Type(types.BaseType(types.UuidType,
- ref_table_name='SSL'), None, 0, 1)
- string_map_type = types.Type(types.BaseType(types.StringType),
- types.BaseType(types.StringType),
- 0, sys.maxint)
-
- new_tables = {}
- new_tables["Interface"] = keep_table_columns(
- schema, "Interface", {"name": string_type,
- "type": string_type,
- "options": string_map_type})
- new_tables["Open_vSwitch"] = keep_table_columns(
- schema, "Open_vSwitch", {"ssl": optional_ssl_type})
- new_tables["SSL"] = keep_table_columns(
- schema, "SSL", {"certificate": string_type,
- "private_key": string_type})
- schema.tables = new_tables
-
-
def update_ipsec(ipsec, interfaces, new_interfaces):
for name, vals in interfaces.iteritems():
if name not in new_interfaces:
root_prefix = args.root_prefix
remote = args.database
- schema_file = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR
- schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schema_file))
- prune_schema(schema)
- idl = ovs.db.idl.Idl(remote, schema)
+ schema_helper = ovs.db.idl.SchemaHelper()
+ schema_helper.register_columns("Interface", ["name", "type", "options"])
+ schema_helper.register_columns("Open_vSwitch", ["ssl"])
+ schema_helper.register_columns("SSL", ["certificate", "private_key"])
+ idl = ovs.db.idl.Idl(remote, schema_helper)
ovs.daemon.daemonize()
The IDL uses and modifies 'schema' directly."""
- if isinstance(schema, SchemaHelper):
- schema = schema.get_idl_schema()
+ assert isinstance(schema, SchemaHelper)
+ schema = schema.get_idl_schema()
self.tables = schema.tables
self._db = schema
self.schema_location = location
self._tables = {}
+ self._all = False
def register_columns(self, table, columns):
"""Registers interest in the given 'columns' of 'table'. Future calls
columns = set(columns) | self._tables.get(table, set())
self._tables[table] = columns
+ def register_all(self):
+ """Registers interest in every column of every table."""
+ self._all = True
+
def get_idl_schema(self):
"""Gets a schema appropriate for the creation of an 'ovs.db.id.IDL'
object based on columns registered using the register_columns()
schema = ovs.db.schema.DbSchema.from_json(
ovs.json.from_file(self.schema_location))
- schema_tables = {}
- for table, columns in self._tables.iteritems():
- schema_tables[table] = (
- self._keep_table_columns(schema, table, columns))
- schema.tables = schema_tables
+ if not self._all:
+ schema_tables = {}
+ for table, columns in self._tables.iteritems():
+ schema_tables[table] = (
+ self._keep_table_columns(schema, table, columns))
+
+ schema.tables = schema_tables
return schema
def _keep_table_columns(self, schema, table_name, columns):
def do_idl(schema_file, remote, *commands):
- schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schema_file))
- idl = ovs.db.idl.Idl(remote, schema)
+ schema_helper = ovs.db.idl.SchemaHelper(schema_file)
+ schema_helper.register_all()
+ idl = ovs.db.idl.Idl(remote, schema_helper)
if commands:
error, stream = ovs.stream.Stream.open_block(
row.other_config = other_config
-def keep_table_columns(schema, table_name, columns):
- table = schema.tables.get(table_name)
- if not table:
- raise error.Error("schema has no %s table" % table_name)
-
- new_columns = {}
- for column_name in columns:
- column = table.columns.get(column_name)
- if not column:
- raise error.Error("%s table schema lacks %s column"
- % (table_name, column_name))
- new_columns[column_name] = column
- table.columns = new_columns
- return table
-
-
-def prune_schema(schema):
- new_tables = {}
- new_tables["Bridge"] = keep_table_columns(
- schema, "Bridge", ("name", "external_ids", "other_config",
- "fail_mode"))
- new_tables["Interface"] = keep_table_columns(
- schema, "Interface", ("name", "external_ids"))
- schema.tables = new_tables
-
-
def main():
global flush_cache
ovs.daemon.handle_args(args)
remote = args.database
- schema_file = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR
- schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schema_file))
- prune_schema(schema)
- idl = ovs.db.idl.Idl(remote, schema)
+ schema_helper = ovs.db.idl.SchemaHelper()
+ schema_helper.register_columns("Bridge", ["name", "external_ids",
+ "other_config", "fail_mode"])
+ schema_helper.register_columns("Interface", ["name", "external_ids"])
+ idl = ovs.db.idl.Idl(remote, schema_helper)
ovs.daemon.daemonize()