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 @@
Admin Pages
+
+ +
diff --git a/app/templates/admin/list_items.html b/app/templates/admin/list_items.html index da6354b..37817d3 100644 --- a/app/templates/admin/list_items.html +++ b/app/templates/admin/list_items.html @@ -10,32 +10,34 @@ {% include "admin/admin_tasks.html" %}
-
+
Deployments

+ - - + + {% for deploy in deployments %} - {% if deploy.enabled == True %}{% else %}{% endif %} + {% if deploy.enabled == False %}{% else %}{% endif %} + - + - - + + {% endfor %} @@ -45,28 +47,28 @@
-
+
Services

Owner Cube ID Alias CPU Mem HDDPrice per monthOwnerPricePeriod 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() }})
+ - - + {% for service in services %} - {% if service.enabled == True %}{% else %}{% endif %} + {% if service.enabled == False %}{% else %}{% endif %} + - - + {% endfor %} @@ -78,23 +80,23 @@
-
+
Domains

Owner Category DescriptionMonths PriceOwnerPeriod 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() }})
+ - {% for domain in domains %} - {% if domain.enabled == True %}{% else %}{% endif %} + {% if domain.enabled == False %}{% else %}{% endif %} + - {% endfor %} @@ -104,26 +106,26 @@
-
+
Addresses

Owner Name Expiry DateOwner
{{ domain.owner.email }} {{ domain.fqdn }} {{ domain.date_expire }}{{ domain.owner.email }}
+ - {% for address in addresses %} - {% if address.enabled == True %}{% else %}{% endif %} + {% if address.enabled == False %}{% else %}{% endif %} + - {% endfor %} diff --git a/app/templates/admin/list_transactions.html b/app/templates/admin/list_transactions.html index c51cf76..a49cf1a 100644 --- a/app/templates/admin/list_transactions.html +++ b/app/templates/admin/list_transactions.html @@ -6,7 +6,7 @@ {% include "admin/admin_tasks.html" %}
-
+
Transactions
diff --git a/app/templates/admin/list_users.html b/app/templates/admin/list_users.html index 4475218..7d892c7 100644 --- a/app/templates/admin/list_users.html +++ b/app/templates/admin/list_users.html @@ -5,7 +5,7 @@ {% include "admin/admin_tasks.html" %}
-
+
Users

Owner IP MAC Addr. Reverse DNSOwner
{{ address.owner.email }} {{ address.ip }} {{ address.mac }} {{ address.rdns }}{{ address.owner.email }}
diff --git a/app/templates/vmanager/dashboard.html b/app/templates/vmanager/dashboard.html index b00e5ad..79ebbd3 100644 --- a/app/templates/vmanager/dashboard.html +++ b/app/templates/vmanager/dashboard.html @@ -123,24 +123,35 @@ addEventListener("DOMContentLoaded", function() {
+ {% if inv_deployments != [] %}
Deployments

- - - - - - - - - - + + + + + + + + + + + {% for deploy in inv_deployments %} + {% if deploy.enabled == False %} + + + + + + + + {% else %} @@ -157,6 +168,7 @@ addEventListener("DOMContentLoaded", function() { {% endif %} + {% endif %} {% endfor %}
NameCPUMemHDDIPv4Control
NameCPUMemHDDIPv4Control
{% 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 %}
{% if status[deploy.machine_id] == 'running' %}{% else %}{% endif %}{{ deploy.machine_alias }} {{ deploy.machine_cpu }} Cores
@@ -165,7 +177,9 @@ addEventListener("DOMContentLoaded", function() {

+ {% endif %} + {% if inv_services != [] %}
Services
@@ -197,8 +211,10 @@ addEventListener("DOMContentLoaded", function() {
+ {% endif %} -
+ {% if inv_domains != [] %} +
Domains

@@ -225,8 +241,10 @@ addEventListener("DOMContentLoaded", function() {

+ {% endif %} -
+ {% if inv_addresses != [] %} +
Addresses

@@ -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('//') @@ -190,6 +197,7 @@ def command(cmd=None, vmid=0): # flash('Недостатъчно средства в сметката за тази операция') # return redirect(url_for('uinvoice.addfunds')) + #work with enabled deploys only result = current_user.inv_deployments.filter_by(enabled=True).order_by(Deployment.date_created.desc()) inventory = [] for invcls in result: @@ -197,7 +205,7 @@ def command(cmd=None, vmid=0): #checks if current user owns this vmid if not vmid in inventory: - current_app.logger.warning('[{}] Access violation with cube id: {}'.format(current_user.pid, vmid)) + current_app.logger.warning('[{}] Access violation with cube id: {}'.format(current_user.email, vmid)) #TODO: log ips else: db_result = contact_proxmaster({}, cmd, vmid)