本文整理汇总了Python中nodetraq.model.meta.Session.add方法的典型用法代码示例。如果您正苦于以下问题:Python Session.add方法的具体用法?Python Session.add怎么用?Python Session.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodetraq.model.meta.Session
的用法示例。
在下文中一共展示了Session.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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))
示例2: create
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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'))
示例3: update
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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'))
示例4: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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()
示例5: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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()
示例6: create
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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}
示例7: update_groups
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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()
示例8: update_vms
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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()
示例9: create_comment
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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))
示例10: update
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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))
示例11: update_comment
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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))
示例12: sendbatchedit
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [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}'
示例13: new_studio
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [as 别名]
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}
示例14: update_studio
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [as 别名]
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}
示例15: grab_controller
# 需要导入模块: from nodetraq.model.meta import Session [as 别名]
# 或者: from nodetraq.model.meta.Session import add [as 别名]
def grab_controller(cls, controller_name):
if not controller_name:
return None
controller = Session.query(cls).filter(cls.name == controller_name).first()
if controller:
return controller.id
else:
c = cls()
c.name = controller_name
Session.add(c)
Session.commit()
return c.id