本文整理汇总了Python中nodetraq.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodetraq.model.meta.Session
的用法示例。
在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_vms
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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()
示例2: update
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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'))
示例3: create_comment
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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))
示例4: update
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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))
示例5: rrd_file
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
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')
示例6: enable_host_svc
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
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})
示例7: create
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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))
示例8: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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()
示例9: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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()
示例10: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [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()
示例11: bulk_update
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
def bulk_update(self):
for k,v in request.params.iteritems():
data = json.loads(k)
# updates
for update in data['updates']:
try:
node_backup = Session.query(NodeDatabaseBackup).filter(
NodeDatabaseBackup.id == update['id']).first()
node_backup.server = Session.query(Node)\
.filter(Node.hostname == update['server']).first()
node_backup.server_id = node_backup.server.id
node_backup.storage = Session.query(Node)\
.filter(Node.hostname == \
update['storage']).first()
node_backup.storage_id = node_backup.storage.id
node_backup.directory = update['directory']
node_backup.enabled = update['enabled']
if node_backup.storage and node_backup.server:
Session.add(node_backup)
Session.commit()
except Exception as e:
session['flash'] = "Error: %s" % e
session.save()
return {"success": False}
# new backups
for backup in data['new_backups']:
try:
node = Session.query(Node).filter(
Node.hostname == backup['server']).first()
if not node.db_backups:
node.db_backups = []
node_backup = NodeDatabaseBackup()
node_backup.enabled = backup['enabled']
node_backup.server = node
node_backup.server_id = node_backup.server.id
node_backup.storage = Session.query(Node)\
.filter(Node.hostname == \
backup['storage']).first()
node_backup.storage_id = node_backup.storage.id
node_backup.directory = backup['directory']
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()
except Exception as e:
session['flash'] = "Error: %s" % e
session.save()
return {"success": False}
session['flash'] = "Successfully updated backups!"
session.save()
return {"success": True}
示例12: disablehost
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
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'))
示例13: sendbatchedit
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
def sendbatchedit(self):
response.content_type = 'application/json'
user_id = int(request.params['user_id'])
field = request.params['field']
info = [json.loads(d[1]) for d in request.params.items()\
if 'items[]' in d]
if field == 'hostname':
for item in info:
data = {}
data['hostname'] = item['hostname']
activity_engine = ActivityEngine(Session,
user_id)
status = activity_engine.update(
'node', item['node_id'], data)
session['flash'] = "Success"
session.save()
elif field == 'groups':
for item in info:
node = Session.query(Node)\
.filter(Node.id == item['node_id']).first()
group_list = item['groups']\
.replace(' ', '').split(',')
node.groups = Session.query(Group)\
.filter(Group.name.in_(group_list)).all()
Session.add(node)
Session.commit()
session['flash'] = "Success"
session.save()
elif field == 'db_backups':
for item in info:
backup = Session.query(NodeDatabaseBackup)\
.filter(NodeDatabaseBackup.id == item['backup_id'])\
.first()
node = Session.query(Node)\
.filter(Node.id == item['node_id']).first()
backup.server_id = node.id
if item['data_type'] == 'storage':
storage = Session.query(Node)\
.filter(Node.hostname == item['value']).first()
backup.storage_id = storage.id
elif item['data_type'] == 'directory':
backup.directory = item['value']
Session.add(backup)
Session.commit()
session['flash'] = "Success"
session.save()
else:
return '{"success": false}'
return '{"success": true}'
示例14: edit
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
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')
示例15: show
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import query [as 别名]
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__()