Your account does not have sufficient funds to create a Capsul
This commit is contained in:
parent
2e6291d87c
commit
5df06dc1b3
@ -83,6 +83,7 @@ def create():
|
|||||||
vm_sizes = get_model().vm_sizes_dict()
|
vm_sizes = get_model().vm_sizes_dict()
|
||||||
operating_systems = get_model().operating_systems_dict()
|
operating_systems = get_model().operating_systems_dict()
|
||||||
ssh_public_keys = get_model().list_ssh_public_keys_for_account(session["account"])
|
ssh_public_keys = get_model().list_ssh_public_keys_for_account(session["account"])
|
||||||
|
account_balance = get_account_balance()
|
||||||
errors = list()
|
errors = list()
|
||||||
created_os = None
|
created_os = None
|
||||||
|
|
||||||
@ -139,7 +140,12 @@ def create():
|
|||||||
ssh_public_keys=list(map(lambda x: x["content"], posted_keys))
|
ssh_public_keys=list(map(lambda x: x["content"], posted_keys))
|
||||||
)
|
)
|
||||||
created_os = os
|
created_os = os
|
||||||
|
|
||||||
|
affordable_vm_sizes = dict()
|
||||||
|
for key, vm_size in vm_sizes.items():
|
||||||
|
if vm_size["dollars_per_month"] < account_balance:
|
||||||
|
affordable_vm_sizes[key] = vm_size
|
||||||
|
|
||||||
for error in errors:
|
for error in errors:
|
||||||
flash(error)
|
flash(error)
|
||||||
|
|
||||||
@ -148,9 +154,10 @@ def create():
|
|||||||
created_os=created_os,
|
created_os=created_os,
|
||||||
ssh_public_keys=ssh_public_keys,
|
ssh_public_keys=ssh_public_keys,
|
||||||
ssh_public_key_count=len(ssh_public_keys),
|
ssh_public_key_count=len(ssh_public_keys),
|
||||||
has_ssh_public_keys=len(ssh_public_keys) > 0,
|
no_ssh_public_keys=len(ssh_public_keys) == 0,
|
||||||
operating_systems=operating_systems,
|
operating_systems=operating_systems,
|
||||||
vm_sizes=vm_sizes
|
cant_afford=len(affordable_vm_sizes) == 0,
|
||||||
|
vm_sizes=affordable_vm_sizes
|
||||||
)
|
)
|
||||||
|
|
||||||
@bp.route("/ssh", methods=("GET", "POST"))
|
@bp.route("/ssh", methods=("GET", "POST"))
|
||||||
@ -208,26 +215,26 @@ def get_payments():
|
|||||||
return g.user_payments
|
return g.user_payments
|
||||||
|
|
||||||
def get_account_balance():
|
def get_account_balance():
|
||||||
|
|
||||||
|
|
||||||
average_number_of_days_in_a_month = 30.44
|
average_number_of_days_in_a_month = 30.44
|
||||||
|
|
||||||
vm_cost_dollars = 0.0
|
vm_cost_dollars = 0.0
|
||||||
for vm in get_vms():
|
for vm in get_vms():
|
||||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.now()
|
end_datetime = vm["deleted"] if vm["deleted"] else datetime.now()
|
||||||
vm_months = ( end_datetime - vm["created"] ).days / average_number_of_days_in_a_month
|
vm_months = ( end_datetime - vm["created"] ).days / average_number_of_days_in_a_month
|
||||||
vm_cost_dollars += vm_months * vm["dollars_per_month"]
|
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
|
||||||
|
|
||||||
payment_total = sum(map(lambda x: x["dollars"], get_payments()))
|
|
||||||
|
|
||||||
|
payment_dollars_total = sum(map(lambda x: x["dollars"], get_payments()))
|
||||||
|
|
||||||
|
return payment_dollars_total - vm_cost_dollars
|
||||||
|
|
||||||
@bp.route("/account-balance")
|
@bp.route("/account-balance")
|
||||||
@account_required
|
@account_required
|
||||||
def account_balance():
|
def account_balance():
|
||||||
errors = list()
|
errors = list()
|
||||||
payments = get_payments()
|
payments = get_payments()
|
||||||
|
account_balance = get_account_balance()
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"account-balance.html",
|
||||||
return render_template("account-balance.html")
|
payments=payments, has_payments=len(payments)>0, account_balance=account_balance
|
||||||
|
)
|
@ -142,12 +142,12 @@ class DBModel:
|
|||||||
|
|
||||||
def list_payments_for_account(self, email):
|
def list_payments_for_account(self, email):
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
SELECT payments.id, payments.dollars, payments.created
|
SELECT payments.dollars, payments.created
|
||||||
FROM payments WHERE payments.email = %s""",
|
FROM payments WHERE payments.email = %s""",
|
||||||
(email, )
|
(email, )
|
||||||
)
|
)
|
||||||
return list(map(
|
return list(map(
|
||||||
lambda x: dict(id=x[0], dollars=x[1], created=x[2]),
|
lambda x: dict(dollars=x[0], created=x[1]),
|
||||||
self.cursor.fetchall()
|
self.cursor.fetchall()
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -19,57 +19,66 @@
|
|||||||
may take an extra-long time to obtain an IP address, like up to 10 minutes. Be patient.
|
may take an extra-long time to obtain an IP address, like up to 10 minutes. Be patient.
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if has_ssh_public_keys %}
|
{% if cant_afford %}
|
||||||
<pre>
|
<p>
|
||||||
CAPSUL SIZES
|
Your account does not have sufficient funds to create a Capsul.
|
||||||
============
|
(Must be funded enough to last at least one month at creation time).
|
||||||
type monthly cpus mem ssd net*
|
</p>
|
||||||
----- ------- ---- --- --- ---
|
<p>You must <a href="/console/account-balance">add funds to your account</a> before you can create a Capsul.</p>
|
||||||
f1-s $5.33 1 512M 25G .5TB
|
{% else %}
|
||||||
f1-m $7.16 1 1024M 25G 1TB
|
{% if no_ssh_public_keys %}
|
||||||
f1-l $8.92 1 2048M 25G 2TB
|
<p>You don't have any ssh public keys yet.</p>
|
||||||
f1-x $16.16 2 4096M 25G 4TB
|
<p>You must <a href="/console/ssh">upload one</a> before you can create a Capsul.</p>
|
||||||
f1-xx $29.66 4 8096M 25G 8TB
|
{% else %}
|
||||||
f1-xxx $57.58 8 16G 25G 16TB
|
<pre>
|
||||||
|
CAPSUL SIZES
|
||||||
|
============
|
||||||
|
type monthly cpus mem ssd net*
|
||||||
|
----- ------- ---- --- --- ---
|
||||||
|
f1-s $5.33 1 512M 25G .5TB
|
||||||
|
f1-m $7.16 1 1024M 25G 1TB
|
||||||
|
f1-l $8.92 1 2048M 25G 2TB
|
||||||
|
f1-x $16.16 2 4096M 25G 4TB
|
||||||
|
f1-xx $29.66 4 8096M 25G 8TB
|
||||||
|
f1-xxx $57.58 8 16G 25G 16TB
|
||||||
|
|
||||||
|
* net is calculated as a per-month average
|
||||||
|
* all VMs come standard with one public IPv4 addr</pre>
|
||||||
|
|
||||||
* net is calculated as a per-month average
|
<form method="post">
|
||||||
* all VMs come standard with one public IPv4 addr</pre>
|
<div class="row justify-start">
|
||||||
|
<label class="align" for="size">Capsul Size</label>
|
||||||
<form method="post">
|
<select id="size" name="size">
|
||||||
<div class="row justify-start">
|
{% for size in vm_sizes.keys() %}<option value="{{ size }}">{{ size }}</option>{% endfor %}
|
||||||
<label class="align" for="size">Capsul Size</label>
|
</select>
|
||||||
<select id="size" name="size">
|
|
||||||
{% for size in vm_sizes.keys() %}<option value="{{ size }}">{{ size }}</option>{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="row justify-start">
|
|
||||||
<label class="align" for="os">Operating System</label>
|
|
||||||
<select id="os" name="os">
|
|
||||||
{% for os_id, os in operating_systems.items() %}
|
|
||||||
<option value="{{ os_id }}">{{ os.description }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="row justify-start">
|
|
||||||
<input type="hidden" name="ssh_public_key_count" value="{{ ssh_public_key_count}}"/>
|
|
||||||
<label class="align" for="ssh_keys">SSH Public Keys</label>
|
|
||||||
<div id="ssh_keys">
|
|
||||||
{% for key in ssh_public_keys %}
|
|
||||||
<label for="ssh_key_{{ loop.index - 1 }}">
|
|
||||||
<input type="checkbox" id="ssh_key_{{ loop.index - 1 }}" name="ssh_key_{{ loop.index - 1 }}" value="{{ key['name'] }}"/>
|
|
||||||
{{ key['name'] }}
|
|
||||||
</label>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row justify-start">
|
||||||
<div class="row justify-end">
|
<label class="align" for="os">Operating System</label>
|
||||||
<input type="submit" value="Create">
|
<select id="os" name="os">
|
||||||
</div>
|
{% for os_id, os in operating_systems.items() %}
|
||||||
</form>
|
<option value="{{ os_id }}">{{ os.description }}</option>
|
||||||
{% else %}
|
{% endfor %}
|
||||||
<p>You don't have any ssh public keys yet.</p>
|
</select>
|
||||||
<p>You must <a href="/console/ssh">upload one</a> before you can create a Capsul.</p>
|
</div>
|
||||||
|
<div class="row justify-start">
|
||||||
|
<input type="hidden" name="ssh_public_key_count" value="{{ ssh_public_key_count}}"/>
|
||||||
|
<label class="align" for="ssh_keys">SSH Public Keys</label>
|
||||||
|
<div id="ssh_keys">
|
||||||
|
{% for key in ssh_public_keys %}
|
||||||
|
<label for="ssh_key_{{ loop.index - 1 }}">
|
||||||
|
<input type="checkbox" id="ssh_key_{{ loop.index - 1 }}" name="ssh_key_{{ loop.index - 1 }}" value="{{ key['name'] }}"/>
|
||||||
|
{{ key['name'] }}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row justify-end">
|
||||||
|
<input type="submit" value="Create">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -77,7 +86,7 @@ f1-xxx $57.58 8 16G 25G 16TB
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block subcontent %}
|
{% block subcontent %}
|
||||||
{% if ssh_public_keys[0] is defined %}
|
{% if not cant_afford and not no_ssh_public_keys %}
|
||||||
<p>
|
<p>
|
||||||
Using our services implies that you agree to our terms of service & privacy policy.
|
Using our services implies that you agree to our terms of service & privacy policy.
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user