Example #1
0
class Category(SurrogatePK, Model):
    __tablename__ = 'category'

    id = Column(db.Integer, primary_key=True)
    name = Column(db.String(50))
    desc = Column(db.String(50))

    def __init__(self, name=''):
        self.name = name

    def __repr__(self):
        return '<Category %r>' % self.name
class LoadBalance(Base):
    """
    the main table that used for web user, who can init the loadbalance host.
    """
    __tablename__ = "loadbalance"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    user_name = Column(String(256), nullable=False)
    user_id = Column(Integer(32), nullable=False)
    uuid = Column(String(256), nullable=False)
    instance_name = Column(String(256), nullable=False)
    realserver = Column(String(4096), default="[]", nullable=True)
    created_time = Column(DateTime, default=datetime.datetime.now,
                          onupdate=datetime.datetime.now)
    
    def __int__(self, user_name=None, user_id=None,
                uuid=None, instance_name=None, realserver=None):
        self.user_name = user_name
        self.user_id = user_id
        self.uuid = uuid
        self.realserver = realserver
    
    def __repr__(self):
        return "<LoadBalance('%s','%s','%s')>" % (self.user_name,
                                                  self.uuid, self.realserver)
Example #3
0
class Host(Base):
    """
    store loadbalance host information, logging informations is the main purpose.
    """
    __tablename__ = "host"

    id = Column(Integer, primary_key=True, autoincrement=True)
    agent = Column(String(128), nullable=True)
    created_time = Column(DateTime,
                          default=datetime.datetime.now,
                          onupdate=datetime.datetime.now)
    lb_type = Column(String(128), nullable=True)
    server_name_port = Column(String(128), nullable=True)
    upstream = Column(String(1024), nullable=True)
    distribute = Column(String(128), nullable=True)

    def __init__(self,
                 agent=None,
                 lb_type=None,
                 server_name_port=None,
                 upstream=None,
                 distribute=None):
        self.agent = agent
        self.lb_type = lb_type
        self.server_name_port = server_name_port
        self.upstream = upstream
        self.distribute = distribute

    def __repr__(self):
        return "<Host('%s','%s','%s','%s')>" % (
            self.server_name_port, self.upstream, self.distribute, self.agent)
Example #4
0
class UUID(Base):
    """
    uuid table, contains the loadbalance host for each loadbalance host.
    """
    __tablename__ = "uuid"

    id = Column(Integer, primary_key=True, autoincrement=True)
    uuid = Column(String(256), nullable=False)
    create_type = Column(String(128), nullable=False)
    lb_type = Column(String(32), nullable=False)
    src_port = Column(Integer(32), nullable=False)
    dst_port = Column(Integer(32), nullable=False)
    dns_name = Column(String(128), nullable=True)
    created_time = Column(DateTime,
                          default=datetime.datetime.now,
                          onupdate=datetime.datetime.now)

    node_id = Column(String(128), nullable=True)
    result = Column(String(128), nullable=True)

    def __int__(self,
                uuid=None,
                create_type=None,
                lb_type=None,
                src_port=None,
                dst_port=None,
                dns_name=None):
        self.uuid = uuid
        self.create_type = create_type
        self.lb_type = lb_type
        self.src_port = src_port
        self.dst_port = dst_port
        self.dns_name = dns_name

    def __repr__(self):
        return "<UUID('%s','%s','%s','%s','%s','%s')>" % (
            self.uuid, self.create_type, self.lb_type, self.src_port,
            self.dst_port, self.dns_name)
Example #5
0
class Role(SurrogatePK, Model):
    """A role for a user."""

    __tablename__ = 'roles'
    name = Column(db.String(80), unique=True, nullable=False)
    user_id = reference_col('users', nullable=True)
    user = relationship('User', backref='roles')

    def __init__(self, name='', **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<Role({name})>'.format(name=self.name)
Example #6
0
class Post(SurrogatePK, Model):
    __tablename__ = 'posts'

    id = Column(db.Integer, primary_key=True)
    title = Column(db.String(80))
    body = Column(db.Text)
    pub_date = Column(db.DateTime)

    category_id = reference_col('category', nullable=True)
    category = relationship('Category', backref='posts')

    # category_id = Column(db.Integer, db.ForeignKey('category.id'))
    # category = db.relationship('Category', backref=db.backref('posts', lazy='dynamic'))

    def __init__(self, title='', body='', category=None, pub_date=None):
        self.title = title
        self.body = body
        if pub_date is None:
            pub_date = datetime.utcnow()
        self.pub_date = pub_date
        self.category = category

    def __repr__(self):
        return '<Post %r>' % self.title
Example #7
0
class User(UserMixin, SurrogatePK, Model):
    """A user of the app."""

    __tablename__ = 'users'
    username = Column(db.String(80), unique=True, nullable=False)
    email = Column(db.String(80), unique=True, nullable=False)
    #: The hashed password
    password = Column(db.Binary(128), nullable=True)
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=dt.datetime.utcnow)
    first_name = Column(db.String(30), nullable=True)
    last_name = Column(db.String(30), nullable=True)
    active = Column(db.Boolean(), default=False)
    is_admin = Column(db.Boolean(), default=False)

    def __init__(self, username='', email='', password=None, **kwargs):
        """Create instance."""
        db.Model.__init__(self, username=username, email=email, **kwargs)
        if password:
            self.set_password(password)
        else:
            self.password = None

    def set_password(self, password):
        """Set password."""
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, value):
        """Check password."""
        return bcrypt.check_password_hash(self.password, value)

    @property
    def full_name(self):
        """Full user name."""
        return '{0} {1}'.format(self.first_name, self.last_name)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<User({username!r})>'.format(username=self.username)
Example #8
0
class DNSRecord(Base):
    """
    table used for bind8 dns server
    """
    __tablename__ = "dns_records"

    id = Column(Integer, primary_key=True, autoincrement=True)
    zone = Column(String(255), nullable=False)
    host = Column(String(255), nullable=False)
    type = Column(String(255), nullable=False)
    data = Column(String(255), nullable=False)

    ttl = Column(Integer(11), nullable=True)

    mx_priority = Column(String(255), nullable=True)

    refresh = Column(Integer(11), nullable=True)
    retry = Column(Integer(11), nullable=False)
    expire = Column(Integer(11), nullable=True)
    minimum = Column(Integer(11), nullable=True)

    serial = Column(Integer(32), nullable=True)

    resp_person = Column(String(255), nullable=True)
    primary_ns = Column(String(255), nullable=True)

    def __init__(self,
                 zone=None,
                 host=None,
                 type=None,
                 data=None,
                 ttl=None,
                 mx_priority=None,
                 refresh=None,
                 retry=None,
                 expire=None,
                 minimum=None,
                 serial=None,
                 resp_person=None,
                 primary_ns=None):
        self.zone = zone
        self.host = host
        self.type = type
        self.data = data
        self.ttl = ttl
        self.mx_priority = mx_priority
        self.refresh = refresh
        self.retry = retry
        self.expire = expire
        self.minimum = minimum
        self.serial = serial
        self.resp_person = resp_person
        self.primary_ns = primary_ns

    def __repr__(self):
        return "<DNSRecord('%s','%s','%s','%s')>" % (self.zone, self.host,
                                                     self.type, self.data)