diff --git a/app/admin/routes.py b/app/admin/routes.py index b35b963..e45c872 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -75,30 +75,38 @@ def charge(user_pid=0): @admin_required def dashboard(user_pid=0): cuser = User.query.filter_by(pid=user_pid).first() - inv_deployments = cuser.inv_deployments.filter_by(enabled=True).order_by(Deployment.date_created.desc()) + + inv_deployments = cuser.inv_deployments.order_by(Deployment.date_created.desc()).all() inv_deploycubeids = [] inv_deployments_list = [] - for invcls in inv_deployments: - inv_deploycubeids.extend([invcls.machine_id]) - inv_deployments_list.extend([invcls.machine_alias]) - - inv_services = cuser.inv_services.filter_by(enabled=True).order_by(Service.date_last_charge.asc()) - inv_services_list = [] - for invcls in inv_services: - inv_services_list.extend([invcls.description]) - - inv_domains = cuser.inv_domains.filter_by(enabled=True).order_by(Domain.date_created.desc()) + for invcls in inv_deployments: + if invcls.user_id == cuser.pid and invcls.enabled == True: + inv_deploycubeids.extend([invcls.machine_id]) + inv_deployments_list.extend([invcls.machine_alias]) + + inv_services = cuser.inv_services.order_by(Service.date_last_charge.asc()).all() + inv_services_list = [] + for invcls in inv_services: + if invcls.user_id == cuser.pid and invcls.enabled == True: + inv_services_list.extend([invcls.description]) + + inv_domains = cuser.inv_domains.order_by(Domain.date_created.desc()).all() inv_domains_list = [] for invcls in inv_domains: - if invcls.user_id == cuser.pid and invcls.enabled == True: + if invcls.user_id == cuser.pid and invcls.enabled == True: inv_domains_list.extend([invcls.fqdn]) - inv_addresses = cuser.inv_addresses.filter_by(enabled=True).order_by(Address.ip.asc()) + inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all() inv_addresses_list = [] for invcls in inv_addresses: if invcls.user_id == cuser.pid and invcls.enabled == True: inv_addresses_list.extend([invcls.ip]) + sys_regions = Region.query.all() + regions = {} + for region in sys_regions: + regions[region.pid] = region.description + #extract rrd and status from the deployments rrd = {} statuses = {} @@ -122,7 +130,7 @@ def dashboard(user_pid=0): send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(cubeid), 'vmanager/email/adm_unreachable', user=cuser, cubeid=cubeid ) current_app.logger.info('[ADMIN] {} deployments: {}, services: {}, domains: {}, services: {}'.format(cuser.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list )) - return render_template('vmanager/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses) + return render_template('vmanager/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions) @admin.route("/listtransactions", methods=['GET']) @login_required diff --git a/app/models.py b/app/models.py index f1e7ebc..bc59e62 100644 --- a/app/models.py +++ b/app/models.py @@ -244,6 +244,7 @@ class Deployment(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow) date_last_charge = db.Column(db.DateTime) + period = db.Column(db.Integer) enabled = db.Column(db.Boolean, default=False) machine_id = db.Column(db.BigInteger) #cubeid diff --git a/app/templates/admin/admin_tasks.html b/app/templates/admin/admin_tasks.html index 79d2261..7df91ec 100644 --- a/app/templates/admin/admin_tasks.html +++ b/app/templates/admin/admin_tasks.html @@ -2,9 +2,12 @@
Owner | Cube ID | Alias | CPU | Mem | HDD | -Price per month | -Owner | +Price | +Period | Last Charged | |
---|---|---|---|---|---|---|---|---|---|---|---|
{{ deploy.owner.email }} | {{ deploy.machine_id }} | {{ deploy.machine_alias }} | -{{ deploy.machine_cpu }} c. | +{{ deploy.machine_cpu }} | {{ deploy.machine_mem }} MB | {{ deploy.machine_hdd }} GB | -{{ deploy.price }} | -{{ deploy.owner.email }} | +{{ deploy.price }} | +{{ deploy.period }} | {{ moment(deploy.date_last_charge).format('lll') }} ({{ moment(deploy.date_last_charge).fromNow() }}) | {% endfor %}
Owner | Category | Description | -Months | Price | -Owner | +Period | Last Charged |
---|---|---|---|---|---|---|---|
{{ service.owner.email }} | {{ service.category }} | {{ service.description }} | -{{ service.period }} | {{ service.price }} | -{{ service.owner.email }} | +{{ service.period }} | {{ moment(service.date_last_charge).format('ll') }} ({{ moment(service.date_last_charge).fromNow() }}) |
Owner | Name | Expiry Date | -Owner | |||
---|---|---|---|---|---|---|
{{ domain.owner.email }} | {{ domain.fqdn }} | {{ domain.date_expire }} | -{{ domain.owner.email }} |
Owner | IP | MAC Addr. | Reverse DNS | -Owner | ||
---|---|---|---|---|---|---|
{{ address.owner.email }} | {{ address.ip }} | {{ address.mac }} | {{ address.rdns }} | -{{ address.owner.email }} | {% endfor %}
Name | -CPU | -Mem | -HDD | -IPv4 | -Control | -- |
---|---|---|---|---|---|---|
Name | +CPU | +Mem | +HDD | +IPv4 | +Control | ++ |
{% if status[deploy.machine_id] == 'running' %}{% else %}{% endif %}{{ deploy.machine_alias }} | +{{ deploy.machine_cpu }} Cores | +{{ deploy.machine_mem }} MB | +{{ deploy.machine_hdd }} GB | +{% for addr in deploy.machine_addresses %} {{ addr.ip }} {% endfor %} |
+
+ {% else %}
||
{% if status[deploy.machine_id] == 'running' %}{% else %}{% endif %}{{ deploy.machine_alias }} | {{ deploy.machine_cpu }} Cores | @@ -157,6 +168,7 @@ addEventListener("DOMContentLoaded", function() { {% endif %}
@@ -225,8 +241,10 @@ addEventListener("DOMContentLoaded", function() {
@@ -235,6 +253,7 @@ addEventListener("DOMContentLoaded", function() {
IP
+ Region
MAC Addr.
Reverse DNS
Control
@@ -243,6 +262,7 @@ addEventListener("DOMContentLoaded", function() {
{% for address in inv_addresses %}
{{ address.ip }}
+ {{ region[address.region_id] }}
{{ address.mac }}
{{ address.rdns }}
soon...
@@ -255,6 +275,7 @@ addEventListener("DOMContentLoaded", function() {
+ {% endif %}
diff --git a/app/vmanager/routes.py b/app/vmanager/routes.py
index 50ee9bc..55f071d 100644
--- a/app/vmanager/routes.py
+++ b/app/vmanager/routes.py
@@ -124,30 +124,37 @@ def deploy(product_id=None):
def dashboard():
cuser = current_user
- inv_deployments = cuser.inv_deployments.filter_by(enabled=True).order_by(Deployment.date_created.desc())
+ inv_deployments = cuser.inv_deployments.order_by(Deployment.date_created.desc()).all()
inv_deploycubeids = []
inv_deployments_list = []
- for invcls in inv_deployments:
- inv_deploycubeids.extend([invcls.machine_id])
- inv_deployments_list.extend([invcls.machine_alias])
+ for invcls in inv_deployments:
+ if invcls.user_id == cuser.pid and invcls.enabled == True:
+ inv_deploycubeids.extend([invcls.machine_id])
+ inv_deployments_list.extend([invcls.machine_alias])
+
+ inv_services = cuser.inv_services.order_by(Service.date_last_charge.asc()).all()
+ inv_services_list = []
+ for invcls in inv_services:
+ if invcls.user_id == cuser.pid and invcls.enabled == True:
+ inv_services_list.extend([invcls.description])
- inv_services = cuser.inv_services.filter_by(enabled=True).order_by(Service.date_last_charge.asc())
- inv_services_list = []
- for invcls in inv_services:
- inv_services_list.extend([invcls.description])
-
- inv_domains = cuser.inv_domains.filter_by(enabled=True).order_by(Domain.date_created.desc())
+ inv_domains = cuser.inv_domains.order_by(Domain.date_created.desc()).all()
inv_domains_list = []
- for invcls in inv_domains:
- if invcls.user_id == cuser.pid and invcls.enabled == True:
+ for invcls in inv_domains:
+ if invcls.user_id == cuser.pid and invcls.enabled == True:
inv_domains_list.extend([invcls.fqdn])
- inv_addresses = cuser.inv_addresses.filter_by(enabled=True).order_by(Address.ip.asc())
+ inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
inv_addresses_list = []
for invcls in inv_addresses:
if invcls.user_id == cuser.pid and invcls.enabled == True:
inv_addresses_list.extend([invcls.ip])
+ sys_regions = Region.query.all()
+ regions = {}
+ for region in sys_regions:
+ regions[region.pid] = region.description
+
#extract rrd and status from the deployments
rrd = {}
statuses = {}
@@ -173,8 +180,8 @@ 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('[{}] deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list ))
- return render_template('vmanager/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses)
+ 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('vmanager/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)
@vmanager.route('/