From ca09e02f70501000a433b53ddd4616005b0722e9 Mon Sep 17 00:00:00 2001 From: deflax Date: Wed, 7 Jun 2017 18:04:27 +0300 Subject: [PATCH] simplify admin page --- app/admin/routes.py | 12 +- app/models.py | 20 +- app/templates/admin/dashboard.html | 255 -------------------------- app/templates/vmanager/dashboard.html | 31 +++- app/vmanager/routes.py | 10 +- manage.py | 3 - 6 files changed, 53 insertions(+), 278 deletions(-) delete mode 100644 app/templates/admin/dashboard.html diff --git a/app/admin/routes.py b/app/admin/routes.py index d91cbdc..934264f 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -32,10 +32,10 @@ def after_request(response): @login_required @admin_required def index(): - alldeployments = Deployment.query.order_by(Deployment.date_created.desc()).all() - alldomains = Domain.query.order_by(Domain.date_created.desc()).all() - allservices = Service.query.order_by(Service.date_created.desc()).all() - alladdresses = Address.query.order_by(Address.date_assigned.desc()).all() + alldeployments = Deployment.query.order_by(Deployment.user_id.desc()).all() + alldomains = Domain.query.order_by(Domain.user_id.desc()).all() + allservices = Service.query.order_by(Service.user_id.desc()).all() + alladdresses = Address.query.order_by(Address.user_id.asc()).all() return render_template('admin/index.html', deployments=alldeployments, domains=alldomains, services=allservices, addresses=alladdresses) @admin.route("/users", methods=['GET']) @@ -84,7 +84,7 @@ def dashboard(user_pid=0): if invcls.user_id == cuser.pid and invcls.enabled == True: inv_domains.extend([invcls.fqdn]) - addresses = cuser.inv_addresses.order_by(Address.date_assigned.desc()).all() + addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all() inv_addresses = [] for invcls in addresses: if invcls.user_id == cuser.pid and invcls.enabled == True: @@ -114,6 +114,6 @@ def dashboard(user_pid=0): 'vmanager/email/adm_unreachable', user=cuser, cubeid=cubeid ) current_app.logger.info('[{}] deployments: {}, domains: {}, services: {}'.format(cuser.email, inv_deploynames, inv_services, inv_domains, inv_addresses )) - return render_template('admin/dashboard.html', rrd=rrd, status=statuses, inv_deployments=deployments, inv_services=services, inv_domains=domains, inv_addresses=addresses) + return render_template('vmanager/dashboard.html', rrd=rrd, status=statuses, inv_deployments=deployments, inv_services=services, inv_domains=domains, inv_addresses=addresses) diff --git a/app/models.py b/app/models.py index eff2db6..437220a 100644 --- a/app/models.py +++ b/app/models.py @@ -7,11 +7,12 @@ from app.exceptions import ValidationError from . import db, lm import os +import random import base64 import hashlib +import json from decimal import Decimal from datetime import date, time, datetime, timedelta -import json from sortedcontainers import SortedDict import requests import onetimepass @@ -249,6 +250,7 @@ class Deployment(db.Model): 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') def charge(): result = Deployment.query.all() @@ -288,10 +290,24 @@ class Address(db.Model): date_assigned = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK region_id = db.Column(db.Integer, db.ForeignKey('regions.pid')) #FK + deploy_id = db.Column(db.Integer, db.ForeignKey('deployments.pid')) #FK + ip = db.Column(db.String(64)) rdns = db.Column(db.String(256)) macaddr = db.Column(db.String(128)) - reserved = db.Column(db.Boolean, default=False) + reserved = db.Column(db.Boolean, default=False) #this ip SHOULD NOT be listed as available to assign even if its not currently owned by anyone + + def __init__(self): + if self.macaddr is None: + self.macaddr = self.genmac() + + def genmac(self): + alladdr = Address.query.all() + + mac = [ random.randint(0, 255) for x in range(0, 6) ] + mac[0] = (mac[0] & 0xfc) | 0x02 + mac = ''.join([ '{0:02x}'.format(x) for x in mac ]) + return mac class Domain(db.Model): __tablename__ = 'domains' diff --git a/app/templates/admin/dashboard.html b/app/templates/admin/dashboard.html deleted file mode 100644 index ef0928a..0000000 --- a/app/templates/admin/dashboard.html +++ /dev/null @@ -1,255 +0,0 @@ -{% extends "base.html" %} - -{% block styles %} -{{ super() }} - - - -{% endblock %} - -{% block scripts %} -{{ super() }} - - -{% endblock %} - -{% block page_content %} -
-
-
- {% include "admin/admin_tasks.html" %} - -
-
-
Deployments
-

- - - - - - - - - - - - - {% for deploy in inv_deployments %} - - - - - - - - - - {% endfor %} - -
NameCPUMemHDDIPv4Control
- {% if status[deploy.machine_id] == 'running' %}{% else %}{% endif %}{{ deploy.machine_alias }}{{ deploy.machine_cpu }} Cores{{ deploy.machine_mem }} MB{{ deploy.machine_hdd }} GB0.0.0.0{% if status[deploy.machine_id] == 'running' %} - - - {% else %} - - {% endif %}{% if status[deploy.machine_id] == 'running' %} - - {% endif %}
- -

-
-
- -
-
-
Domains
-

- - - - - - - - - {% for domain in inv_domains %} - - - - - - {% endfor %} - -
NameExpiry DateControl
{{ domain.fqdn }}{{ domain.date_expire }}soon...
- -

-
-
- -
-
-
Addresses
-

- - - - - - - - - - {% for address in inv_addresses %} - - - - - - {% endfor %} - - -
IPReverse DNSMAC Addr.Control
{{ address.ip }}{{ address.rdns }}{{ address.macaddr }}soon...
- -

-
-
- -
-
-
Services
-

- - - - - - - - - - {% for service in inv_services %} - - - - - - - {% endfor %} - -
NameDescriptionUnitPrice
{{ service.name }}{{ service.description }}{{ service.unit }}{{ service.unitprice }}
- -

-
-
- -
- - -
-
-
- -{% endblock %} - diff --git a/app/templates/vmanager/dashboard.html b/app/templates/vmanager/dashboard.html index 3789543..3e96689 100644 --- a/app/templates/vmanager/dashboard.html +++ b/app/templates/vmanager/dashboard.html @@ -7,10 +7,8 @@ .tg td{font-family:Arial, sans-serif;font-size:14px;padding:1px 1px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg th{font-family:Arial, sans-serif;font-size:14px;padding:1px 1px;font-weight:normal;padding:border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg .tg-yw4l{vertical-align:top} - -