当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.merge方法代码示例

本文整理汇总了Python中vigilo.models.session.DBSession.merge方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.merge方法的具体用法?Python DBSession.merge怎么用?Python DBSession.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vigilo.models.session.DBSession的用法示例。


在下文中一共展示了DBSession.merge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_mapsegment

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_mapsegment(from_node, to_node, map):
    """
    Ajoute un segment entre deux éléments d'une carte.

    @param from_node: Nœud de départ du segment.
    @type from_node: L{tables.MapNode} ou C{basestring}
    @param to_node: Nœud d'arrivée du segment.
    @type to_node: L{tables.MapNode} ou C{basestring}
    @param map: Carte sur laquelle le segment doit être ajouté.
    @type map: L{tables.Map}
    @return: Le segment nouvellement créé.
    @rtype: L{tables.MapSegment}
    """
    if isinstance(from_node, basestring):
        from_node = tables.MapNode.by_map_label(map, unicode(from_node))
    if isinstance(to_node, basestring):
        to_node = tables.MapNode.by_map_label(map, unicode(to_node))
    ms = tables.MapSegment(idfrom_node=from_node.idmapnode,
                           idto_node=to_node.idmapnode,
                           idmap=map.idmap,
                           color=u'#000000',
                           thickness=2)
    DBSession.merge(ms)
    DBSession.flush()
    return ms
开发者ID:vigilo,项目名称:models,代码行数:27,代码来源:functions.py

示例2: add_ventilation

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_ventilation(host, server, application):
    """
    Ventile un hôte sur un serveur de supervision
    pour une application donnée.

    @param host: Hôte supervisé à ventiler.
    @type host: C{basestr} ou L{tables.Host}
    @param server: Serveur de supervision sur lequel ventiler.
    @type server: C{basestr} ou L{tables.VigiloServer}
    @param application: Application sur laquelle porte la ventilation.
    @type application: C{basestr} ou L{tables.Application}
    @return: Instance de ventilation créée.
        Cette fonction lèvera une exception si l'hôte est déjà ventilé
        sur un serveur de supervision pour l'application donnée.
    @rtype: L{tables.Ventilation}
    """
    if isinstance(host, basestring):
        host = tables.Host.by_host_name(unicode(host))
    if isinstance(server, basestring):
        server = tables.VigiloServer.by_vigiloserver_name(unicode(server))
    if isinstance(application, basestring):
        application = tables.Application.by_app_name(unicode(application))
    v = tables.Ventilation(
            idhost=host.idhost,
            idvigiloserver=server.idvigiloserver,
            idapp=application.idapp
        )
    DBSession.merge(v)
    DBSession.flush()
    return v
开发者ID:vigilo,项目名称:models,代码行数:32,代码来源:functions.py

示例3: add_maphlslink

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_maphlslink(from_node, to_node, hls, map):
    if isinstance(from_node, basestring):
        from_node = tables.MapNode.by_map_label(map, unicode(from_node))
    if isinstance(to_node, basestring):
        to_node = tables.MapNode.by_map_label(map, unicode(to_node))
    if isinstance(hls, basestring):
        hls = tables.HighLevelService.by_service_name()
    ms = tables.MapHlsLink(idfrom_node=from_node.idmapnode,
                               idto_node=to_node.idmapnode,
                               idref=hls.idservice,
                               idmap=map.idmap)
    DBSession.merge(ms)
    DBSession.flush()
    return ms
开发者ID:vigilo,项目名称:models,代码行数:16,代码来源:functions.py

示例4: after_insert

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
    def after_insert(self, mapper, connection, instance):
        from vigilo.models.tables.state import State
        from vigilo.models.tables.statename import StateName
        from vigilo.models.tables.service import Service

        # Pour un service (HLS ou LLS) : on initialise à UNKNOWN.
        if isinstance(instance, Service):
            state = StateName.statename_to_value(u"UNKNOWN")
        # Pour un hôte : on initialise à UP.
        else:
            state = StateName.statename_to_value(u"UP")

        s = State(idsupitem=instance.idsupitem, state=state, message=u"")
        DBSession.merge(s)
        return EXT_CONTINUE
开发者ID:vigilo,项目名称:models,代码行数:17,代码来源:supitem.py

示例5: add_event

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_event(supitem, statename, message, timestamp=None):
    """
    Ajoute un événement

    @param supitem: ID ou instance du supitem
    @type  supitem: C{int} ou sous-classe de L{tables.SupItem}
    @param statename: Nouvel état
    @type  statename: C{basestr}
    @param message: Message associé au nouvel état.
    @type  message: C{basestr}
    @param timestamp: timestamp de l'événement (par défaut: maintenant)
    @type  timestamp: C{datetime.datetime.DateTime}
    """
    if isinstance(supitem, int):
        idsupitem = supitem
    elif isinstance(supitem, tables.Host):
        idsupitem = supitem.idhost
    elif isinstance(supitem, tables.service.Service):
        idsupitem = supitem.idservice
    elif isinstance(supitem, tables.SupItem):
        idsupitem = supitem.idsupitem
    if timestamp is None:
        timestamp = datetime.now()
    e = tables.Event(
                idsupitem=idsupitem,
                current_state=tables.StateName.statename_to_value(statename),
                timestamp=timestamp,
                message=unicode(message),
                )
    e = DBSession.merge(e)
    DBSession.flush()
    return e
开发者ID:vigilo,项目名称:models,代码行数:34,代码来源:functions.py

示例6: add_host_state

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_host_state(host, statename, message=None, timestamp=None):
    """
    Met à jour l'état d'un hôte

    @param host: Nom, ID, ou instance de l'hôte.
    @type  host: C{str} ou C{int} ou L{tables.Host}
    @param statename: Nouvel état de l'hôte.
    @type  statename: C{basestr}
    @param message: Message associé au nouvel état.
    @type  message: C{basestr}
    """
    if isinstance(host, int):
        idhost = host
    elif isinstance(host, basestring):
        idhost = tables.Host.by_name(host).idhost
    else:
        idhost = host.idhost
    if timestamp is None:
        timestamp = datetime.now()
    s = tables.State(idsupitem=idhost,
                    state=tables.StateName.statename_to_value(statename),
                    message=unicode(message),
                    timestamp=timestamp,
                    )
    s = DBSession.merge(s)
    DBSession.flush()
    return s
开发者ID:vigilo,项目名称:models,代码行数:29,代码来源:functions.py

示例7: add_svc_state

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_svc_state(service, statename, message=None, timestamp=None):
    """
    Met à jour l'état d'un service (bas niveau ou haut niveau).

    @param service: Si c'est un tuple (hôte, service), on cherche un service de
        bas niveau. Si c'est une chaîne on cherche un service de haut niveau.
        Si c'est une instance on l'utilise telle quelle.
    @type  service: C{tuple} ou C{str} ou L{tables.LowLevelService} ou
        L{tables.HighLevelService}
    @param statename: Nouvel état du service.
    @type  statename: C{basestr}
    @param message: Message associé au nouvel état.
    @type  message: C{basestr}
    """
    if isinstance(service, tuple):
        service = [ unicode(s) for s in service ]
        service = tables.LowLevelService.by_host_service_name(*service)
    elif isinstance(service, basestring):
        service = tables.HighLevelService.by_service_name(service)
    if timestamp is None:
        timestamp = datetime.now()
    s = tables.State(idsupitem=service.idservice,
                    state=tables.StateName.statename_to_value(statename),
                    message=unicode(message),
                    timestamp=timestamp,
                    )
    s = DBSession.merge(s)
    DBSession.flush()
    return s
开发者ID:vigilo,项目名称:models,代码行数:31,代码来源:functions.py

示例8: add_mapllslink

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_mapllslink(from_node, to_node, lls, map):
    if isinstance(from_node, basestring):
        from_node = tables.MapNode.by_map_label(map, unicode(from_node))
    if isinstance(to_node, basestring):
        to_node = tables.MapNode.by_map_label(map, unicode(to_node))
    if isinstance(lls, tuple):
        lls = [unicode(s) for s in lls]
        lls = tables.LowLevelService.by_host_service_name(*lls)
    pds_in = add_perfdatasource('ineth0', lls.host)
    pds_out = add_perfdatasource('outeth0', lls.host)
    ms = tables.MapLlsLink(idfrom_node=from_node.idmapnode,
                               idto_node=to_node.idmapnode,
                               idref=lls.idservice, idmap=map.idmap,
                               ds_out=pds_out,
                               ds_in=pds_in)
    DBSession.merge(ms)
    DBSession.flush()
    return ms
开发者ID:vigilo,项目名称:models,代码行数:20,代码来源:functions.py

示例9: setup

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
 def setup(self):
     """Set up the fixture used to test the model."""
     setup_db()
     try:
         print "Class being tested:", self.klass
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         self.obj = DBSession.merge(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
开发者ID:vigilo,项目名称:models,代码行数:17,代码来源:controller.py

示例10: add_correvent

# 需要导入模块: from vigilo.models.session import DBSession [as 别名]
# 或者: from vigilo.models.session.DBSession import merge [as 别名]
def add_correvent(events, cause=None, status=tables.CorrEvent.ACK_NONE,
                  priority=4, timestamp=None):
    """
    Ajoute un événement corrélé

    @param events: liste d'évènements bruts à associer
    @type  events: C{list}
    @param cause:  évènement brut à utiliser comme cause. Si None, on prend le
        premier de la liste L{events}.
    @type  cause:  L{tables.Event} ou C{None}
    @param status: état de prise en compte de l'évènement corrélé
    @type  status: C{int}
    @param priority: priorité de l'événement corrélé
    @type  priority: C{int}
    @param timestamp: timestamp de l'événement (par défaut: maintenant)
    @type  timestamp: C{datetime.datetime.DateTime}
    """
    # on veut des instances de Event dans la liste
    for i in range(len(events)):
        if isinstance(events[i], int):
            events[i] = DBSession.query(tables.Event).get(events[i])
    if cause is None:
        cause = events[0]
    if timestamp is None:
        timestamp = datetime.now()

    ce = tables.CorrEvent(
                idcause=cause.idevent,
                events=events,
                priority=priority,
                ack=status,
                timestamp_active=timestamp,
                )
    ce = DBSession.merge(ce)
    DBSession.flush()
    return ce
开发者ID:vigilo,项目名称:models,代码行数:38,代码来源:functions.py


注:本文中的vigilo.models.session.DBSession.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。