forked from 3wordchant/capsul-flask
Fix up API
This commit is contained in:
parent
6dbae94bd6
commit
cffa40c0e3
@ -248,7 +248,7 @@ def _create(vm_sizes, operating_systems, public_keys_for_account, affordable_vm_
|
||||
template_image_file_name=operating_systems[os]['template_image_file_name'],
|
||||
vcpus=vm_sizes[size]['vcpus'],
|
||||
memory_mb=vm_sizes[size]['memory_mb'],
|
||||
ssh_authorized_keys=list(map(lambda x: x["content"], posted_keys))
|
||||
ssh_authorized_keys=posted_keys
|
||||
)
|
||||
return id, errors
|
||||
|
||||
|
@ -44,6 +44,7 @@ class MockHub(VirtualizationInterface):
|
||||
validate_capsul_id(id)
|
||||
current_app.logger.info(f"mock create: {id} for {email}")
|
||||
sleep(1)
|
||||
|
||||
get_model().create_vm(
|
||||
email=email,
|
||||
id=id,
|
||||
|
@ -17,7 +17,7 @@ bp = Blueprint("publicapi", __name__, url_prefix="/api")
|
||||
def capsul_create():
|
||||
email = session["account"]
|
||||
|
||||
from .console import _create,get_account_balance, get_payments, get_vms
|
||||
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()
|
||||
@ -25,12 +25,21 @@ def capsul_create():
|
||||
account_balance = get_account_balance(get_vms(), get_payments(), datetime.datetime.utcnow())
|
||||
capacity_avaliable = current_app.config["HUB_MODEL"].capacity_avaliable(512*1024*1024)
|
||||
|
||||
affordable_vm_sizes = dict()
|
||||
for key, vm_size in vm_sizes.items():
|
||||
# if a user deposits $7.50 and then creates an f1-s vm which costs 7.50 a month,
|
||||
# then they have to delete the vm and re-create it, they will not be able to, they will have to pay again.
|
||||
# so for UX it makes a lot of sense to give a small margin of 25 cents for usability sake
|
||||
if vm_size["dollars_per_month"] <= account_balance+0.25:
|
||||
affordable_vm_sizes[key] = vm_size
|
||||
|
||||
request.json['ssh_authorized_key_count'] = 1
|
||||
|
||||
id, errors = _create(
|
||||
vm_sizes,
|
||||
operating_systems,
|
||||
public_keys_for_account,
|
||||
affordable_vm_sizes,
|
||||
request.json)
|
||||
|
||||
if id is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user