add market items into the database model

This commit is contained in:
deflax 2018-02-01 01:55:35 +02:00
parent cac4f2f847
commit 61a1839ea6
3 changed files with 33 additions and 4 deletions

View file

@ -226,6 +226,22 @@ def contact_proxmaster(data, method):
except:
return { 'status': 'UNREACHABLE' }
#MARKET
class Order(db.Model):
__tablename__ = 'orders'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.ForeignKey('users.pid')) #FK
recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK
parameters = db.Column(db.String)
class Recipe(db.Model):
__tablename__ = 'recipes'
pid = db.Column(db.Integer, primary_key=True)
inv_orders = db.relationship('Order', backref='recipe', lazy='dynamic')
category = db.Column(db.String)
templatefile = db.Column(db.String)
description = db.Column(db.String)
#VDC
class Region(db.Model):
__tablename__ = 'regions'

View file

@ -17,6 +17,8 @@
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Server</th>
<th>VLAN</th>
<th>Alias</th>
<th>CPU</th>
<th>Mem</th>
@ -37,7 +39,9 @@
<tr>
{% endif %}
{% endif %}
<td data-title="Alias"><a class="rrd" data-toggle="tooltip" title="Protected: {{ deploy.protected }}<br />Online: {{ deploy.connected }}<br />ID: {{ deploy.machine_id }}"><b>{% if deploy.protected == True %}<font color="green">{% else %}<font color="red">{% endif %}{{ deploy.machine_alias }}</font></b></a></td>
<td data-title="Server">{{ deploy.server.name }}</td>
<td data-title="VLAN">{% for vlan in deploy.inv_pubvlans %}{{ vlan.vlan_id }}{% endfor %}</td>
<td data-title="Alias"><a class="rrd" data-toggle="tooltip" title="Protected: {{ deploy.protected }} Online: {{ deploy.connected }}ID: {{ deploy.machine_id }}"><b>{% if deploy.enabled == True %}<font color="green">{% else %}<font color="red">{% endif %}{{ deploy.machine_alias }}</font></b></a></td>
<td data-title="CPU">{{ deploy.machine_cpu }}</td>
<td data-title="Memory">{{ deploy.machine_mem }} MB</td>
<td data-title="HDD">{{ deploy.machine_hdd }} GB</td>

View file

@ -70,8 +70,7 @@ def createvm():
data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email),
'hostname': 'c' + str(current_user.pid) + '-' + str(form.servername.data),
'region': str(region_name),
'slave': str(slave_name),
'region': str(selected_region.name),
'type': 'kvm',
'cpu': '1',
'mem': '512',
@ -86,9 +85,13 @@ def createvm():
if query['status'] == 'kvm_created':
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'])
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))
db.session.add(deployment)
db.session.commit()
new_vlan = PubVLAN(deploy_id=int(deployment.pid), vlan_id=int(query['vlanid']))
db.session.add(new_vlan)
db.session.commit()
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description)))
return redirect(url_for('panel.dashboard'))
else:
@ -179,6 +182,11 @@ def remove(unit_id=0):
if current_user.is_administrator():
if deploy.protected is not True:
try:
#pubvlans depends on deploy as foreign key so delete them first
for pubvlan in deploy.inv_pubvlans:
db.session.delete(pubvlan)
db.session.commit()
query = contact_proxmaster(data, 'status')
if query['status'] == 'running':
query = contact_proxmaster(data, 'stop')
@ -190,6 +198,7 @@ def remove(unit_id=0):
deploy.enabled = False
deploy.warning = False
db.session.commit()
except Exception as e:
current_app.logger.error(e)
flash('Cannot delete machine {}'.format(unit_id))