rethink deactivated deployments

This commit is contained in:
deflax 2017-06-28 17:42:21 +03:00
parent f2c6d62556
commit 98f41a5533
8 changed files with 108 additions and 65 deletions

View file

@ -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

View file

@ -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

View file

@ -2,9 +2,12 @@
<div class="panel panel-warning" id="prxadmin">
<div class="panel-heading">Admin Pages</div>
<div class="panel-body">
<center>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_items') }}','_self')"><span class="glyphicon glyphicon-list" aria-hidden="true"></span> Items</button>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-usd" aria-hidden="true"></span> Transactions</button>
<button class="btn btn-default" onclick="alert('yes. this button does nothing.')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Nothing</button>
</center>
</div>
</div>
</div>

View file

@ -10,32 +10,34 @@
{% include "admin/admin_tasks.html" %}
<div class="col-md-12">
<div class="panel panel-danger" id="deployments">
<div class="panel panel-warning" id="deployments">
<div class="panel-heading">Deployments</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Owner</th>
<th>Cube ID</th>
<th>Alias</th>
<th>CPU</th>
<th>Mem</th>
<th>HDD</th>
<th>Price per month</th>
<th>Owner</th>
<th>Price</th>
<th>Period</th>
<th>Last Charged</th>
</tr>
</thead>
<tbody>
{% for deploy in deployments %}
{% if deploy.enabled == True %}<tr class="error">{% else %}<tr>{% endif %}
{% if deploy.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
<td><a href="{{ url_for('admin.dashboard', user_pid=deploy.user_id) }}">{{ deploy.owner.email }}</a></td>
<td>{{ deploy.machine_id }}</td>
<td>{{ deploy.machine_alias }}</font></td>
<td>{{ deploy.machine_cpu }} c.</td>
<td>{{ deploy.machine_cpu }}</td>
<td>{{ deploy.machine_mem }} MB</td>
<td>{{ deploy.machine_hdd }} GB</td>
<td>{{ deploy.price }} </td>
<td><a href="{{ url_for('admin.dashboard', user_pid=deploy.user_id) }}">{{ deploy.owner.email }}</a></td>
<td>{{ deploy.price }}</td>
<td>{{ deploy.period }}</td>
<td>{{ moment(deploy.date_last_charge).format('lll') }} ({{ moment(deploy.date_last_charge).fromNow() }})</td>
{% endfor %}
</tbody>
@ -45,28 +47,28 @@
</div>
<div class="col-md-12">
<div class="panel panel-danger" id="services">
<div class="panel panel-warning" id="services">
<div class="panel-heading">Services</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Owner</th>
<th>Category</th>
<th>Description</th>
<th>Months</th>
<th>Price</th>
<th>Owner</th>
<th>Period</th>
<th>Last Charged</th>
</tr>
</thead>
<tbody>
{% for service in services %}
{% if service.enabled == True %}<tr class="error">{% else %}<tr>{% endif %}
{% if service.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
<td><a href="{{ url_for('admin.dashboard', user_pid=service.user_id) }}">{{ service.owner.email }}</a></td>
<td>{{ service.category }}</td>
<td>{{ service.description }}</td>
<td>{{ service.period }}</td>
<td>{{ service.price }}</td>
<td><a href="{{ url_for('admin.dashboard', user_pid=service.user_id) }}">{{ service.owner.email }}</a></td>
<td>{{ service.period }}</td>
<td>{{ moment(service.date_last_charge).format('ll') }} ({{ moment(service.date_last_charge).fromNow() }})</td>
</tr>
{% endfor %}
@ -78,23 +80,23 @@
<div class="col-md-12">
<div class="panel panel-danger" id="domains">
<div class="panel panel-warning" id="domains">
<div class="panel-heading">Domains</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Owner</th>
<th>Name</th>
<th>Expiry Date</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
{% for domain in domains %}
{% if domain.enabled == True %}<tr class="error">{% else %}<tr>{% endif %}
{% if domain.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
<td><a href="{{ url_for('admin.dashboard', user_pid=domain.user_id) }}">{{ domain.owner.email }}</a></td>
<td><b><a href="http://{{ domain.fqdn }}">{{ domain.fqdn }}</a></b></td>
<td>{{ domain.date_expire }}</td>
<td><a href="{{ url_for('admin.dashboard', user_pid=domain.user_id) }}">{{ domain.owner.email }}</a></td>
</tr>
{% endfor %}
</tbody>
@ -104,26 +106,26 @@
</div>
<div class="col-md-12">
<div class="panel panel-danger" id="addresses">
<div class="panel panel-warning" id="addresses">
<div class="panel-heading">Addresses</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Owner</th>
<th>IP</th>
<th>MAC Addr.</th>
<th>Reverse DNS</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
{% for address in addresses %}
<tr>
{% if address.enabled == True %}<tr class="error">{% else %}<tr>{% endif %}
{% if address.enabled == False %}<tr class="danger">{% else %}<tr>{% endif %}
<td><a href="{{ url_for('admin.dashboard', user_pid=address.user_id) }}">{{ address.owner.email }}</a></td>
<td>{{ address.ip }}</td>
<td>{{ address.mac }}</td>
<td>{{ address.rdns }}</td>
<td><a href="{{ url_for('admin.dashboard', user_pid=address.user_id) }}">{{ address.owner.email }}</a></td>
{% endfor %}
</tr>
</tbody>

View file

@ -6,7 +6,7 @@
{% include "admin/admin_tasks.html" %}
<div class="col-md-12">
<div class="panel panel-danger">
<div class="panel panel-warning">
<div class="panel-heading">Transactions</div>
<div class="panel-body">

View file

@ -5,7 +5,7 @@
{% include "admin/admin_tasks.html" %}
<div class="col-md-12">
<div class="panel panel-danger" id="users">
<div class="panel panel-warning" id="users">
<div class="panel-heading">Users</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">

View file

@ -123,24 +123,35 @@ addEventListener("DOMContentLoaded", function() {
<div class="row">
{% if inv_deployments != [] %}
<div class="col-md-12">
<div class="panel panel-info" id="deployments">
<div class="panel-heading">Deployments</div>
<div class="panel-body"><p>
<div id="no-more-tables">
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Name</th>
<th>CPU</th>
<th>Mem</th>
<th>HDD</th>
<th>IPv4</th>
<th>Control</th>
<th></th>
</tr>
<thead>
<tr>
<th>Name</th>
<th>CPU</th>
<th>Mem</th>
<th>HDD</th>
<th>IPv4</th>
<th>Control</th>
<th></th>
</tr>
</thead>
<tbody>
{% for deploy in inv_deployments %}
{% if deploy.enabled == False %}
<tr class="danger">
<td data-title="Name"><b>{% if status[deploy.machine_id] == 'running' %}<font color="green">{% else %}<font color="red">{% endif %}{{ deploy.machine_alias }}</font></b></td>
<td data-title="CPU">{{ deploy.machine_cpu }} Cores</td>
<td data-title="Memory">{{ deploy.machine_mem }} MB</td>
<td data-title="Disk">{{ deploy.machine_hdd }} GB</td>
<td data-title="Network">{% for addr in deploy.machine_addresses %} {{ addr.ip }}<br /> {% endfor %}</td>
{% else %}
<tr>
<td data-title="Name"><a class="rrd" data-toggle="tooltip" title="ID# {{ deploy.machine_id }}<br />Deployment state: {{ status[deploy.machine_id] }}"><b>{% if status[deploy.machine_id] == 'running' %}<font color="green">{% else %}<font color="red">{% endif %}{{ deploy.machine_alias }}</font></b></a></td>
<td data-title="CPU"><a class="rrd" data-toggle="tooltip" title="<img src='data:image/png;base64,{{ rrd[deploy.machine_id]['cpu'] }}' />">{{ deploy.machine_cpu }} Cores</a></td>
@ -157,6 +168,7 @@ addEventListener("DOMContentLoaded", function() {
<button class="btn btn-default btn-info" onclick="window.open('/vmanager/vmvnc/{{ deploy.machine_id }}', '_blank');"><span class="glyphicon glyphicon-console" aria-hidden="true"></span> Console</button>
{% endif %}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
@ -165,7 +177,9 @@ addEventListener("DOMContentLoaded", function() {
</div>
</div>
</div>
{% endif %}
{% if inv_services != [] %}
<div class="col-md-12">
<div class="panel panel-info" id="services">
<div class="panel-heading">Services</div>
@ -197,8 +211,10 @@ addEventListener("DOMContentLoaded", function() {
</div>
</div>
</div>
{% endif %}
<div class="col-md-6">
{% if inv_domains != [] %}
<div class="col-md-12">
<div class="panel panel-info" id="domains">
<div class="panel-heading">Domains</div>
<div class="panel-body"><p>
@ -225,8 +241,10 @@ addEventListener("DOMContentLoaded", function() {
</div>
</div>
</div>
{% endif %}
<div class="col-md-6">
{% if inv_addresses != [] %}
<div class="col-md-12">
<div class="panel panel-info" id="addresses">
<div class="panel-heading">Addresses</div>
<div class="panel-body"><p>
@ -235,6 +253,7 @@ addEventListener("DOMContentLoaded", function() {
<thead>
<tr>
<th>IP</th>
<th>Region</th>
<th>MAC Addr.</th>
<th>Reverse DNS</th>
<th>Control</th>
@ -243,6 +262,7 @@ addEventListener("DOMContentLoaded", function() {
{% for address in inv_addresses %}
<tr>
<td data-title="IP">{{ address.ip }}</td>
<td data-title="Region">{{ region[address.region_id] }}</td>
<td data-title="MAC">{{ address.mac }}</td>
<td data-title="RDNS">{{ address.rdns }}</td>
<td data-title="Control">soon...</td>
@ -255,6 +275,7 @@ addEventListener("DOMContentLoaded", function() {
</div>
</div>
</div>
{% endif %}
</div>

View file

@ -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('/<cmd>/<int:vmid>')
@ -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)