本文整理汇总了Python中marathon.MarathonClient.create_app_by_json方法的典型用法代码示例。如果您正苦于以下问题:Python MarathonClient.create_app_by_json方法的具体用法?Python MarathonClient.create_app_by_json怎么用?Python MarathonClient.create_app_by_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marathon.MarathonClient
的用法示例。
在下文中一共展示了MarathonClient.create_app_by_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_app
# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app_by_json [as 别名]
def new_app(request):
data = {}
if request.method == "POST":
data["msg"] = "Post"
post_params = {}
for key in request.POST:
if key.startswith("filehidden"):
fkey = key[11:]
if request.FILES.get(fkey, None):
post_file = request.FILES[fkey]
file_content = ""
for chunk in post_file.chunks():
file_content += chunk.decode("utf8")
post_params[fkey] = convert(file_content)
else:
post_params[fkey] = request.POST[key]
else:
post_params[key] = request.POST[key]
template = Template.objects.get(pk=post_params["template_id"])
content = template.content % post_params
data["content"] = content
mc = MarathonClient("http://{}:{}".format(settings.MARATHON["host"], settings.MARATHON["port"]))
try:
mc.create_app_by_json(content)
data["result"] = "Success"
except Exception as e:
data["result"] = str(e)
templates = Template.objects.filter(type="marathon").all()
for template in templates:
template.params = template.param_set.order_by("id")
data["templates"] = templates
return render(request, "marathon_mgmt/new_app.html", data)
示例2: new_app
# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app_by_json [as 别名]
def new_app(request, type):
data = {}
if request.method == 'POST':
data['msg'] = "Post"
post_params = {}
for key in request.POST:
if key.startswith("filehidden"):
fkey = key[11:]
if(request.FILES.get(fkey, None)):
post_file = request.FILES[fkey]
file_content=""
for chunk in post_file.chunks():
file_content += chunk.decode("utf8")
post_params[fkey] = convert(file_content)
else:
post_params[fkey] = request.POST[key]
else:
post_params[key] = request.POST[key]
template = Template.objects.get(pk=post_params['template_id'])
content = template.content%post_params
data['content'] = content
mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port']))
try:
if(type == "app"):
mc.create_app_by_json(content)
elif(type == "group"):
mc.create_group(content)
data['result'] = "Success"
except Exception as e:
data['result'] = str(e)
if(type == "app"):
data['type'] = "Application"
templates = Template.objects.filter(type="marathon-app").order_by('name').all()
elif(type == "group"):
data['type'] = "Group"
templates = Template.objects.filter(type="marathon-group").order_by('name').all()
for template in templates:
template.params = template.param_set.order_by('id')
data['templates'] = templates
return render(request, 'marathon_mgmt/new_app.html', data)