simplify create-activate again

This commit is contained in:
deflax 2018-01-24 10:58:28 +02:00
parent 4c3739da20
commit f616f2c2e1
7 changed files with 32 additions and 128 deletions

View file

@ -137,7 +137,7 @@ def list_transactions():
@admin_required
def transaction(user_pid=0):
cuser = User.query.filter_by(pid=user_pid).first()
transactions = cuser.inv_transactions.order_by(Transaction.date_created.desc()).all()
transactions = cuser.inv_transactions.order_by(Transaction.date_created.desc()).limit(20)
labelslist = ['today']
translist = [cuser.wallet]

View file

@ -7,13 +7,14 @@
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Transactions</div>
<div class="panel-heading">All Transactions</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>ID</th>
<th>Description</th>
<th>Amount</th>
<th>Date</th>
@ -25,12 +26,14 @@
{% for transaction in transactions %}
{% if transaction.value > 0 %}
<tr class="default">
<td>{{ transaction.pid }}</td>
<td>{{ transaction.description }}</td>
<td>{{ transaction.value }} {{ transaction.currency }}</td>
<td>{{ moment(transaction.date_created).format('lll') }}</td>
<td><a href="{{ url_for('admin.transaction', user_pid=transaction.owner.pid) }}">{{ transaction.owner.email }}</a></td>
{% else %}
<tr class="default">
<td>{{ transaction.pid }}</td>
<td>{{ transaction.description }}</td>
<td>{{ transaction.value }} {{ transaction.currency }}</td>
<td>{{ moment(transaction.date_created).format('lll') }}</td>

View file

@ -90,16 +90,7 @@
<h2 class="media-heading">Оборудване</h2>
<p>Благодарение на внедрените нови технологии ние предлагаме изчислителна мощ, надеждно съхранение на данни и гъвкаво разпределение на ресурсите. Предвиждаме възможности нашата система да бъде неразделна част от текущата ви инфраструктура.</p>
</div>
</div>
<div class="panel panel-primary panel-transparent">
<div class="panel-body">
<img src="../../static/images/VPS-Support.png" width="128" height="128" />
<h2 class="media-heading">Поддръжка</h2>
<p>Ще Ви помогнем във всички неприятни ситуации, по всяко време. </p>
<a href="/chat"><button type="button" class="btn btn-lg btn-success">Support</button></a>
</div>
</div>
i </div>
</div>
<div class="col-md-6">
@ -110,8 +101,12 @@
<p>Желанието ни е да предоставим елегантна платформа за управление на изчислителни процеси, която цели да бъде използваема от всеки, а не само от тесен кръг специалисти, без да се прави компромис със качеството и възможностите й.</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary panel-transparent">
<div class="panel-body">
<img src="../../static/images/VPS-Security.png" width="128" height="128" />
@ -120,6 +115,18 @@
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-primary panel-transparent">
<div class="panel-body">
<img src="../../static/images/VPS-Support.png" width="128" height="128" />
<h2 class="media-heading">Поддръжка</h2>
<p>Ще Ви помогнем във всички неприятни ситуации, по всяко време. </p>
<a href="/chat"><button type="button" class="btn btn-lg btn-success">Support</button></a>
</div>
</div>
</div>
</div>
</div>

View file

@ -229,26 +229,6 @@ addEventListener("DOMContentLoaded", function() {
<div class="panel panel-info" id="addresses">
<div class="panel-heading">Communications</div>
<div class="panel-body"><p>
<img width="32" height="32" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAALnSURBVGhD7ZrPaxNBFMcXRK/q3+JVEKS7G6kWUVP/A+v/IFgQmpm00R7Ve/2RoiB4EEHag3ZnlR4LRtMqgndb8aTF9X0nbw/qxpnRTTIu+4FHmdk3895350eSmQY1Qzi1qNZmrr988SeDD7v7SyxVdvVhP7vx9EOh4Rl82N1fkOSz3l72fvd7oeFZLaQMmvNbh2KZzEYiuRcJ1YtF8gUJFZmNkEKjPtF3JNVdxEJMDl8OoUwvUIDtSCZ7CBKJ9FLU3jhNgad+M0rISkhBW92nTOb0y6JY5NenuOc5jb+nubp6gAIskX0lAQsnlteP8KOh2Aph96EgFsUV5PsNOSAXfuQOvZ0O2W4o0pNcZaQsITkYKeRAL3KRq9zAdMJIuIgAZQsBEENTbJ+m3lmusoMX9g6GlqusQZI2xu7WYESwTo/d3jzIVWailrqIxTYlNw9zlTV6KlgYu1uDNYOcGiJpcpUZvTORcdEbaJbcj4Va4aIZUv6GGs1x0RuQE3Ljohmai59DkZzhojcgJ+TGRTNYjA2pjnPRG5CT00ZRCxkxtRAueoNRSKOtEjiYbJzi8qRNhty5SRBMd9JXVx68zZ5sfRpqutEEhBTlktu1RzsZcucmAyHL9Hu66EtebpMSUpRLbjfXP9ZCaiGu1EIqI6QS229lPhB/RTuMMWlbcnFcNFMLGTG1EC56g7OQyhw+eHsc1Eouk5AeF83EQt3B0T4XvYFEdJ0O6Gg0Zn07Mp0Wz48iJxyuc5UZHGKT+m0SJLnKGixGG2N3a0j8ErXrOx1iA2p0jsTs+3CtELbSCLnEbTXDVW4M3oK+ZAm5ykjZQiBC5yBUm6vcwXUX7iUosL7+GvvVm0w6GAmI+KertxzcFFHwPhYbddrFNog9PV+4P5mlkKK2us/BFttFLMQs/fMMGwAuWbD9UYDXFHgk19P0l/pWK4hV+vW0C0jIRgi7+0ulhCw8fpfdot/TRYZn/4WQyvyb02QIgh+ETy3CcS71GAAAAABJRU5ErkJggg=="> Private<br />
<div id="bridges" class="no-more-tables">
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<th>Unit</th>
<th>Network</th>
</tr>
</thead>
<tbody>
{% for bridge in inv_bridges %}
<tr>
<td data-title="Unit">{{ bridge.bridge_id }}</td>
<td data-title="Network">192.168.9.0</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<img width="32" height="32" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAEW0lEQVRYhe3YT0zbVhwH8HfgwKGHHnrYYYcddkBVT7t0kybNh8kvgTiBJlTdhCba0R03qVo3NBUtUkv88sdOgtapYu0mFQ1tY4BGK9qKaZmYkud/BFzKyBYYGmgRNCGBjf+ovB0SVyklJHEM7aR9pafIVmJ//Ht5z34G4P8AAJHQDxHegm48bkJC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g/RHtUG5/fItKfa+TOgwwJDs1uN3eOZWo94gbjE27WeqQXdMMAyL6WqPOKK13R1adwGlD7Lt0ePmH24E/sAQWf8stxGyclIcKE8YnL9bw0eyogR+s8gtfEYsqwe3GDXxlu7Z1J7YXbDTyU2ALKSXtAju1ele3X7IEn17oHmsYOJd4/uljWH743miKO4JNLyQMLRFjXdHFoXf2fAOpthwJ8XvMve9hz7NcDU4IAAAAASUVORK5CYII="> Public<br />
<div id="routers" class="no-more-tables">
<table class="table table-hover table-striped table-condensed cf">

View file

@ -60,7 +60,7 @@ var myChart = new Chart(ctx, {
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Transactions</div>
<div class="panel-heading">Last 20 Transactions</div>
<div class="panel-body">
<div class="table-responsive">

View file

@ -14,7 +14,7 @@ from ..models import User, Transaction
def transactions():
page = { 'title': 'Payment Transaction' }
cuser = current_user
transactions = Transaction.query.filter_by(user_id=cuser.pid).order_by(Transaction.date_created.desc()).limit(100)
transactions = Transaction.query.filter_by(user_id=cuser.pid).order_by(Transaction.date_created.desc()).limit(20)
labelslist = ['today']
translist = [cuser.wallet]

View file

@ -56,49 +56,9 @@ def createvm():
form = CreateForm()
if current_user.confirmed and form.validate_on_submit():
#selects the chosen region
selected_region = Region.query.filter_by(pid=int(form.region.data)).first()
#TODO: Filter bridges for the selected region only. switch should return slave name
selected_bridge = current_user.inv_bridges.filter_by(deleted=False).first()
if selected_bridge is None:
#no bridges in the account. create one...
data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email),
'region': str(selected_region.name),
'type': 'br'
}
#create bridge unit
query = contact_proxmaster(data, 'create')
if query['status'] == 'bridge_created':
newbridge = True
#machine will be installed where the bridge physically is
region_name = query['region']
slave_name = query['slave']
bridge_id = query['unit_id']
bridge_phy_id = query['phy_id']
selected_bridge = Bridge(user_id=int(current_user.pid), bridge_id=bridge_id)
db.session.add(selected_bridge)
db.session.commit()
flash('New point created successfully in region "{}".'.format(str(selected_region.description)))
else:
flash('Point could not be created! Please try again later...')
return redirect(url_for('panel.dashboard'))
else:
#bridge found. lets see on which slave it is so we can create the instance on the same slave.
data = { 'unit_id': int(selected_bridge.bridge_id),
'type': 'br' }
query = contact_proxmaster(data, 'query')
if query['status'] == 'query_success':
newbridge = False
#machine will be installed where the switch physically is
region_name = query['region']
slave_name = query['slave']
bridge_phy_id = query['phy_id']
else:
flash('Point found but cannot be used!')
return redirect(url_for('panel.dashboard'))
###
#create new machine...
data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email),
@ -109,7 +69,7 @@ def createvm():
'cpu': '1',
'mem': '512',
'hdd': '20',
'net0if': 'vmbr' + str(bridge_phy_id)
'net0if': 'vmbr7'
}
try:
query = contact_proxmaster(data, 'create')
@ -121,10 +81,10 @@ def createvm():
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))
db.session.add(deployment)
db.session.commit()
flash('New device created successfully in region "{}".'.format(str(selected_region.description)))
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description)))
return redirect(url_for('panel.dashboard'))
else:
flash('Device could not be created! Please try again later...')
flash('Deployment could not be created! Please try again later...')
#TODO: cleanup bridge if the machine is new and we were not be able to create it
@ -174,52 +134,6 @@ def activate(itemid=0):
else:
return redirect(url_for('uinvoice.transactions'))
current_app.logger.info('[{}] Charge deployment: {}'.format(owner.email, deploy.machine_id))
#TODO: Filter routers for the selected region only. switch should return slave name
selected_router = owner.inv_routers.filter_by(deleted=False).first()
if selected_router is None:
#TODO: Filter bridges for the selected region only. switch should return slave name
selected_bridge = owner.inv_bridges.filter_by(deleted=False).first()
if selected_bridge is None:
flash('No private network found.')
else:
#bridge found. lets see on which slave it is so we can create the instance on the same slave.
data = { 'unit_id': int(selected_bridge.bridge_id),
'type': 'br' }
query = contact_proxmaster(data, 'query')
if query['status'] == 'query_success':
#TODO: selected random ip address from the pool.
selected_ip = '87.120.110.41'
#machine will be installed where the switch physically is
region_name = query['region']
slave_name = query['slave']
bridge_phy_id = query['phy_id']
data = { 'clientid': str(owner.pid),
'clientemail': str(owner.email),
'hostname': 'c' + str(owner.pid) + '-r' + selected_ip,
'region': str(region_name),
'slave': str(slave_name),
'type': 'lxc',
'cpu': '1',
'mem': '256',
'hdd': '1',
'net0if': 'vmbr' + str(bridge_phy_id),
'net0ip': '192.168.9.1',
'net0mask': '24',
'net1if': 'vmbr0',
'net1ip': selected_ip,
'net1mask': '24',
'net1gw': '87.120.110.1' #should be queried from the current region
}
query = contact_proxmaster(data, 'create')
if query['status'] == 'lxc_created':
router = Router(user_id=int(owner.pid), machine_id=query['unit_id'])
db.session.add(router)
db.session.commit()
else:
flash('Router cannot be created.')
return redirect(url_for('panel.dashboard'))
today = datetime.utcnow()
expiry = today + relativedelta(today, months=+(form.period.data))
daysleft = expiry - today