本文整理汇总了Python中nodetraq.model.meta.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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})
示例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')
示例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()
示例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))
示例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}
示例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'))
示例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()
示例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}
示例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}
示例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'))
示例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()
示例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))
示例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))
示例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()
示例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()