Example #1
0
 def create_notification(self, **kwargs):
     notif_data = {"topic": "discover", "message": "Test message", "status": "unread", "datetime": datetime.now()}
     if kwargs:
         notif_data.update(kwargs)
     notification = Notification()
     notification.cluster_id = notif_data.get("cluster_id")
     for f, v in notif_data.iteritems():
         setattr(notification, f, v)
     self.db.add(notification)
     self.db.commit()
     return notification
Example #2
0
 def create_notification(self, **kwargs):
     notif_data = {
         "topic": "discover",
         "message": "Test message",
         "status": "unread",
         "datetime": datetime.now()
     }
     if kwargs:
         notif_data.update(kwargs)
     notification = Notification()
     notification.cluster_id = notif_data.get("cluster_id")
     for f, v in notif_data.iteritems():
         setattr(notification, f, v)
     self.db.add(notification)
     self.db.commit()
     return notification
Example #3
0
def notify(topic, message,
           cluster_id=None, node_id=None, task_uuid=None):
    if topic == 'discover' and node_id is None:
        raise errors.CannotFindNodeIDForDiscovering(
            "No node id in discover notification")
    task = None
    if task_uuid:
        task = db().query(Task).filter_by(uuid=task_uuid).first()

    exist = None
    if node_id and task:
        exist = db().query(Notification).filter_by(
            node_id=node_id,
            message=message,
            task=task
        ).first()

    if not exist:
        notification = Notification()
        notification.topic = topic
        notification.message = message
        notification.cluster_id = cluster_id
        notification.node_id = node_id
        if task:
            notification.task_id = task.id
        notification.datetime = datetime.now()
        db().add(notification)
        db().commit()
        logger.info(
            "Notification: topic: %s message: %s" % (topic, message)
        )