def get_back_references_json(parent_row, parent_table, table, schema, idl, uri, selector=None, depth=0): references = schema.ovs_tables[table].references _refCol = None for key, value in references.iteritems(): if value.relation == OVSDB_SCHEMA_PARENT and value.ref_table == parent_table: _refCol = key break if _refCol is None: return None resources_list = [] if not depth: for row in idl.tables[table].rows.itervalues(): ref = row.__getattr__(_refCol) if ref.uuid == parent_row: tmp = utils.get_table_key(row, table, schema, idl) _uri = _create_uri(uri, tmp) resources_list.append(_uri) else: for row in idl.tables[table].rows.itervalues(): ref = row.__getattr__(_refCol) if ref.uuid == parent_row: json_row = get_row_json(row.uuid, _refCol, schema, idl, uri, selector, depth) resources_list.append(json_row) return resources_list
def get_column_json(column, row, table, schema, idl, uri, selector=None, depth=0, depth_counter=0): db_table = idl.tables[table] db_row = db_table.rows[row] db_col = db_row.__getattr__(column) current_table = schema.ovs_tables[table] # list of resources to return resources_list = [] # Reference Column col_table = current_table.references[column].ref_table column_table = schema.ovs_tables[col_table] # GET without depth if not depth: # Is a top level table if column_table.parent is None: uri = _get_base_uri() + column_table.plural_name # Is a child table, is faster concatenate the uri instead searching elif column_table.parent == current_table.name: # If this is a child reference URI don't add the column path. if column_table.plural_name not in uri: uri = uri.rstrip('/') uri += '/' + column_table.plural_name for value in db_col: ref_row = _get_referenced_row(schema, table, row, column, value, idl) # Reference with different parent, search the parent if column_table.parent is not None and \ column_table.parent != current_table.name: uri = _get_base_uri() uri += utils.get_reference_parent_uri(col_table, ref_row, schema, idl) uri += column_table.plural_name # Set URI for key tmp = utils.get_table_key(ref_row, column_table.name, schema, idl) _uri = _create_uri(uri, tmp) resources_list.append(_uri) # GET with depth else: for value in db_col: ref_row = _get_referenced_row(schema, table, row, column, value, idl) json_row = get_row_json(ref_row.uuid, col_table, schema, idl, uri, selector, depth, depth_counter) resources_list.append(json_row) return resources_list
def get_back_references_json(parent_row, parent_table, table, schema, idl, uri, selector=None, depth=0, fetch_readonly=False, manager=None): references = schema.ovs_tables[table].references _refCol = None for key, value in references.iteritems(): if (value.relation == OVSDB_SCHEMA_PARENT and value.ref_table == parent_table): _refCol = key break if _refCol is None: raise gen.Return(None) resources_list = [] if not depth: for row in idl.tables[table].rows.itervalues(): ref = row.__getattr__(_refCol) if ref.uuid == parent_row: tmp = utils.get_table_key(row, table, schema, idl, False) _uri = _create_uri(uri, tmp) resources_list.append(_uri) else: # Fetch all read-only columns prior to retrieving row data rows = [] for row in idl.tables[table].rows.itervalues(): ref = row.__getattr__(_refCol) if ref.uuid == parent_row: rows.append(row) if fetch_readonly and manager: yield utils.fetch_readonly_columns(schema, table, idl, manager, rows) for row in rows: json_row = yield get_row_json(row.uuid, table, schema, idl, uri, selector, depth, fetch_readonly=fetch_readonly, manager=manager) resources_list.append(json_row) raise gen.Return(resources_list)
def get_table_json(table, schema, idl, uri, selector=None, depth=0): db_table = idl.tables[table] resources_list = [] if not depth: for row in db_table.rows.itervalues(): tmp = utils.get_table_key(row, table, schema, idl) _uri = _create_uri(uri, tmp) resources_list.append(_uri) else: for row in db_table.rows.itervalues(): json_row = get_row_json(row.uuid, table, schema, idl, uri, selector, depth) resources_list.append(json_row) return resources_list
def subscription_changes_check_callback(self, manager, idl): """ Callback method invoked by manager of the IDL used for detecting notification subscription changes. """ table_changes = \ notifutils.get_table_changes_from_idl(consts.SUBSCRIPTION_TABLE, idl) for sub_uuid, sub_changes in table_changes.iteritems(): seqno = manager.curr_seqno if notifutils.is_resource_added(sub_changes, seqno): subscription_row = \ idl.tables[consts.SUBSCRIPTION_TABLE].rows[sub_uuid] subscription_name = \ utils.get_table_key(subscription_row, consts.SUBSCRIPTION_TABLE, self._schema, idl) # Only one key, so grab the first index subscription_name = subscription_name[0] app_log.debug("Subscription added for: \"%s\"" % subscription_name) resource_uri = \ utils.get_column_data_from_row(subscription_row, consts.SUBSCRIPTION_URI) try: subscription = \ yield self.create_subscription(subscription_name, subscription_row, resource_uri, idl) yield self.get_initial_values_and_notify(idl, subscription) self.add_subscription(sub_uuid, subscription) except Exception as e: app_log.error("Error while creating subscription: %s" % e) elif notifutils.is_resource_deleted(sub_changes, seqno): app_log.debug("Subscription was deleted.") self.remove_subscription(sub_uuid)
def get_table_json(table, schema, idl, uri, selector=None, depth=0, fetch_readonly=False, manager=None): db_table = idl.tables[table] resources_list = [] if not depth: for row in db_table.rows.itervalues(): tmp = utils.get_table_key(row, table, schema, idl) _uri = _create_uri(uri, tmp) resources_list.append(_uri) else: # Fetch all read-only columns prior to retrieving row data if fetch_readonly and manager: yield utils.fetch_readonly_columns_for_table( schema, table, idl, manager) for row in db_table.rows.itervalues(): json_row = yield get_row_json(row.uuid, table, schema, idl, uri, selector, depth, fetch_readonly=fetch_readonly, manager=manager) resources_list.append(json_row) raise gen.Return(resources_list)