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


Python Session.commit方法代码示例

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


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

示例1: update

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def update(self):
        id = request.params['id']
        graph = Session.query(Graph)\
            .filter(Graph.id == id).first()
        group = request.params['group_select']

        graph.name = request.params['graph_title']
        graph.filename = request.params['filename']
        graph.group = Session.query(Group)\
            .filter(Group.name == group).first()

        rrds = []
        for k,v in request.params.iteritems():
            if k == 'rrd_type':
                rrds.append(v)

        graph.rrd_types = ','.join(rrds)

        if not graph.name or not graph.group or not graph.rrd_types:
            session['flash'] = "Failed to update graph"
            session.save()
            return redirect(url(
                    controller='graphs', action='index'))

        Session.add(graph)
        Session.commit()
        session['flash'] = "Successfully updated"
        session.save()
        grab_new_drraw(graph)
        generate_index()
        return redirect(url(
                controller='graphs', action='index'))
开发者ID:seryl,项目名称:Nodetraq,代码行数:34,代码来源:graphs.py

示例2: update_groups

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
def update_groups():
    regex = '^r\d{3}$'
    for node in Session.query(Node).all():
        rack_name = 'r%s' % node.rack

        # create the group if it doesn't exist
        group = Session.query(Group)\
           .filter(Group.name == rack_name).first()

        if not group:
           group = create_group(rack_name)

        # add that computer to the group
        node.groups.append(group)
        Session.add(node)
        Session.commit()

        # Remove rack groups that a node is no longer a part of
        found_groups = [g for g in node.groups\
                            if re.search(regex, g.name) and g != group]

        for bad_group in found_groups:
            node.groups.remove(bad_group)

        Session.add(node)
        Session.commit()
开发者ID:seryl,项目名称:Nodetraq,代码行数:28,代码来源:create_rackgroups.py

示例3: update

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def update(self, id, backup_id):
        for k,v in request.params.iteritems():
            params = json.loads(k)
            break
        storage = params['storage']
        directory = params['directory']
        enabled = params['enabled']
        backup_type_id = params['backup_type']
        node_backup = Session.query(NodeDatabaseBackup).filter(
            NodeDatabaseBackup.id == backup_id).first()
        node_backup.server = Session.query(Node)\
                .filter(Node.id == id).first()
        node_backup.server_id = node_backup.server.id
        node_backup.storage = Session.query(Node)\
                .filter(Node.hostname == \
                storage).first()
        node_backup.storage_id = node_backup.storage.id
        node_backup.directory = directory
        node_backup.enabled = enabled
        node_backup.backup_type_id = backup_type_id

        if node_backup.storage and node_backup.server:
            Session.add(node_backup)
            Session.commit()
        else:
            session['flash'] = 'Storage hostname doesn\'t exist'
            session.save()

        return redirect(url(controller='dbbackups', action='index', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:31,代码来源:dbbackups.py

示例4: create

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def create(self, id):
        node = Session.query(Node).filter(Node.id == id).first()
        if not node.db_backups:
            node.db_backups = []

        node_backup = NodeDatabaseBackup()
        node_backup.enabled = True
        node_backup.server = Session.query(Node)\
                .filter(Node.id == id).first()
        node_backup.server_id = node_backup.server.id
        node_backup.storage = Session.query(Node)\
                .filter(Node.hostname == \
                request.params['storage']).first()
        node_backup.storage_id = node_backup.storage.id
        node_backup.directory = request.params['directory']
        node_backup.backup_type_id = request.params['backup_type']

        if node_backup.storage and node_backup.server:
            Session.add(node_backup)
            Session.commit()
            node.db_backups.append(node_backup)
            Session.add(node)
            Session.commit()
        else:
            session['flash'] = 'Storage hostname doesn\'t exist'
            session.save()

        return redirect(url(controller='dbbackups', action='index', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:30,代码来源:dbbackups.py

示例5: create_comment

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def create_comment(self):
        content = None
        node = None
        if 'comment' in request.params:
            content = request.params['comment']
            if not content:
                return redirect(
                    url(controller='nodes', action='show', id=id))

            if 'node' in request.params:
                id = request.params['node']
                node = Session.query(Node)\
                    .filter(Node.id == id).first()

        if node:
            if not node.comments:
                node.comments = []
            comment = NodeComment()
            comment.node_id = id
            user = Session.query(User).filter(
                User.id == session['active_user']['user_id']).first()
            comment.user_id = session['active_user']['user_id']
            comment.description = content
            node.comments.append(comment)
            Session.add(node)
            Session.add(comment)
            Session.commit()

        return redirect(url(controller='nodes', action='show', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:31,代码来源:nodes.py

示例6: create

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def create(self):
        graph_title = ''
        rrds = []
        group = None
        for k,v in request.params.iteritems():
            if k == 'rrd_type':
                rrds.append(v)
            elif k == 'graph_title':
                graph_title = v
            elif k == 'group_select':
                group = Session.query(Group)\
                    .filter(Group.name == v).first()
            else:
                pass

        graph = Graph()
        graph.name = graph_title
        graph.filename = 'g%s' % time()
        graph.rrd_types = ','.join(rrds)
        graph.group = group

        if not graph.name or not graph.rrd_types or not graph.group:
            session['flash'] = "Failed to created graph"
            session.save()
            return redirect(url(
                    controller='graphs', action='index'))

        Session.add(graph)
        Session.commit()
        session['flash'] = "Successfully created %s" % graph.name
        session.save()
        grab_new_drraw(graph)
        generate_index()
        return redirect(url(
                controller='graphs', action='index'))
开发者ID:seryl,项目名称:Nodetraq,代码行数:37,代码来源:graphs.py

示例7: update_groups

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
def update_groups():
    for node in Session.query(Node)\
        .filter(Node.hostname.startswith('sv')).all():

        # create the group if it doesn't exist
        group = Session.query(Group)\
           .filter(Group.name == 'idle').first()

        if not group:
           group = create_group('idle')

        # add that computer to the group
        node.groups = []
        node.groups.append(group)
        Session.add(node)
        Session.commit()

    for group in Session.query(Group)\
            .filter(Group.name == 'idle')\
            .all():
        if group:
            for node in group.nodes:
                if not node.hostname.startswith('sv'):
                    group.nodes.remove(node)

        Session.commit()
开发者ID:seryl,项目名称:Nodetraq,代码行数:28,代码来源:update_idle_nodes.py

示例8: update_groups

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
def update_groups():
    for node in Session.query(Node)\
            .filter(Node.model_name != None).all():

        # create the group if it doesn't exist
        group = Session.query(Group)\
           .filter(Group.name == generate_groupname(node.model_name)).first()

        if not group:
           group = create_group(generate_groupname(node.model_name))

        # add that computer to the group
        if not group in node.groups:
            node.groups.append(group)
            Session.add(node)
            Session.commit()

            # Remove rack groups that a node is no longer a part of
            # found_groups = [g for g in node.groups\
            #                    if re.search(regex, g.name) and g != group]

            # for bad_group in found_groups:
            #    node.groups.remove(bad_group)

            Session.add(node)
            Session.commit()
开发者ID:seryl,项目名称:Nodetraq,代码行数:28,代码来源:create_productgroups.py

示例9: destroy_comment

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
 def destroy_comment(self, id, commentid):
     comment = Session.query(NodeComment)\
             .filter(NodeComment.id == commentid).first()
     Session.delete(comment)
     Session.commit()
     return redirect(url(
         controller='nodes', action='show', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:9,代码来源:nodes.py

示例10: create

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def create(self):
        p = ['_hostname', 'logical',
         'management_ip', 'type',
         'serial_number', 'part_number',
         'mac_address', 'parent']

        try:
            data = json.loads(request.params.items()[0][0])['data']
        except:
            return {'success': False}

        network_device = NetworkDevice()
        count = 0
        for param in p:
            if param in data:
                if param == 'parent':
                    if not data[param]:
                        network_device.parent = None
                        continue
                    else:
                        network_device.parent = Session.query(
                            NetworkDevice).filter(
                            NetworkDevice.id == int(
                                    data[param])).first()
                        continue
                setattr(network_device,
                        param, data[param])
                count += 1
        if count:
            Session.add(network_device)
            Session.commit()
            return {'success': True}
        return {'success': False}
开发者ID:seryl,项目名称:Nodetraq,代码行数:35,代码来源:network.py

示例11: update_vms

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
def update_vms():
    xen_group = Session.query(Group)\
        .filter(Group.name == 'xen-dom0').first()
    vm_group = Session.query(Group)\
        .filter(Group.name == 'vm').first()
    vm_hosts = xen_group.nodes

    update_xen_nodes(get_xen_list(xen_group))

    for node in Session.query(Node).all():
        if node.xen_instance:
            if not vm_group in node.groups:
                node.groups.append(vm_group)

    for host in vm_hosts:
        vm_instances = Session.query(Node)\
            .filter(and_(Node.rack == host.rack,
                    Node.rack_u == host.rack_u,
                    )).all()
        vm_instances = [v for v in vm_instances if v not in vm_hosts]

        for node in vm_instances:
            n = Session.query(Node).filter(
                    Node.hostname == node.hostname).first()
            n.service_tag = host.service_tag
            n.drac_ip = None
            Session.add(n)
            Session.commit()
开发者ID:seryl,项目名称:Nodetraq,代码行数:30,代码来源:update_vms.py

示例12: destroy_studio

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def destroy_studio(self, id):
        studio = Session.query(Studio).filter(Studio.id == id).first()
        Session.delete(studio)
        Session.commit()

        session['flash'] = "Success"
        session.save()
        return {'success': True}
开发者ID:seryl,项目名称:Nodetraq,代码行数:10,代码来源:nodes.py

示例13: destroy_game

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def destroy_game(self, id):
        game = Session.query(Game).filter(Game.id == id).first()
        Session.delete(game)
        Session.commit()

        session['flash'] = "Success"
        session.save()
        return {'success': True}
开发者ID:seryl,项目名称:Nodetraq,代码行数:10,代码来源:nodes.py

示例14: destroy

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
    def destroy(self, id, backup_id):
        dbbackup = Session.query(NodeDatabaseBackup)\
            .filter(NodeDatabaseBackup.id == backup_id).first()
        Session.delete(dbbackup)
        Session.commit()
        session['flash'] = "Successfully destroyed dbbackup"
        session.save()

        return redirect(url(controller='dbbackups', action='index', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:11,代码来源:dbbackups.py

示例15: update_comment

# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import commit [as 别名]
 def update_comment(self, id, commentid):
     comment = Session.query(NodeComment)\
             .filter(NodeComment.id == commentid).first()
     if 'description' in request.params:
         comment.description = request.params['description']
     Session.add(comment)
     Session.commit()
     c.node_id = id
     return redirect(url(
         controller='nodes', action='show', id=id))
开发者ID:seryl,项目名称:Nodetraq,代码行数:12,代码来源:nodes.py


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