def update_flavor(request, flavor_id): if request.method == "POST": token = request.session.get('passToken') auth_url = request.session.get("auth_url") data = json.loads(request.POST.get("data")) try: nova = NovaRestAPI(auth_url, token) flavor = nova.update_flavor(flavor_id, {"flavor": data.get("flavor")}) if flavor.get("success"): if data.get("flavor_access"): add_project = data["flavor_access"].get("add_project") remove_project = data["flavor_access"].get( "remove_project") if add_project: result = nova.add_flavor_access(flavor_id, add_project) if result.get("error"): flavor["error"] = result["error"] if remove_project: result = nova.remove_flavor_access( flavor_id, remove_project) if result.get("error"): if flavor.get("error"): flavor["error"]["message"] += result["error"][ "message"] else: flavor["error"] = result["error"] except Unauthorized as e: request.session["error"] = { "title": e.message, "message": e.details } flavor = {"error": request.session.get("error")} return JsonResponse(flavor)
def create_flavor(request): if request.method == "POST": token = request.session.get('passToken') auth_url = request.session.get("auth_url") data = json.loads(request.POST.get("data")) try: nova = NovaRestAPI(auth_url, token) flavor = nova.create_flavor({"flavor": data.get("flavor")}) if flavor.get("success"): if data.get("flavor_access"): result = nova.add_flavor_access( flavor.get("success").get("flavor").get("id"), data["flavor_access"]) if result.get("error"): flavor["error"] = { "title": "flavor access Fail", "message": "Flavor는 생성되었으나 access 설정에 실패하였습니다." } except Unauthorized as e: request.session["error"] = { "title": e.message, "message": e.details } flavor = {"error": request.session.get("error")} return JsonResponse(flavor)