monitorSystem.py 2.54 KB
Newer Older
wanli's avatar
wanli committed
1 2 3 4 5 6 7 8
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-21 18:39:45
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\models\monitorSystem.py
'''
9 10
#!/usr/bin/env python
# -*- coding: utf_8 -*-
wanli's avatar
wanli committed
11 12 13 14 15 16

from application.app import db, ma
from .base import PrimaryModel 
from marshmallow import Schema, fields, INCLUDE, EXCLUDE

class MonitorSystemModel(PrimaryModel):
17
    __tablename__ = 'evm_monitor_system'
wanli's avatar
wanli committed
18 19

    watch = db.Column(db.Integer, nullable = False)
20
    free_size = db.Column(db.Integer, nullable = True, default = 0)
wanli's avatar
wanli committed
21 22
    free_space_size = db.Column(db.Integer, nullable = True, default = 0)
    used_space_size = db.Column(db.Integer, nullable = True, default = 0)
wanli's avatar
wanli committed
23 24 25 26 27 28 29 30
    host = db.Column(db.String(20), index = True, nullable = False, default = '')
    path = db.Column(db.String(20), index = True, nullable = False, default = '')
    protocol = db.Column(db.String(20), index = True, nullable = False, default = '')

    # __table_args__ = (
    #     db.Index('idx_xxx', 'xxx', mysql_using='btree'),
    # )

wanli's avatar
wanli committed
31
    def __init__(self, watch, free_size=0, free_space_size=0, used_space_size=0, host='', path='', protocol=''):
wanli's avatar
wanli committed
32 33
        self.watch = watch
        self.free_size = free_size
wanli's avatar
wanli committed
34 35
        self.free_space_size = free_space_size
        self.used_space_size = used_space_size
wanli's avatar
wanli committed
36 37 38 39 40 41 42
        self.host = host
        self.path = path
        self.protocol = protocol

    def __repr__(self):
        return '<MonitorSystemModel %r>' % (self.watch)

43
    def to_dict(self):
wanli's avatar
wanli committed
44 45 46
        return {
            'watch': self.watch,
            'free_size': self.free_size,
wanli's avatar
wanli committed
47 48
            'free_space_size': self.free_space_size,
            'used_space_size': self.used_space_size,
wanli's avatar
wanli committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
            'host': self.host,
            'path': self.path,
            'protocol': self.protocol,
        }


class GetListMonitorSystemSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorSystemModel

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    watch = ma.auto_field()

getListMonitorSystemSchema = GetListMonitorSystemSchema()
getListMonitorSystemsSchema = GetListMonitorSystemSchema(many=True)

class GetMonitorSystemSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorSystemModel

    watch = ma.auto_field()

getMonitorSystemSchema = GetMonitorSystemSchema()