Exemplo n.º 1
0
    def run_idl(self, txn):
        table_schema = self.api._tables[self.table]
        idx = idlutils.get_index_column(table_schema)
        columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
        # If there's an index for this table, we'll fetch all columns and
        # remove the unwanted ones based on self.records. Otherwise, let's try
        # to get the uuid of the wanted ones which is an O(n^2) operation.
        if not idx and self.records:
            rows = []
            for record in self.records:
                try:
                    rows.append(
                        idlutils.row_by_record(self.api.idl, self.table,
                                               record))
                except idlutils.RowNotFound:
                    if self.if_exists:
                        continue
                    self._raise_notfound()
        else:
            rows = table_schema.rows.values()

        if idx and self.records:
            match = lambda row: getattr(row, idx) in self.records
        else:
            match = lambda row: True

        self.result = [{c: idlutils.get_column_value(row, c)
                        for c in columns} for row in rows if match(row)]

        if (not self.if_exists and idx and self.records
                and len(self.result) < len(self.records)):
            self._raise_notfound()
Exemplo n.º 2
0
 def run_idl(self, txn):
     table_schema = self.api._tables[self.table]
     columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
     if self.records:
         row_uuids = []
         for record in self.records:
             try:
                 row_uuids.append(
                     idlutils.row_by_record(self.api.idl, self.table,
                                            record).uuid)
             except idlutils.RowNotFound:
                 if self.if_exists:
                     continue
                 # NOTE(kevinbenton): this is converted to a RuntimeError
                 # for compat with the vsctl version. It might make more
                 # sense to change this to a RowNotFoundError in the future.
                 raise RuntimeError(
                     _("Row doesn't exist in the DB. Request info: "
                       "Table=%(table)s. Columns=%(columns)s. "
                       "Records=%(records)s.") % {
                           "table": self.table,
                           "columns": self.columns,
                           "records": self.records,
                       })
     else:
         row_uuids = table_schema.rows.keys()
     self.result = [{
         c: idlutils.get_column_value(table_schema.rows[uuid], c)
         for c in columns
     } for uuid in row_uuids]
Exemplo n.º 3
0
 def run_idl(self, txn):
     table_schema = self.api._tables[self.table]
     columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
     if self.records:
         row_uuids = []
         for record in self.records:
             try:
                 row_uuids.append(idlutils.row_by_record(
                                  self.api.idl, self.table, record).uuid)
             except idlutils.RowNotFound:
                 if self.if_exists:
                     continue
                 # NOTE(kevinbenton): this is converted to a RuntimeError
                 # for compat with the vsctl version. It might make more
                 # sense to change this to a RowNotFoundError in the future.
                 raise RuntimeError(_(
                       "Row doesn't exist in the DB. Request info: "
                       "Table=%(table)s. Columns=%(columns)s. "
                       "Records=%(records)s.") % {
                           "table": self.table,
                           "columns": self.columns,
                           "records": self.records,
                       })
     else:
         row_uuids = table_schema.rows.keys()
     self.result = [
         {
             c: idlutils.get_column_value(table_schema.rows[uuid], c)
             for c in columns
         }
         for uuid in row_uuids
     ]
Exemplo n.º 4
0
 def run_idl(self, txn):
     self.result = [
         {
             c: idlutils.get_column_value(self.table.rows[uuid], c)
             for c in self.columns
         }
         for uuid in self.records
     ]
Exemplo n.º 5
0
 def run_idl(self, txn):
     self.result = [
         {
             c: idlutils.get_column_value(r, c)
             for c in self.columns
         }
         for r in self.table.rows.values()
         if idlutils.row_match(r, self.conditions)
     ]
Exemplo n.º 6
0
 def run_idl(self, txn):
     self.result = [
         {
             c: idlutils.get_column_value(r, c)
             for c in self.columns
         }
         for r in self.table.rows.values()
         if idlutils.row_match(r, self.conditions)
     ]
Exemplo n.º 7
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     # TODO(twilson) This feels wrong, but ovs-vsctl returns single results
     # on set types without the list. The IDL is returning them as lists,
     # even if the set has the maximum number of items set to 1. Might be
     # able to inspect the Schema and just do this conversion for that case.
     result = idlutils.get_column_value(record, self.column)
     if isinstance(result, list) and len(result) == 1:
         self.result = result[0]
     else:
         self.result = result
Exemplo n.º 8
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     # TODO(twilson) This feels wrong, but ovs-vsctl returns single results
     # on set types without the list. The IDL is returning them as lists,
     # even if the set has the maximum number of items set to 1. Might be
     # able to inspect the Schema and just do this conversion for that case.
     result = idlutils.get_column_value(record, self.column)
     if isinstance(result, list) and len(result) == 1:
         self.result = result[0]
     else:
         self.result = result
Exemplo n.º 9
0
 def run_idl(self, txn):
     try:
         self.result = [
             {
                 c: idlutils.get_column_value(self.table.rows[uuid], c)
                 for c in self.columns
                 if not self.if_exists or uuid in self.table.rows
             }
             for uuid in self.records
         ]
     except KeyError:
         # NOTE(kevinbenton): this is converted to a RuntimeError for compat
         # with the vsctl version. It might make more sense to change this
         # to a RowNotFoundError in the future.
         raise RuntimeError(_LE(
               "Row removed from DB during listing. Request info: "
               "Table=%(table)s. Columns=%(columns)s. "
               "Records=%(records)s.") % self.requested_info)
Exemplo n.º 10
0
 def run_idl(self, txn):
     self.result = [{
         c: idlutils.get_column_value(self.table.rows[uuid], c)
         for c in self.columns
     } for uuid in self.records]