diff --git a/app/auth/routes.py b/app/auth/routes.py index e0c1858..647916b 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -210,8 +210,7 @@ def password_reset_request(): 'auth/email/reset_password', user=user, token=token, next=request.args.get('next')) - flash('An email with instructions to reset your password has been ' - 'sent to you.') + flash('An email with instructions to reset your password has been sent to you.') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form) diff --git a/app/main/routes.py b/app/main/routes.py index d2ef055..4478cc1 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -96,6 +96,6 @@ def dashboard(): send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(cubeid), 'vmanager/email/adm_unreachable', user=current_user, cubeid=cubeid ) - current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list )) + #current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list )) return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions) diff --git a/app/models.py b/app/models.py index 4106eb2..57c9047 100644 --- a/app/models.py +++ b/app/models.py @@ -230,15 +230,15 @@ class Deployment(db.Model): warning = db.Column(db.Boolean, default=False) enabled = db.Column(db.Boolean, default=True) cancelled = db.Column(db.Boolean, default=False) - protected = db.Column(db.Boolean, default=False) #machines with this False will be autodeleted after the warning period is over. - connected = db.Column(db.Boolean, default=False) #requires: protected=True, indicate that a connection is enabled + machine_id = db.Column(db.BigInteger) #cubeid machine_alias = db.Column(db.String) #dns name machine_cpu = db.Column(db.Integer) machine_mem = db.Column(db.Integer) machine_hdd = db.Column(db.Integer) machine_addresses = db.relationship('Address', backref='deployments', lazy='dynamic') + discount = db.Column(db.Integer) class Service(db.Model): __tablename__ = 'services' diff --git a/app/smanager/routes.py b/app/smanager/routes.py index 27d1741..fc27056 100644 --- a/app/smanager/routes.py +++ b/app/smanager/routes.py @@ -65,7 +65,7 @@ def activate(itemid=0): db.session.add(transaction) db.session.commit() - owner.wallet = owner.wallet - price + owner.wallet = owner.wallet - total db.session.commit() if owner.is_administrator: diff --git a/app/static/images/serverroom.jpg b/app/static/images/serverroom.jpg new file mode 100644 index 0000000..282e979 Binary files /dev/null and b/app/static/images/serverroom.jpg differ diff --git a/app/templates/admin/list_deployments.html b/app/templates/admin/list_deployments.html index e76db00..8e04410 100644 --- a/app/templates/admin/list_deployments.html +++ b/app/templates/admin/list_deployments.html @@ -43,7 +43,11 @@ {{ deploy.machine_mem }} MB {{ deploy.machine_hdd }} GB {{ deploy.price }} + {% if deploy.date_last_charge == None %} + Never + {% else %} {{ moment(deploy.date_last_charge).format('lll') }} ({{ moment(deploy.date_last_charge).fromNow() }}) + {% endif %} {{ deploy.daysleft }} {% endfor %} diff --git a/app/templates/main/dashboard.html b/app/templates/main/dashboard.html index 6736f8b..19e6243 100644 --- a/app/templates/main/dashboard.html +++ b/app/templates/main/dashboard.html @@ -128,70 +128,79 @@ addEventListener("DOMContentLoaded", function() {
Deployments

- -

- - - - - - - - - - - - - - {% for deploy in inv_deployments %} - {% if deploy.enabled == False %} - - - - - - - + +
+ {% for deploy in inv_deployments %} +
+
- {% else %} - - {% endif %} - - - - - - - {% if deploy.warning == True %} - - {% else %} - - {% endif %} - - {% endif %} - {% endfor %} - -
- - - - - - - - -
{% if deploy.enabled == True %}{% else %}{% endif %} {{ deploy.machine_alias }}{{ deploy.machine_cpu }} {% if deploy.machine_cpu > 1 %}cores{% else %}core{% endif %}{{ deploy.machine_mem }} MB{{ deploy.machine_hdd }} GB
{% if deploy.protected == True %}{% else %}{% endif %}{{ deploy.machine_alias }}{% for addr in deploy.machine_addresses %} {% endfor %}{{ deploy.machine_cpu }} {% if deploy.machine_cpu > 1 %}cores{% else %}core{% endif %}{{ deploy.machine_mem }} MB{{ deploy.machine_hdd }} GB{% if status[deploy.machine_id] == 'running' %} + ok + {% endif %} + {% if deploy.protected == True %}{% endif %} {% if status[deploy.machine_id] == 'running' %}{% else %}{% endif %}{{ deploy.machine_alias }} + + +
+
+ + +
+
+

+ {% if status[deploy.machine_id] == 'running' %} {% else %} {% endif %} - {% if status[deploy.machine_id] == 'running' %}{% endif %}

{{ deploy.daysleft }} day(s)
+ {% if status[deploy.machine_id] == 'running' %}{% endif %} +

+
+
+

+ CPU {{ deploy.machine_cpu }} {% if deploy.machine_cpu > 1 %}cores{% else %}core{% endif %}
+

+ Memory {{ deploy.machine_mem }} MB:
+

+ {% for addr in deploy.machine_addresses %} + Network {{ addr.ip }}:
+

+ {% endfor %} + Hard Disk IOPS: {{ deploy.machine_hdd }} GB
+
+

+
+
+

+ {% if deploy.enabled == False %} + + {% endif %} + {% if deploy.warning == True %} + + {% else %} + Time Left: {{ deploy.daysleft }} day(s) + {% endif %} +

+
+
+ + + + {% endfor %} + + + diff --git a/app/templates/main/index.html b/app/templates/main/index.html index a689176..42e61e4 100644 --- a/app/templates/main/index.html +++ b/app/templates/main/index.html @@ -30,7 +30,7 @@ {% block scripts %} {{ super() }} - + {% endblock %} @@ -34,7 +43,7 @@ function calculateTotal()
Activate deployment {{ deploy.machine_alias }}
-
+

CPU: {{ deploy.machine_cpu }} cores
Memory: {{ deploy.machine_mem }} MB
@@ -44,6 +53,9 @@ Storage: {{ deploy.machine_hdd }} GB
{{ error }}
{% endfor %} ---
+{% if deploy.discount != 0 %} +
Discount -{{ deploy.discount }}%: {{ discount }} {{ currency }}
+{% endif %}
Previous Period: {{ total }} {{ currency }}

@@ -56,5 +68,7 @@ Storage: {{ deploy.machine_hdd }} GB
+ + {% endblock %} diff --git a/app/vmanager/routes.py b/app/vmanager/routes.py index 40ff50b..ed198b8 100644 --- a/app/vmanager/routes.py +++ b/app/vmanager/routes.py @@ -91,8 +91,11 @@ def activate(itemid=0): cpu_cost = deploy.machine_cpu * current_app.config['CPU_RATIO'] mem_cost = ( deploy.machine_mem / 1024 ) * current_app.config['MEM_RATIO'] hdd_cost = deploy.machine_hdd * current_app.config['HDD_RATIO'] - ppm = round(cpu_cost + mem_cost + hdd_cost) + ppm = cpu_cost + mem_cost + hdd_cost + discount = round(( ppm * deploy.discount ) / 100) + ppm = round(ppm - discount) + #default period = 1 for virgin deployments if deploy.period is None: form = ActivateForm(period=1) total = ppm * 1 @@ -129,7 +132,7 @@ def activate(itemid=0): return redirect(url_for('admin.list_deployments')) else: return redirect(url_for('main.dashboard')) - return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, ppm=ppm, total=total, currency=owner.currency) + return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, ppm=ppm, discount=discount, total=total, currency=owner.currency) @vmanager.route('//') diff --git a/manage.py b/manage.py index fb99b28..06400cb 100644 --- a/manage.py +++ b/manage.py @@ -113,9 +113,6 @@ def autowarn(): print('Deployment "' + deploy.machine_alias + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) deploy.warning = True db.session.commit() - else: - deploy.warning = False - db.session.commit() services_ena = Service.query.filter_by(cancelled=False).filter_by(enabled=True).all() for service in services_ena: @@ -129,9 +126,6 @@ def autowarn(): print('Service "' + service.description + '" is ' + str(daysleft.days) + ' days until expiration. Last charged: ' + lastcharge.strftime('%c') + ' expiry date: ' + expiry.strftime('%c')) service.warning = True db.session.commit() - else: - service.warning = False - db.session.commit() domains_ena = Domain.query.filter_by(cancelled=False).filter_by(enabled=True).all() for domain in domains_ena: @@ -139,8 +133,7 @@ def autowarn(): daysleft = expiry - today domain.daysleft = daysleft.days + 1 db.session.commit() - - warndays = service.period * 5 + warndays = domain.period * 5 if daysleft.days < warndays: print('Domain "' + domain.fqdn + '" is ' + str(daysleft.days)+ ' days until expiration. Expiry date: ' + expiry.strftime('%c')) domain.warning = True