Exemple #1
0
from NodeDefender.db.sql import SQL
from datetime import datetime
from NodeDefender.db.sql.node import LocationModel
import NodeDefender
from flask import url_for

user_list = SQL.Table(
    'user_list', SQL.Column('group_id', SQL.Integer,
                            SQL.ForeignKey('group.id')),
    SQL.Column('user_id', SQL.Integer, SQL.ForeignKey('user.id')))
node_list = SQL.Table(
    'node_list', SQL.Column('group_id', SQL.Integer,
                            SQL.ForeignKey('group.id')),
    SQL.Column('node_id', SQL.Integer, SQL.ForeignKey('node.id')))

mqtt_list = SQL.Table(
    'mqtt_list', SQL.Column('group_id', SQL.Integer,
                            SQL.ForeignKey('group.id')),
    SQL.Column('mqtt_id', SQL.Integer, SQL.ForeignKey('mqtt.id')))


class GroupModel(SQL.Model):
    '''
    Representing one group containing iCPEs and Users
    '''
    __tablename__ = 'group'
    id = SQL.Column(SQL.Integer, primary_key=True)
    name = SQL.Column(SQL.String(50))
    email = SQL.Column(SQL.String(120))
    description = SQL.Column(SQL.String(250))
    date_created = SQL.Column(SQL.DateTime)
Exemple #2
0
from NodeDefender.db.sql import SQL
from NodeDefender.db.sql.icpe import iCPEModel
from datetime import datetime
import NodeDefender

mqtt_icpe = SQL.Table(
    'mqtt_icpe', SQL.Column('mqtt_id', SQL.Integer, SQL.ForeignKey('mqtt.id')),
    SQL.Column('icpe_id', SQL.Integer, SQL.ForeignKey('icpe.id')))


class MQTTModel(SQL.Model):
    __tablename__ = 'mqtt'
    id = SQL.Column(SQL.Integer, primary_key=True)
    host = SQL.Column(SQL.String(128))
    port = SQL.Column(SQL.Integer)
    username = SQL.Column(SQL.String(64))
    password = SQL.Column(SQL.String(64))

    icpes = SQL.relationship('iCPEModel',
                             secondary=mqtt_icpe,
                             backref=SQL.backref('mqtt', lazy='dynamic'))
    date_created = SQL.Column(SQL.DateTime)

    def __init__(self, host, port, username=None, password=None):
        self.host = host
        self.port = int(port)
        self.username = username
        self.password = password
        self.date_created = datetime.now()

    def online(self):