52 lines
1.7 KiB
Python

from pillar_tool.db.base_model import Base
from sqlalchemy import Column, UUID, String, ForeignKey, UniqueConstraint, Boolean
class Pillar(Base):
"""
Describes a pillar by its name and parent. A parent equal to NULL mains that the pillar is a top level pillar.
Note that this is not a value, as the value is bound to the host.
"""
__tablename__ = 'pillar_tool_pillar'
id = Column(UUID, primary_key=True)
name = Column(String, nullable=False)
parent_id = Column(UUID, ForeignKey('pillar_tool_pillar.id'), nullable=True)
__table_args__ = (
UniqueConstraint('parent_id', 'name', name="pillar_parent_unique_name_parent"),
)
class PillarValue(Base):
"""
A value for a given pillar on a given host.
"""
__tablename__ = 'pillar_tool_pillar_value'
id = Column(UUID, primary_key=True)
pillar_id = Column(UUID, ForeignKey('pillar_tool_pillar.id'), nullable=False)
host_id = Column(UUID, ForeignKey('pillar_tool_host.id'), nullable=True)
type = Column(String, nullable=False)
value = Column(String, nullable=False)
__table_args__ = (
UniqueConstraint('pillar_id', 'host_id', name='pillar_value_unique_pillar_value'),
)
class Host(Base):
"""
Describes a host or a hostgroup by its name and parent. A parent equal to NULL mains that the host is a top level
host or hostgroup.
"""
__tablename__ = 'pillar_tool_host'
id = Column(UUID, primary_key=True)
name = Column(String, nullable=False)
parent_id = Column(UUID, ForeignKey('pillar_tool_host.id'), nullable=True)
__table_args__ = (
UniqueConstraint('name', 'parent_id', name='pillar_tool_host_unique_name'),
)