merge logic user admin logic for dashboard view
This commit is contained in:
parent
c653c27509
commit
2bfb08c2bc
6 changed files with 21 additions and 69 deletions
|
@ -169,61 +169,3 @@ def transaction(user_pid=0):
|
||||||
#current_app.logger.info('[{}] transactions: {} {} '.format(cuser.email, translist, labelslist))
|
#current_app.logger.info('[{}] transactions: {} {} '.format(cuser.email, translist, labelslist))
|
||||||
return render_template('uinvoice/transactions.html', transactions=transactions, translist=translist, labelslist=labelslist, cuser=cuser)
|
return render_template('uinvoice/transactions.html', transactions=transactions, translist=translist, labelslist=labelslist, cuser=cuser)
|
||||||
|
|
||||||
@admin.route("/dashboard/<int:user_pid>", methods=['GET'])
|
|
||||||
@fresh_login_required
|
|
||||||
@admin_required
|
|
||||||
def dashboard(user_pid=0):
|
|
||||||
form = OrderForm()
|
|
||||||
sys_regions = Region.query.all()
|
|
||||||
|
|
||||||
cuser = User.query.filter_by(pid=user_pid).first()
|
|
||||||
|
|
||||||
inv_deployments = cuser.inv_deployments.filter_by(deleted=False).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(deleted=False).order_by(Service.date_last_charge.asc()).all()
|
|
||||||
inv_services_list = []
|
|
||||||
for invcls in inv_services:
|
|
||||||
inv_services_list.extend([invcls.description])
|
|
||||||
|
|
||||||
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
|
|
||||||
inv_domains_list = []
|
|
||||||
for invcls in inv_domains:
|
|
||||||
inv_domains_list.extend([invcls.fqdn])
|
|
||||||
|
|
||||||
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
|
|
||||||
inv_addresses_list = []
|
|
||||||
for invcls in inv_addresses:
|
|
||||||
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 = {}
|
|
||||||
for unit_id in inv_deploycubeids:
|
|
||||||
rrd[unit_id] = {}
|
|
||||||
data = { 'unit_id': int(unit_id),
|
|
||||||
'type': 'kvm' }
|
|
||||||
query = contact_proxmaster(data, 'vmrrd')
|
|
||||||
if query['status'] == 'UNREACHABLE':
|
|
||||||
flash('Deploy #{} is unreachable.'.format(str(unit_id)))
|
|
||||||
send_email(current_app.config['MAIL_USERNAME'], 'Deploy {} is unreachable'.format(unit_id),
|
|
||||||
'vmanager/email/adm_unreachable', user=cuser, unit_id=unit_id )
|
|
||||||
else:
|
|
||||||
graphs_list = ['net', 'cpu', 'mem', 'hdd']
|
|
||||||
for graph in graphs_list:
|
|
||||||
raw = query[graph]['image'].encode('raw_unicode_escape')
|
|
||||||
rrd[unit_id][graph] = base64.b64encode(raw).decode()
|
|
||||||
status = { unit_id : query['status'] }
|
|
||||||
statuses.update(status)
|
|
||||||
current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(cuser.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list))
|
|
||||||
return render_template('panel/dashboard.html', form=form, sys_regions=sys_regions, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, rrd=rrd, status=statuses, regions=regions)
|
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,21 @@ def deploy():
|
||||||
return render_template('panel/deploy.html', form=form)
|
return render_template('panel/deploy.html', form=form)
|
||||||
|
|
||||||
#DASHBOARD
|
#DASHBOARD
|
||||||
@panel.route("/dashboard", methods=['GET', 'POST'])
|
@panel.route("/dashboard", defaults={'user_pid': 0}, methods=['GET'])
|
||||||
|
@panel.route("/dashboard/<int:user_pid>", methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard(user_pid):
|
||||||
form = OrderForm()
|
|
||||||
sys_regions = Region.query.all()
|
sys_regions = Region.query.all()
|
||||||
|
|
||||||
|
if user_pid == 0:
|
||||||
cuser = current_user
|
cuser = current_user
|
||||||
|
else:
|
||||||
|
cuser = User.query.filter_by(pid=user_pid).first()
|
||||||
|
if cuser == None:
|
||||||
|
abort(404)
|
||||||
|
if not current_user.is_administrator():
|
||||||
|
abort(404) #hidden 403
|
||||||
|
|
||||||
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
|
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
|
||||||
inv_deployments = cuser.inv_deployments.filter_by(deleted=False).order_by(Deployment.date_created.desc()).all()
|
inv_deployments = cuser.inv_deployments.filter_by(deleted=False).order_by(Deployment.date_created.desc()).all()
|
||||||
regions = {}
|
regions = {}
|
||||||
|
@ -50,14 +58,16 @@ def dashboard():
|
||||||
regions[region.pid] = region.description
|
regions[region.pid] = region.description
|
||||||
|
|
||||||
inv_deploycubeids = []
|
inv_deploycubeids = []
|
||||||
|
warnflag = False
|
||||||
for invcls in inv_deployments:
|
for invcls in inv_deployments:
|
||||||
if invcls.user_id == cuser.pid:
|
if invcls.user_id == cuser.pid:
|
||||||
inv_deploycubeids.extend([invcls.machine_id])
|
inv_deploycubeids.extend([invcls.machine_id])
|
||||||
#warning detector
|
#warning detector
|
||||||
|
#current_app.logger.info(str(invcls.machine_alias))
|
||||||
if invcls.warning == True or invcls.enabled == False:
|
if invcls.warning == True or invcls.enabled == False:
|
||||||
|
current_app.logger.warning('[{}] Deploy {} triggered a warning'.format(cuser.email, invcls.machine_alias))
|
||||||
warnflag = True
|
warnflag = True
|
||||||
else:
|
|
||||||
warnflag = False
|
|
||||||
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
|
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
|
||||||
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
|
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
|
||||||
|
|
||||||
|
@ -93,5 +103,5 @@ def dashboard():
|
||||||
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
|
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
|
||||||
'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e))
|
'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e))
|
||||||
|
|
||||||
return render_template('panel/dashboard.html', form=form, sys_regions=sys_regions, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, rrd=rrd, status=statuses, warnflag=warnflag, regions=regions)
|
return render_template('panel/dashboard.html', sys_regions=sys_regions, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, rrd=rrd, status=statuses, warnflag=warnflag, regions=regions)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<td data-title="Parameter3">{{ order.parameter3 }}</td>
|
<td data-title="Parameter3">{{ order.parameter3 }}</td>
|
||||||
<td data-title="Parameter4">{{ order.parameter4 }}</td>
|
<td data-title="Parameter4">{{ order.parameter4 }}</td>
|
||||||
<td data-title="Status">{{ order.status }}</td>
|
<td data-title="Status">{{ order.status }}</td>
|
||||||
<td><button class="btn btn-default" onclick="window.open('{{ url_for('vmanager.vmcreate') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Confirm</button></td>
|
<td><button class="btn btn-default btn-success" onclick="window.open('{{ url_for('vmanager.vmcreate', orderid=order.pid) }}','_self');"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Confirm</button></td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<td data-title="Currency">{{ usr.currency }}</td>
|
<td data-title="Currency">{{ usr.currency }}</td>
|
||||||
<td><a href="{{ url_for('admin.charge', user_pid=usr.pid) }}" data-toggle="tooltip" title="Add Funds"><span class="glyphicon glyphicon-plus"></span></a>
|
<td><a href="{{ url_for('admin.charge', user_pid=usr.pid) }}" data-toggle="tooltip" title="Add Funds"><span class="glyphicon glyphicon-plus"></span></a>
|
||||||
<a href="{{ url_for('admin.transaction', user_pid=usr.pid) }}" data-toggle="tooltip" title="List Transactions"><span class="glyphicon glyphicon-credit-card"></span></a>
|
<a href="{{ url_for('admin.transaction', user_pid=usr.pid) }}" data-toggle="tooltip" title="List Transactions"><span class="glyphicon glyphicon-credit-card"></span></a>
|
||||||
<a href="{{ url_for('admin.dashboard', user_pid=usr.pid) }}" data-toggle="tooltip" title="Show Dashboard"><span class="glyphicon glyphicon-modal-window"></span></a>
|
<a href="{{ url_for('panel.dashboard', user_pid=usr.pid) }}" data-toggle="tooltip" title="Show Dashboard"><span class="glyphicon glyphicon-modal-window"></span></a>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
{% if deploy.enabled == False or deploy.warning == True %}
|
{% if deploy.enabled == False or deploy.warning == True %}
|
||||||
<div id="cube{{ deploy.machine_id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading{{ deploy.machine_id }}" style="border:3px solid #faebcc; border-top: none; margin-bottom: 10px;">
|
<div id="cube{{ deploy.machine_id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading{{ deploy.machine_id }}" style="border:3px solid #faebcc; border-top: none; margin-bottom: 10px;">
|
||||||
{% else %}
|
{% else %}
|
||||||
<div id="cube{{ deploy.machine_id }}" class="panel-collapse collapse {% if not warnflag %}in{% endif %}" role="tabpanel" aria-labelledby="heading{{ deploy.machine_id }}" style="border:3px solid #d6e9c6; border-top: none; margin-bottom: 10px;">
|
<div id="cube{{ deploy.machine_id }}" class="panel-collapse collapse {% if warnflag == False %}in{% endif %}" role="tabpanel" aria-labelledby="heading{{ deploy.machine_id }}" style="border:3px solid #d6e9c6; border-top: none; margin-bottom: 10px;">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
|
|
|
@ -33,7 +33,7 @@ pkg-resources==0.0.0
|
||||||
psycopg2==2.7.4
|
psycopg2==2.7.4
|
||||||
Pygments==2.2.0
|
Pygments==2.2.0
|
||||||
PyQRCode==1.2.1
|
PyQRCode==1.2.1
|
||||||
python-dateutil==2.7.0
|
python-dateutil==2.7.1
|
||||||
python-editor==1.0.3
|
python-editor==1.0.3
|
||||||
pytz==2018.3
|
pytz==2018.3
|
||||||
requests==2.18.4
|
requests==2.18.4
|
||||||
|
|
Loading…
Reference in a new issue