41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import datetime
|
|
|
|
from flask import Blueprint
|
|
from flask import current_app
|
|
from flask import jsonify
|
|
from flask import request
|
|
from flask import session
|
|
from nanoid import generate
|
|
|
|
from capsulflask.auth import account_required
|
|
from capsulflask.db import get_model
|
|
|
|
bp = Blueprint("publicapi", __name__, url_prefix="/api")
|
|
|
|
@bp.route("/capsul/create", methods=["POST"])
|
|
@account_required
|
|
def capsul_create():
|
|
email = session["account"]
|
|
|
|
from .console import _create,get_account_balance, get_payments, get_vms
|
|
|
|
vm_sizes = get_model().vm_sizes_dict()
|
|
operating_systems = get_model().operating_systems_dict()
|
|
public_keys_for_account = get_model().list_ssh_public_keys_for_account(session["account"])
|
|
account_balance = get_account_balance(get_vms(), get_payments(), datetime.datetime.utcnow())
|
|
capacity_avaliable = current_app.config["HUB_MODEL"].capacity_avaliable(512*1024*1024)
|
|
|
|
request.json['ssh_authorized_key_count'] = 1
|
|
|
|
id, errors = _create(
|
|
vm_sizes,
|
|
operating_systems,
|
|
public_keys_for_account,
|
|
request.json)
|
|
|
|
if id is not None:
|
|
return jsonify(
|
|
id=id,
|
|
)
|
|
return jsonify(errors=errors)
|