本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput._anon方法的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput._anon方法的具体用法?Python JsonOutput._anon怎么用?Python JsonOutput._anon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudrunner_server.api.util.JsonOutput
的用法示例。
在下文中一共展示了JsonOutput._anon方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profiles
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import _anon [as 别名]
def profiles(self, name=None, *args):
def shares(p):
return [sh.serialize(
skip=['id', 'profile_id', 'password']) for sh in p]
def nodes(ns):
return [n.name for n in ns]
def shares_details(p):
return [sh.serialize(
skip=['id', 'profile_id', 'password'],
rel=[('shared_nodes', 'nodes', nodes)]
) for sh in p]
if name:
prof = CloudProfile.my(request).filter(
CloudProfile.name == name).first()
return O.profile(prof.serialize(
skip=['id', 'owner_id', 'share_id', 'password', 'arguments'],
rel=[('shares', 'shares', shares_details)]))
else:
profs = [p.serialize(
skip=['id', 'owner_id', 'share_id', 'password', 'arguments'],
rel=[('shares', 'shares', shares)])
for p in CloudProfile.my(request).all()]
return O._anon(
profiles=profs,
quota=dict(allowed=request.user.tier.cloud_profiles))
示例2: deployments
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import _anon [as 别名]
def deployments(self, name=None, **kwargs):
skip = ['id', 'owner_id']
def _encode(s):
try:
return json.loads(s)
except ValueError:
return {}
if name:
depl = Deployment.my(request).filter(
Deployment.name == name).first()
if depl:
return O.deployment(**depl.serialize(
skip=skip,
rel=[('content', 'content',
lambda p: _encode(p))]))
else:
return O.error(msg="Cannot find deployment '%s'" % name)
else:
depl = sorted([d.serialize(skip=skip)
for d in Deployment.my(request).all()],
key=lambda d: d['name'])
return O._anon(deployments=depl,
quota=dict(allowed=request.user.tier.deployments))
return O.none()
示例3: repo
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import _anon [as 别名]
def repo(self, *args, **kwargs):
if not args:
repos = Repository.visible(request).all()
tier = request.user.tier
repositories = sorted([r.serialize(
skip=['id', 'org_id', 'owner_id', 'linked_id'],
rel=[('owner.username', 'owner')],
editable=lambda r: r.editable(request))
for r in repos],
key=lambda l: l['name'])
return O._anon(repositories=repositories,
quota=dict(total=tier.total_repos,
user=tier.total_repos,
external=tier.external_repos == "True"))
else:
repo_name = args[0]
repo = Repository.visible(request).filter(
Repository.name == repo_name).first()
def get_creds(repo):
parents = [p for p in repo.parents
if p.org.name == request.user.org]
if parents:
return dict(auth_user=parents[0].credentials.auth_user)
else:
return {}
if repo.type == 'cloudrunner':
return O.repository(repo.serialize(
skip=['id', 'org_id', 'owner_id', 'linked_id'],
rel=[('owner.username', 'owner')],
editable=lambda r: r.editable(request)))
else:
if repo.editable(request):
return O.repository(repo.serialize(
skip=['id', 'org_id', 'owner_id', 'linked_id'],
rel=[('owner.username', 'owner'),
('linked', 'credentials', get_creds),
# ('credentials.auth_user', 'key'),
# ('credentials.auth_pass', 'secret'),
# ('credentials.auth_args', 'args')
],
editable=lambda r: True))
else:
return O.repository(**repo.serialize(
skip=['id', 'org_id', 'owner_id', 'linked_id'],
rel=[('owner.username', 'owner')],
editable=lambda r: True))
示例4: groups
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import _anon [as 别名]
def groups(self, name=None, *args):
def modifier(roles):
return [dict(as_user=role.as_user, servers=role.servers)
for role in roles]
if name:
group = Group.visible(request).filter(Group.name == name).first()
return O.group(group.serialize(
skip=['id', 'org_id'],
rel=[('roles', 'roles', modifier)]))
else:
groups = [u.serialize(
skip=['id', 'org_id'],
rel=[('roles', 'roles', modifier)])
for u in Group.visible(request).all()]
return O._anon(groups=groups,
quota=dict(allowed=request.user.tier.groups))
示例5: shares
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import _anon [as 别名]
def shares(self, profile, *args, **kwargs):
def nodes(p):
return []
if args:
sh = CloudShare.my(request, profile).filter(
CloudShare.name == args[0]).first()
return O.share(sh.serialize(
skip=['id', 'profile_id'],
rel=[('shared_nodes', 'nodes', nodes)]))
else:
profs = [p.serialize(
skip=['id', 'profile_id', 'password'],
rel=[('shared_nodes', 'nodes', nodes)])
for p in CloudShare.my(request, profile).all()]
return O._anon(shares=profs)