class Document(BASE, DeckhandBase): UNIQUE_CONSTRAINTS = ('schema', 'name', 'revision_id') __tablename__ = 'documents' id = Column(Integer, primary_key=True) name = Column(String(64), nullable=False) schema = Column(String(64), nullable=False) # NOTE(fmontei): ``metadata`` is reserved by the DB, so ``_metadata`` # must be used to store document metadata information in the DB. _metadata = Column(oslo_types.JsonEncodedDict(), nullable=False) data = Column(oslo_types.JsonEncodedDict(), nullable=True, default={}) data_hash = Column(String, nullable=False) metadata_hash = Column(String, nullable=False) is_secret = Column(Boolean, nullable=False, default=False) bucket_id = Column(Integer, ForeignKey('buckets.id', ondelete='CASCADE'), nullable=False) revision_id = Column(Integer, ForeignKey('revisions.id', ondelete='CASCADE'), nullable=False) # Used for documents that haven't changed across revisions but still have # been carried over into newer revisions. This is necessary in order to # roll back to previous revisions or to generate a revision diff. Without # recording all the documents that were PUT in a revision, this is rather # difficult. By using `orig_revision_id` it is therefore possible to # maintain the correct revision history -- that is, remembering the exact # revision a document was created in -- while still being able to roll # back to all the documents that exist in a specific revision or generate # an accurate revision diff report. orig_revision_id = Column(Integer, ForeignKey('revisions.id', ondelete='CASCADE'), nullable=True) UniqueConstraint(*UNIQUE_CONSTRAINTS) @hybrid_property def bucket_name(self): if hasattr(self, 'bucket') and self.bucket: return self.bucket.name return None def to_dict(self, raw_dict=False): """Convert the object into dictionary format. :param raw_dict: Renames the key "_metadata" to "metadata". """ d = super(Document, self).to_dict() d['bucket_name'] = self.bucket_name if not raw_dict: d['metadata'] = d.pop('_metadata') if 'bucket' in d: d.pop('bucket') return d
def test_mysql_variants(self): self.assertEqual( "LONGTEXT", str( types.JsonEncodedDict(mysql_as_long=True).compile( dialect=mysql.dialect()))) self.assertEqual( "MEDIUMTEXT", str( types.JsonEncodedDict(mysql_as_medium=True).compile( dialect=mysql.dialect()))) self.assertRaises( TypeError, lambda: types.JsonEncodedDict(mysql_as_long=True, mysql_as_medium=True))
def upgrade(): op.create_table( 'allocations', sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('version', sa.String(length=15), nullable=True), sa.Column('id', sa.Integer(), nullable=False), sa.Column('uuid', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=255), nullable=True), sa.Column('node_id', sa.Integer(), nullable=True), sa.Column('state', sa.String(length=15), nullable=False), sa.Column('last_error', sa.Text(), nullable=True), sa.Column('resource_class', sa.String(length=80), nullable=True), sa.Column('traits', types.JsonEncodedList(), nullable=True), sa.Column('candidate_nodes', types.JsonEncodedList(), nullable=True), sa.Column('extra', types.JsonEncodedDict(), nullable=True), sa.Column('conductor_affinity', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['conductor_affinity'], ['conductors.id'], ), sa.ForeignKeyConstraint( ['node_id'], ['nodes.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name', name='uniq_allocations0name'), sa.UniqueConstraint('uuid', name='uniq_allocations0uuid')) op.add_column('nodes', sa.Column('allocation_id', sa.Integer(), nullable=True)) op.create_foreign_key(None, 'nodes', 'allocations', ['allocation_id'], ['id'])
class RevisionTag(BASE, DeckhandBase): __tablename__ = 'revision_tags' id = Column(Integer, primary_key=True) tag = Column(String(64), nullable=False) data = Column(oslo_types.JsonEncodedDict(), nullable=True, default={}) revision_id = Column( Integer, ForeignKey('revisions.id', ondelete='CASCADE'), nullable=False)
class Validation(BASE, DeckhandBase): __tablename__ = 'validations' id = Column(Integer, primary_key=True) name = Column(String(64), nullable=False) status = Column(String(8), nullable=False) validator = Column(oslo_types.JsonEncodedDict(), nullable=False) errors = Column(oslo_types.JsonEncodedList(), nullable=False, default=[]) revision_id = Column( Integer, ForeignKey('revisions.id', ondelete='CASCADE'), nullable=False)
class RevisionTag(BASE, DeckhandBase): UNIQUE_CONSTRAINTS = ('tag', 'revision_id') __tablename__ = 'revision_tags' tag = Column(String(64), primary_key=True, nullable=False) data = Column(oslo_types.JsonEncodedDict(), nullable=True, default={}) revision_id = Column(Integer, ForeignKey('revisions.id', ondelete='CASCADE'), nullable=False) UniqueConstraint(*UNIQUE_CONSTRAINTS)
def upgrade(): op.create_table('introspection_data', sa.Column('uuid', sa.String(36), sa.ForeignKey('nodes.uuid'), primary_key=True), sa.Column('processed', sa.Boolean, default=False, primary_key=True), sa.Column( 'data', db_types.JsonEncodedDict(mysql_as_long=True).impl, nullable=True), mysql_ENGINE='InnoDB', mysql_DEFAULT_CHARSET='UTF8')
class Node(Base): """Represents a bare metal node.""" __tablename__ = 'nodes' __table_args__ = ( schema.UniqueConstraint('uuid', name='uniq_nodes0uuid'), schema.UniqueConstraint('instance_uuid', name='uniq_nodes0instance_uuid'), schema.UniqueConstraint('name', name='uniq_nodes0name'), table_args()) id = Column(Integer, primary_key=True) uuid = Column(String(36)) # NOTE(deva): we store instance_uuid directly on the node so that we can # filter on it more efficiently, even though it is # user-settable, and would otherwise be in node.properties. instance_uuid = Column(String(36), nullable=True) name = Column(String(255), nullable=True) chassis_id = Column(Integer, ForeignKey('chassis.id'), nullable=True) power_state = Column(String(15), nullable=True) target_power_state = Column(String(15), nullable=True) provision_state = Column(String(15), nullable=True) target_provision_state = Column(String(15), nullable=True) provision_updated_at = Column(DateTime, nullable=True) last_error = Column(Text, nullable=True) instance_info = Column(db_types.JsonEncodedDict(mysql_as_long=True)) properties = Column(db_types.JsonEncodedDict) driver = Column(String(255)) driver_info = Column(db_types.JsonEncodedDict) driver_internal_info = Column(db_types.JsonEncodedDict) clean_step = Column(db_types.JsonEncodedDict) resource_class = Column(String(80), nullable=True) raid_config = Column(db_types.JsonEncodedDict) target_raid_config = Column(db_types.JsonEncodedDict) # NOTE(deva): this is the host name of the conductor which has # acquired a TaskManager lock on the node. # We should use an INT FK (conductors.id) in the future. reservation = Column(String(255), nullable=True) # NOTE(deva): this is the id of the last conductor which prepared local # state for the node (eg, a PXE config file). # When affinity and the hash ring's mapping do not match, # this indicates that a conductor should rebuild local state. conductor_affinity = Column(Integer, ForeignKey('conductors.id', name='nodes_conductor_affinity_fk'), nullable=True) maintenance = Column(Boolean, default=False) maintenance_reason = Column(Text, nullable=True) console_enabled = Column(Boolean, default=False) inspection_finished_at = Column(DateTime, nullable=True) inspection_started_at = Column(DateTime, nullable=True) extra = Column(db_types.JsonEncodedDict) boot_interface = Column(String(255), nullable=True) console_interface = Column(String(255), nullable=True) deploy_interface = Column(String(255), nullable=True) inspect_interface = Column(String(255), nullable=True) management_interface = Column(String(255), nullable=True) network_interface = Column(String(255), nullable=True) raid_interface = Column(String(255), nullable=True) rescue_interface = Column(String(255), nullable=True) storage_interface = Column(String(255), nullable=True) power_interface = Column(String(255), nullable=True) vendor_interface = Column(String(255), nullable=True)
def upgrade(): op.alter_column('nodes', 'instance_info', existing_type=db_types.JsonEncodedDict.impl, type_=db_types.JsonEncodedDict(mysql_as_long=True).impl)
class IntrospectionData(Base): __tablename__ = 'introspection_data' uuid = Column(String(36), ForeignKey('nodes.uuid'), primary_key=True) processed = Column(Boolean, default=False, primary_key=True) data = Column(db_types.JsonEncodedDict(mysql_as_long=True), nullable=True)