Beispiel #1
0
    def add_pending_changes(cls, instance, changes_type, node_id=None):
        """Add pending changes for current Cluster.
        If node_id is specified then links created changes with node.

        :param instance: Cluster instance
        :param changes_type: name of changes to add
        :param node_id: node id for changes
        :returns: None
        """
        logger.debug(u"New pending changes in environment {0}: {1}{2}".format(
            instance.id, changes_type,
            u" node_id={0}".format(node_id) if node_id else u""))

        #TODO(enchantner): check if node belongs to cluster
        ex_chs = db().query(models.ClusterChanges).filter_by(cluster=instance,
                                                             name=changes_type)
        if not node_id:
            ex_chs = ex_chs.first()
        else:
            ex_chs = ex_chs.filter_by(node_id=node_id).first()
        # do nothing if changes with the same name already pending
        if ex_chs:
            return
        ch = models.ClusterChanges(cluster_id=instance.id, name=changes_type)
        if node_id:
            ch.node_id = node_id
        db().add(ch)
        db().flush()
Beispiel #2
0
 def update_changes(cls, instance, changes):
     instance.changes_list = [
         models.ClusterChanges(**change) for change in changes
     ]
     db().flush()