本文整理汇总了Python中nodetraq.model.meta.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: enable_host_svc
def enable_host_svc(self):
id_list = []
hostname_list = []
for k,v in request.params.iteritems():
if k == 'ids[]':
id_list.append(int(v))
if k == 'hostname':
hostname_list.append(v)
if id_list:
nodes = Session.query(Node.hostname).filter(
Node.id.in_(id_list)).all()
for node in nodes:
enable_host_service_notifications(node[0])
session['flash'] = 'Enabled host services successfully'
session.save()
return str({'success': True})
elif hostname_list:
nodes = Session.query(Node.hostname).filter(
Node.hostname.in_(hostname_list)).all()
for node in nodes:
enable_host_service_notifications(node[0])
session['flash'] = 'Enabled host services successfully'
session.save()
return str({'success': True})
else:
session['flash'] = 'Enable host services failed'
session.save()
return str({'success': False})
开发者ID:seryl,项目名称:Nodetraq,代码行数:29,代码来源:nagios.py
示例2: rrd_file
def rrd_file(self, id):
response.content_type = 'text/plain'
if id.isdigit():
graph_data = Session.query(Graph)\
.filter(Graph.id == int(id)).first()
else:
graph_data = Session.query(Graph)\
.filter(Graph.name == id).first()
c.graph = graph_data.filename[1:]
hostnames = [n.hostname for n in graph_data.get_hosts()]
c.datasource = generate_rrd_sequence_map(
hostnames, graph_data.get_rrds())
c.title = graph_data.name
if len(c.datasource) == 2:
c.colors = ['Lime', 'Red']
c.brmod = 2
else:
c.colors = ['Lime', 'Teal', 'Maroon']
c.brmod = 3
return render('/graphs/graph.mako')
开发者ID:seryl,项目名称:Nodetraq,代码行数:26,代码来源:graphs.py
示例3: update_groups
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,代码行数:26,代码来源:create_rackgroups.py
示例4: destroy_comment
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,代码行数:7,代码来源:nodes.py
示例5: create
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,代码行数:33,代码来源:network.py
示例6: create
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,代码行数:35,代码来源:graphs.py
示例7: update_groups
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,代码行数:26,代码来源:create_productgroups.py
示例8: destroy_studio
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,代码行数:8,代码来源:nodes.py
示例9: destroy_game
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,代码行数:8,代码来源:nodes.py
示例10: disablehost
def disablehost(self, format=None):
valid = False
response.content_type = "application/json"
ids = None
ips = None
data = {}
if 'ids[]' in request.params:
ids = [v for k,v in request.params.items() if 'ids[]' in k]
elif 'ips[]' in request.params:
ips = [v for k,v in reuqest.params.items() if 'ips[]' in k]
if 'pool' in request.params:
pool = request.params['pool']
if 'ports[]' in request.params:
ports = [v for k,v in request.params.items()\
if 'ports[]' in k]
if ids or ips:
valid = True
if not valid:
session['flash'] = 'No ids were sent'
session.save()
if format == 'json':
return '{"success": false}'
else:
return redirect(url(
controller='loadbalancer', action='index'))
lb = LoadBalancer(ip='your_lb_ip')
if ids:
data['hosts'] = [ q[0] for q in\
Session.query(Node.hostname)\
.filter(Node.id.in_(ids)).all() ]
members = [
':'.join([Session.query(Node.primary_ip)\
.filter(Node.id == id)\
.first()[0], ports[i]])\
for i,id in enumerate(ids)]
elif ips:
data['hosts'] = [q[0] for q in Session.query(Node.hostname)\
.filter(or_(Node.primary_ip.in_(ips),
Node.secondary_ip.in_(ips)))\
.all() ]
members = [
':'.join([ip, ports[i]]) for i,ip in enumerate(ips)]
lb.disable_members(pool, members)
data['type'] = 'disable'
data['pool'] = pool
ae = ActivityEngine(
Session, session['active_user']['user_id'])
status = ae.update('loadbalancer', None, data)
session['flash'] = status
if format == 'json':
return '{"success": true}'
else:
return redirect(url(
controller='loadbalancer', action='index'))
开发者ID:seryl,项目名称:Nodetraq,代码行数:58,代码来源:loadbalancer.py
示例11: __call__
def __call__(self, environ, start_response):
"""Invoke the Controller"""
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
try:
return WSGIController.__call__(self, environ, start_response)
finally:
Session.remove()
开发者ID:seryl,项目名称:Nodetraq,代码行数:9,代码来源:base.py
示例12: destroy
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,代码行数:9,代码来源:dbbackups.py
示例13: update_comment
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,代码行数:10,代码来源:nodes.py
示例14: update_groups
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,代码行数:26,代码来源:update_idle_nodes.py
示例15: update_vms
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,代码行数:28,代码来源:update_vms.py
示例16: edit
def edit(self, id):
id = unicode(id)
if id.isdigit():
c.group = Session.query(Group).filter(Group.id == id).first()
else:
c.group = Session.query(Group).filter(Group.name == id).first()
c.title = 'Nodetraq - Edit group %s' % c.group.name
c.selected_page = 'groups'
c.subpage = 'edit'
return render('/groups/edit.mako')
开发者ID:seryl,项目名称:Nodetraq,代码行数:11,代码来源:groups.py
示例17: show
def show(self, id, format='html'):
id = unicode(id)
if id.isdigit():
c.group = Session.query(Group).filter(Group.id == int(id)).first()
else:
c.group = Session.query(Group).filter(Group.name == id).first()
c.group_list = [g[0] for g in Session.query(Group.name)]
c.title = 'Nodetraq - Group - %s' % c.group.name
c.selected_page = 'groups'
c.subpage = 'show'
c.header = 'Groups : %s' % c.group.name
c.page = int(request.params['page'])\
if 'page' in request.params else 1
c.current_page_count = (c.page-1) * 25
c.node_count = len(c.group.nodes)
c.filters = [
{ 'name': 'group', 'label': 'Group', 'type': 'text' }
]
c.link_append = None
is_sorted = False
if 'sort' in request.params:
sortkey, sortorder = request.params['sort'].split(':')
is_sorted = True
c.sort_order = sortorder
else:
c.sort_order = None
if is_sorted:
if sortorder == 'asc':
c.nodes = c.group.nodes\
[c.current_page_count:c.current_page_count+25]
c.nodes = sorted(c.nodes, key=attrgetter(sortkey), reverse=False)
else:
c.nodes = c.group.nodes\
[c.current_page_count:c.current_page_count+25]
c.nodes = sorted(c.nodes, key=attrgetter(sortkey), reverse=True)
else:
c.nodes = c.group.nodes[c.current_page_count:c.current_page_count+25]
c.all_groups, c.tag_sizes = self.get_tag_info()
c.total_pages = (c.node_count+25-1)/25
c.request_url = request.environ.get('PATH_INFO')
if request.environ.get('QUERY_STRING'):
c.request_url += '?' + request.environ['QUERY_STRING']
if format == 'html':
return render('/nodes/list.mako')
elif format == 'json':
return c.group.__json__()
elif format == 'xml':
return c.group.__xml__()
开发者ID:seryl,项目名称:Nodetraq,代码行数:53,代码来源:groups.py
示例18: new_studio
def new_studio(self):
params = json.loads(request.params.iteritems().next()[0])
studio = Studio()
studio.name = params['name']
if 'description' in params:
studio.description = params['description']
Session.add(studio)
Session.commit()
session['flash'] = "Success"
session.save()
return {'success': True}
开发者ID:seryl,项目名称:Nodetraq,代码行数:12,代码来源:nodes.py
示例19: update_studio
def update_studio(self, id):
studio = Session.query(Studio).filter(Studio.id == id).first()
studio.name = request.params['name']
if 'description' in request.params:
studio.description = request.params['description']
Session.add(studio)
Session.commit()
session['flash'] = "Success"
session.save()
return {'success': True}
开发者ID:seryl,项目名称:Nodetraq,代码行数:12,代码来源:nodes.py
示例20: create_comment
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,代码行数:29,代码来源:nodes.py
注:本文中的nodetraq.model.meta.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论