redesign admin pages
This commit is contained in:
parent
426143a5cc
commit
d7246f30ed
8 changed files with 93 additions and 66 deletions
|
@ -258,60 +258,64 @@ class Deployment(db.Model):
|
||||||
pid = db.Column(db.Integer, primary_key=True)
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
||||||
server_id = db.Column(db.ForeignKey('servers.pid')) #FK
|
server_id = db.Column(db.ForeignKey('servers.pid')) #FK
|
||||||
|
|
||||||
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
deleted = db.Column(db.Boolean, default=False)
|
deleted = db.Column(db.Boolean, default=False)
|
||||||
|
|
||||||
enabled = db.Column(db.Boolean, default=True)
|
enabled = db.Column(db.Boolean, default=True)
|
||||||
warning = db.Column(db.Boolean, default=False)
|
warning = 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.
|
protected = db.Column(db.Boolean, default=False) #machines with this False will be autodeleted after the warning period is over.
|
||||||
date_last_charge = db.Column(db.DateTime)
|
date_last_charge = db.Column(db.DateTime)
|
||||||
|
discount = db.Column(db.Integer)
|
||||||
period = db.Column(db.Integer)
|
period = db.Column(db.Integer)
|
||||||
daysleft = db.Column(db.Integer)
|
daysleft = db.Column(db.Integer)
|
||||||
|
|
||||||
vlan = db.Column(db.Integer)
|
|
||||||
machine_id = db.Column(db.BigInteger) #unit_id
|
machine_id = db.Column(db.BigInteger) #unit_id
|
||||||
machine_alias = db.Column(db.String) #dns name
|
machine_alias = db.Column(db.String) #dns name
|
||||||
machine_cpu = db.Column(db.Integer)
|
machine_cpu = db.Column(db.Integer)
|
||||||
machine_mem = db.Column(db.Integer)
|
machine_mem = db.Column(db.Integer)
|
||||||
machine_hdd = db.Column(db.Integer)
|
machine_hdd = db.Column(db.Integer)
|
||||||
discount = db.Column(db.Integer)
|
|
||||||
|
|
||||||
inv_addresses = db.relationship('Address', backref='assignee', lazy='dynamic')
|
inv_pubvlans = db.relationship('PubVLAN', backref='deploy', lazy='dynamic')
|
||||||
|
|
||||||
|
class PubVLAN(db.Model):
|
||||||
|
__tablename__ = 'pubvlans'
|
||||||
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
|
deploy_id = db.Column(db.ForeignKey('deployments.pid')) #FK
|
||||||
|
vlan_id = db.Column(db.Integer)
|
||||||
|
pubaddr = db.relationship('Address', uselist=False, backref='assignee')
|
||||||
|
|
||||||
class Address(db.Model):
|
class Address(db.Model):
|
||||||
__tablename__ = 'address'
|
__tablename__ = 'address'
|
||||||
pid = db.Column(db.Integer, primary_key=True)
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
||||||
region_id = db.Column(db.ForeignKey('regions.pid')) #FK
|
region_id = db.Column(db.ForeignKey('regions.pid')) #FK
|
||||||
deployment_id = db.Column(db.ForeignKey('deployments.pid')) #FK
|
pubvlan_id = db.Column(db.ForeignKey('pubvlans.pid')) #FK
|
||||||
date_assigned = db.Column(db.DateTime, default=datetime.utcnow)
|
|
||||||
enabled = db.Column(db.Boolean)
|
enabled = db.Column(db.Boolean)
|
||||||
|
|
||||||
ip = db.Column(db.String)
|
ip = db.Column(db.String)
|
||||||
mac = db.Column(db.String)
|
#mac = db.Column(db.String)
|
||||||
rdns = db.Column(db.String)
|
rdns = db.Column(db.String)
|
||||||
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
|
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, **kwargs):
|
#def __init__(self, **kwargs):
|
||||||
super(Address, self).__init__(**kwargs)
|
# super(Address, self).__init__(**kwargs)
|
||||||
if self.mac is None:
|
# if self.mac is None:
|
||||||
self.mac = self.genmac()
|
# self.mac = self.genmac()
|
||||||
|
|
||||||
def genmac(self):
|
#def genmac(self):
|
||||||
alladdr = Address.query.all()
|
# alladdr = Address.query.all()
|
||||||
allmacs = []
|
# allmacs = []
|
||||||
current_app.logger.info('populating mac addr pool')
|
# current_app.logger.info('populating mac addr pool')
|
||||||
for addr in alladdr:
|
# for addr in alladdr:
|
||||||
allmacs.append(str(addr.mac))
|
# allmacs.append(str(addr.mac))
|
||||||
while True:
|
# while True:
|
||||||
mac = [ random.randint(0, 255) for x in range(0, 6) ]
|
# mac = [ random.randint(0, 255) for x in range(0, 6) ]
|
||||||
mac[0] = (mac[0] & 0xfc) | 0x02
|
# mac[0] = (mac[0] & 0xfc) | 0x02
|
||||||
mac = ':'.join([ '{0:02x}'.format(x) for x in mac ])
|
# mac = ':'.join([ '{0:02x}'.format(x) for x in mac ])
|
||||||
if mac in allmacs:
|
# if mac in allmacs:
|
||||||
current_app.logger.warning('mac address {} is in the pool. regenerating...'.format(mac))
|
# current_app.logger.warning('mac address {} is in the pool. regenerating...'.format(mac))
|
||||||
continue
|
# continue
|
||||||
else:
|
# else:
|
||||||
return mac
|
# return mac
|
||||||
|
|
||||||
#MISC ITEMS
|
#MISC ITEMS
|
||||||
class Service(db.Model):
|
class Service(db.Model):
|
||||||
|
|
7
app/templates/admin/admin_cloud.html
Normal file
7
app/templates/admin/admin_cloud.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<center>
|
||||||
|
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_servers') }}','_self')"><span class="glyphicon glyphicon-off" aria-hidden="true"></span> Servers</button>
|
||||||
|
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
|
||||||
|
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
|
||||||
|
<button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_recyclebin') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button>
|
||||||
|
</center>
|
||||||
|
|
7
app/templates/admin/admin_misc.html
Normal file
7
app/templates/admin/admin_misc.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<center>
|
||||||
|
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
|
||||||
|
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
|
||||||
|
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
|
||||||
|
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-btc" aria-hidden="true"></span> Transactions</button>
|
||||||
|
</center>
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-6">
|
||||||
<div class="panel panel-warning" id="prxadmin">
|
<div class="panel panel-warning" id="prxadmincloud">
|
||||||
<div class="panel-heading">Admin Pages</div>
|
<div class="panel-heading">Cloud Manager</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<center>
|
{% include "admin/admin_cloud.html" %}
|
||||||
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
|
</div>
|
||||||
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
|
</div>
|
||||||
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
|
</div>
|
||||||
<button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_recyclebin') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button>
|
|
||||||
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
|
<div class="col-md-6">
|
||||||
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-btc" aria-hidden="true"></span> Transactions</button>
|
<div class="panel panel-warning" id="prxadminmisc">
|
||||||
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_servers') }}','_self')"><span class="glyphicon glyphicon-off" aria-hidden="true"></span> Servers</button>
|
<div class="panel-heading">Misc</div>
|
||||||
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
|
<div class="panel-body">
|
||||||
</center>
|
{% include "admin/admin_misc.html" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
<th>Assignee</th>
|
|
||||||
<th>VLAN</th>
|
<th>VLAN</th>
|
||||||
<th>Slave</th>
|
<th>Deploy</th>
|
||||||
|
<th>Server</th>
|
||||||
<th>Region</th>
|
<th>Region</th>
|
||||||
<th>rDNS</th>
|
<th>rDNS</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -27,19 +27,23 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for address in addresses %}
|
{% for address in addresses %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if address.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
|
{% if address.reserved == True %}<tr class="danger">{% else %}<tr>{% endif %}
|
||||||
<td>{{ address.ip }}</td>
|
<td>{{ address.ip }}</td>
|
||||||
{% if address.assignee != None %}
|
{% if address.assignee != None %}
|
||||||
<td>{{ address.assignee.machine_alias }}</td>
|
<td>{{ address.assignee.vlan_id }}</td>
|
||||||
<td>{{ address.assignee.vlan }}</td>
|
<td>{{ address.assignee.deploy.machine_alias }}</td>
|
||||||
<td>{{ address.assignee.server.name }}</td>
|
<td>{{ address.assignee.deploy.server.name }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td>None</td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{ address.region.name }}</td>
|
<td>{{ address.region.name }}</td>
|
||||||
|
{% if address.rdns != None %}
|
||||||
<td>{{ address.rdns }}</td>
|
<td>{{ address.rdns }}</td>
|
||||||
|
{% else %}
|
||||||
|
<td></td>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
<th>CPU</th>
|
<th>CPU</th>
|
||||||
<th>Mem</th>
|
<th>Mem</th>
|
||||||
<th>HDD</th>
|
<th>HDD</th>
|
||||||
<th>Price</th>
|
|
||||||
<th>Last Charged</th>
|
<th>Last Charged</th>
|
||||||
<th>Days Left</th>
|
<th>Days Left</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -42,7 +41,6 @@
|
||||||
<td>{{ deploy.machine_cpu }}</td>
|
<td>{{ deploy.machine_cpu }}</td>
|
||||||
<td>{{ deploy.machine_mem }} MB</td>
|
<td>{{ deploy.machine_mem }} MB</td>
|
||||||
<td>{{ deploy.machine_hdd }} GB</td>
|
<td>{{ deploy.machine_hdd }} GB</td>
|
||||||
<td>{{ deploy.price }}</td>
|
|
||||||
{% if deploy.date_last_charge == None %}
|
{% if deploy.date_last_charge == None %}
|
||||||
<td>Never</td>
|
<td>Never</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -4,11 +4,12 @@ from flask_sqlalchemy import get_debug_queries
|
||||||
|
|
||||||
from . import vmanager
|
from . import vmanager
|
||||||
from .forms import CreateForm, ActivateForm
|
from .forms import CreateForm, ActivateForm
|
||||||
from .. import db
|
from .. import db, csrf
|
||||||
from ..email import send_email
|
from ..email import send_email
|
||||||
from ..models import User, Permission, Transaction, Deployment, Service, Region, Address, Domain, contact_proxmaster
|
from ..models import User, Permission, Transaction, Deployment, Service, Region, Server, Address, Domain, contact_proxmaster
|
||||||
from ..decorators import admin_required, permission_required
|
from ..decorators import admin_required, permission_required
|
||||||
|
|
||||||
|
import json
|
||||||
import base64
|
import base64
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
@ -27,20 +28,24 @@ def after_request(response):
|
||||||
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
|
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@vmanager.route('/slavetables/<int:regionid>', methods=['GET'])
|
@vmanager.route('/slavetables', methods=['POST'])
|
||||||
def slavetables(regionid):
|
@csrf.exempt
|
||||||
selected_region = Region.query.filter_by(pid=int(regionid)).first()
|
def slavetables():
|
||||||
if selected_region == None:
|
postdata = request.get_json()
|
||||||
return jsonify({})
|
if postdata['passphrase'] == 'batkataisthebest1':
|
||||||
addresses = selected_region.inv_addresses.filter_by(enabled=True).all()
|
selected_slave = Server.query.filter_by(name=str(postdata['slavename'])).first()
|
||||||
regionlist = {}
|
if selected_slave == None:
|
||||||
for address in addresses:
|
return jsonify({'status': 'slave_not_found'})
|
||||||
regionlist[str(address.pid)] = { 'ipv4': str(address.ip), 'mac': str(address.mac) }
|
deploylist = selected_slave.inv_deployments.all()
|
||||||
|
addresslist = {}
|
||||||
data = { 'region_id': str(selected_region.pid),
|
for deploy in deploylist:
|
||||||
'addresses': regionlist }
|
addresslist[str(deploy.machine_id)] = {}
|
||||||
return jsonify(data)
|
addresses = deploy.inv_addresses.first()
|
||||||
|
deploy_address_list = []
|
||||||
|
for address in addresses:
|
||||||
|
deploy_address_list.append(address.ip)
|
||||||
|
addresslist[deploy.vlan] = deploy_address_list
|
||||||
|
return jsonify(addresslist)
|
||||||
|
|
||||||
@vmanager.route('/createvm', methods=['GET', 'POST'])
|
@vmanager.route('/createvm', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -78,7 +83,8 @@ def createvm():
|
||||||
return redirect(url_for('panel.dashboard'))
|
return redirect(url_for('panel.dashboard'))
|
||||||
|
|
||||||
if query['status'] == 'kvm_created':
|
if query['status'] == 'kvm_created':
|
||||||
deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0, bridge_id=int(selected_bridge.pid))
|
selected_slave = Server.query.filter_by(name=query['slave']).first()
|
||||||
|
deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0, server_id=int(selected_slave.pid), vlan=query['vlanid'])
|
||||||
db.session.add(deployment)
|
db.session.add(deployment)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description)))
|
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description)))
|
||||||
|
|
|
@ -39,6 +39,7 @@ requests==2.17.3
|
||||||
schedule==0.4.2
|
schedule==0.4.2
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
sortedcontainers==1.5.7
|
sortedcontainers==1.5.7
|
||||||
|
speaklater==1.3
|
||||||
SQLAlchemy==1.1.10
|
SQLAlchemy==1.1.10
|
||||||
traits==4.6.0
|
traits==4.6.0
|
||||||
Unipath==1.1
|
Unipath==1.1
|
||||||
|
|
Loading…
Reference in a new issue