def list_hypervisor(req, db, context): action = get_input(req, 'action') if action == 'stats': return hopervisor_stats(db, context) else: results = admin_nova_client().hypervisors.list() return obj_array_to_json(results, 'hypervisors')
def list_dept(req, db, context): format = get_input(req, 'format') if (format and format == 'as_tree'): dept_id = context['user'].dept_id return '[' + json.dumps(get_dept_tree(db, dept_id)) + ']' else: return obj_array_to_json(context['depts'], 'depts')
def list_dept(req, db, context): format = get_input(req, 'format') if (format and format=='as_tree'): dept_id = context['user'].dept_id return '[' + json.dumps(get_dept_tree(db, dept_id)) + ']' else: return obj_array_to_json(context['depts'], 'depts')
def list_hypervisor(req, db, context): action = get_input(req, "action") if action == "stats": return hopervisor_stats(db, context) else: results = admin_nova_client().hypervisors.list() return obj_array_to_json(results, "hypervisors")
def list_volume(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有云硬盘 volumes = db.query(Volume).filter(Volume.dept.in_(context['dept_ids']), Volume.deleted==0).all() else: # 普通用户只能看到属于自己的云硬盘 volumes = db.query(Volume).filter(Volume.owner==context['user'].id, Volume.deleted==0).all() return obj_array_to_json(volumes, 'volumes')
def list_snapshot(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有云硬盘 snapshots = db.query(Snapshot).filter(Snapshot.dept.in_(context['dept_ids']), Snapshot.deleted==0).all() else: # 普通用户只能看到属于自己的云硬盘 snapshots = db.query(Snapshot).filter(Snapshot.owner==context['user'].id, Snapshot.deleted==0).all() return obj_array_to_json(snapshots, 'snapshots')
def list_volume(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有云硬盘 volumes = db.query(Volume).filter(Volume.dept.in_(context['dept_ids']), Volume.deleted == 0).all() else: # 普通用户只能看到属于自己的云硬盘 volumes = db.query(Volume).filter(Volume.owner == context['user'].id, Volume.deleted == 0).all() return obj_array_to_json(volumes, 'volumes')
def list_server(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有机器 servers = db.query(Server).filter(Server.dept.in_(context['dept_ids']), Server.deleted==0).all() else: # 普通用户只能看到属于自己的机器 servers = db.query(Server).filter(Server.owner==context['user'].id, Server.deleted==0).all() return obj_array_to_json(servers, 'servers')
def list_server(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有机器 servers = db.query(Server).filter(Server.dept.in_(context['dept_ids']), Server.deleted == 0).all() else: # 普通用户只能看到属于自己的机器 servers = db.query(Server).filter(Server.owner == context['user'].id, Server.deleted == 0).all() return obj_array_to_json(servers, 'servers')
def list_snapshot(req, db, context): if is_sys_admin_or_dept_admin(context): # 管理员可以看到部门下面所有云硬盘 snapshots = db.query(Snapshot).filter( Snapshot.dept.in_(context['dept_ids']), Snapshot.deleted == 0).all() else: # 普通用户只能看到属于自己的云硬盘 snapshots = db.query(Snapshot).filter( Snapshot.owner == context['user'].id, Snapshot.deleted == 0).all() return obj_array_to_json(snapshots, 'snapshots')
def list_image(req, db, context): images = db.query(Image).filter(Image.deleted==0).all() return obj_array_to_json(images, 'images')
def list_image(req, db, context): images = db.query(Image).filter(Image.deleted == 0).all() return obj_array_to_json(images, 'images')
def list_role(req, db): roles = db.query(Role) return obj_array_to_json(roles, 'roles')