craete seed function phase 1

This commit is contained in:
deflax 2017-07-29 04:31:44 +03:00
parent 54703a8825
commit 6380a199b3
7 changed files with 118 additions and 73 deletions

View file

@ -234,6 +234,7 @@ class Service(db.Model):
daysleft = db.Column(db.Integer)
warning = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=False)
cancelled = db.Column(db.Boolean, default=False)
category = db.Column(db.String)
description = db.Column(db.Unicode)
@ -248,7 +249,9 @@ class Deployment(db.Model):
period = db.Column(db.Integer)
daysleft = db.Column(db.Integer)
warning = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=True)
protected = db.Column(db.Boolean, default=False) #machines with this False will be autodeleted after the warning period is over.
cancelled = db.Column(db.Boolean, default=False)
machine_id = db.Column(db.BigInteger) #cubeid
machine_alias = db.Column(db.String) #dns name
@ -308,6 +311,7 @@ class Domain(db.Model):
daysleft = db.Column(db.Integer)
warning = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=False)
cancelled = db.Column(db.Boolean, default=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, index=True, default=datetime.utcnow)

View file

@ -19,6 +19,11 @@ 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))
return response
@smanager.route('/requestservice', methods=['GET', 'POST'])
@login_required
def requestservice():
abort(403)
@smanager.route('/activate/<int:itemid>', methods=['GET', 'POST'])
@login_required
def activate(itemid=0):

View file

@ -3,13 +3,13 @@
<div class="panel-heading">Admin Pages</div>
<div class="panel-body">
<center>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
<button class="btn btn-default" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
<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_transactions') }}','_self')"><span class="glyphicon glyphicon-usd" aria-hidden="true"></span> Transactions</button>
<button class="btn btn-default" onclick="alert('Как ще си събираш зъбите със счупени ръце?')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Nothing</button>
<button class="btn btn-success btn-lg" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
<button class="btn btn-success btn-lg" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>
<button class="btn btn-success btn-lg" 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-lg" 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-lg" 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-lg" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-usd" aria-hidden="true"></span> Transactions</button>
<button class="btn btn-danger btn-lg" onclick="alert('Как ще си събираш зъбите със счупени ръце?')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Nothing</button>
</center>
</div>
</div>

View file

@ -128,6 +128,7 @@ addEventListener("DOMContentLoaded", function() {
<div class="panel panel-info" id="deployments">
<div class="panel-heading">Deployments</div>
<div class="panel-body"><p>
<!-- Individual Server icon by Icons8 -->
<div id="no-more-tables">
<table class="table table-hover table-striped table-condensed cf">
<thead>
@ -153,7 +154,7 @@ addEventListener("DOMContentLoaded", function() {
<td data-title="Network">{% for addr in deploy.machine_addresses %} {{ addr.ip }}<br /> {% endfor %}</td>
<td data-title="Control"> </td>
<td data-title="Remote"> </td>
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/vmanager/activate/{{ deploy.machine_id }}');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Activate</td>
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/vmanager/activate/{{ deploy.machine_id }}','_self');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Activate</td>
{% else %}
{% if deploy.warning == True %}
<tr class="warning">
@ -185,7 +186,8 @@ addEventListener("DOMContentLoaded", function() {
</tbody>
</table>
</div>
<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Create</button>
<!-- Cloud Storage icon by Icons8 -->
<button class="btn btn-default" onclick="window.open('{{ url_for('vmanager.createvm') }}','_self')"><img class="icon icons8-Cloud-Storage" width="40" height="40" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAEEklEQVRYhe3Xy0/bBhwHcA6btEMP0077A3boYYdK23EHLiQ0hQBtVC1S9zjs0L069TCkSUWNpgZCshDYItZOI+tKH7Cibgw6Wu2RAXWMYyc8mpAoUAIEp6VuTR5OwAnJd5dBEbYJKDSA1J/0PfjgXz6y5W/ssrKDNm9dYl4+aqYeq00kSpnK5pGUusX1WkGgxux+/ePLvmQ4lkcp88nPfkHV6DpcEFhpGnnH2D8XKzXwQv98UtXoqioIVDeRH/1IcKlSAzsIbqXSTJ0tCKy2uNt/uy+slhrYez8JrY25XhCotdKDgzNiSXHhWB5DYRFaK+0tfAWt9Pzow9WSA8cereKYheILAo/bGDHE72z5n8E46rsC0LXR0LXRqO8K4O5kbEc7pvg8TrQxuXKD8xVFnLrJ9canVyYTO1k84FvCe+1eXCcWwPLLYPlldJMsPrg4ipsMtyPkmasBQWUk3twKWGm8PRff7kImsoxT7V5MLwrYPPNP0tDbPfh3KrltoGkgIqgaXbVbAT9zuLi00oIHfA6O4ShOOyZQZaFQZ3Pjbx8nwa3NcPAp1CYSersH529NwcuubAn8iXya0VjcXykCtVa6o9cn5JVwZzr9OHcziNBDAWI2hzCXwmourwgEAF7IgEuI6CJZ6FppMJFlRWCfX0BNq6dLEVjdQlODYfmK6RiK4twvwS0xheYasYCGnpAi8N6sCK2V8SsCq76hFsce5WRPPu2YQIBNFgXkEiL0do8icGIxB42Fisviyg3Ol463MtkpmYoZj4qoslAQs7migACgNpFo7Hsge6unl/I4+Z0nW25wHpIAVY2uw593BiQVMx4V8eGlMVwZjhSNA4B4OgtL/zROfsvIIs/eCAoVRuKIHLC26Y+IBGjqn0GHc25XcBvnh39mcaF3WgK03F1IqZoJnQR41EzVO1xPVjaf8P73o2D55V0HTi8K0LXREmAnxWe1VtogrZgW+sbvPkFygt7uAZcQdx2o9MDcnkyh1sb8KgNkvEMyFXP+1hS6SXbXgd0kK1s5rrkMalqYSQlQY6HichXjZVdwqt2LHioKXsgUDeMSIrpJFnU2N9xzacnv+R7noDFTwuaKOXSizSPKVcwasqEnhDqbu+iPI73dg4aekCwuHMtjZikPvd2TLTc4X10HVhiJI19cDe7oLeZ55suukFDRfO/tZxXTTOhMdxZK/iWnFNtf0bTKRLy7DjxmcX99meLFvYat5RodW61uYZo2PsH9fX5pxexV7gTTqGn1DGzswODwbGbPYWsZiWSgtTGhZxVjpoTxRfm3mL2In8tBY6ZS60C1icRFJrevojaReAF8bkAykkcqAxDz+W0dFxOlXVsCU///5aYy2NZxMVHadbCv4H7IC+CuA/djyg7C/AeJ36h1J+7ehgAAAABJRU5ErkJggg=="> Create</button>
</div>
</div>
</div>
@ -220,10 +222,10 @@ addEventListener("DOMContentLoaded", function() {
<td data-title="Description" >{{ service.description }}</td>
<td data-title="Last Charged">{{ moment(service.date_last_charge).format('lll') }} ({{ moment(service.date_last_charge).fromNow() }})</td>
{% if service.enabled == False %}
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/smanager/activate/{{ service.pid }}');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Activate</button></td>
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/smanager/activate/{{ service.pid }}','_self');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Activate</button></td>
{% else %}
{% if service.warning == True %}
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/smanager/activate/{{ service.pid }}');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Renew ({{ service.daysleft }} days left)</button></td>
<td data-title="Time Left"><button class="btn btn-default btn-success" onclick="window.open('/smanager/activate/{{ service.pid }}','_self');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Renew ({{ service.daysleft }} days left)</button></td>
{% else %}
<td data-title="Time Left">{{ service.daysleft }} day(s)</td>
{% endif %}
@ -233,7 +235,8 @@ addEventListener("DOMContentLoaded", function() {
</tbody>
</table>
</div>
<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Order</button>
<img class="icon icons8-Key-2" width="40" height="40" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAADwUlEQVRYhdXYz0/bVhwA8Bz4I/Yn9A/gwKGHHApxiENwo8IG2rSqh/XUw267cRmJY8dOQpIGOq2cdtguFZNoUQQeiOBnm7h4iB+TRkJwkiJtdZ0GQzPLeTtU0bIQ0qQ8wP1K30sU6X3y/X7fs18cjk89Bsn1fjwEAgQj7nhpQXMFeeilBY1gpV2cFkgsCG7fCAwL8E5fWBQmk7IeX1bNTM6ASrkG83odKuUazOQMGF9WzYmEXP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ick="window.open('{{ url_for('smanager.requestservice') }}','_self')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Send Request</button>
</div>
</div>
</div>
@ -261,7 +264,7 @@ addEventListener("DOMContentLoaded", function() {
<td data-title="Time Left">EXPIRED</td>
{% else %}
{% if domain.warning == True %}
<td data-title="Time Left"><button class="btn btn-default btn-warning" onclick="window.open('/dmanager/activate/{{ domain.pid }}');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Renew </button></td>
<td data-title="Time Left"><button class="btn btn-default btn-warning" onclick="window.open('/dmanager/activate/{{ domain.pid }}','_self');"><span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Renew </button></td>
{% else %}
<td data-title="Time Left">{{ domain.daysleft }} day(s)</td>
{% endif %}
@ -272,7 +275,9 @@ addEventListener("DOMContentLoaded", function() {
</tbody>
</table>
</div>
<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Order</button>
<!-- Address Book icon by Icons8 -->
<img class="icon icons8-Address-Book" width="40" height="40" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAACOElEQVRYhe2Y3W7aQBCF83ZIVdTn4iK973tUCo1KoVVbCC0hSqUoKrKxoQYDCf5BGBtjz+nFeMFO41RtyIIqjzTCs1jMt7OzZ7GPjgrboR2ffK2Wyk3sw49PWm/+CFgqN/G6HW+8VG7iVCEpXio3UQD+94DCX+T1474B03kLwAKwAJQJWNUI17eEvgs4AbBcA1MP0BzgwtwzYMckrCIgigHLZyjFAswFsAgBAJgtgc8/9wA4nDPA1ANq+sP3XI4J/hogAr48ApkW6pevWuMnA15NCADQs5EZ/9jnJT9VCHWdr2s6IYwBLwTOevmAwp5cwarGCRchUFF5rGEQlutNDvRs/tQdZCakWHh+wJs7TnY+5PhDnxATEERAe0T4NqJN/3UToLcqgQiYeBIAzQX/kFiugctxx/x9Et+n2zE3APy1BMD5iqVExKJa71L9JZb0crwds30gjCUARjHrnYhjAtwgm7hrcbKGwXFF5fucQAKgE7DupeP7lbF9ZPq0YXBFNUcCYD/puXqifUpSretb3gw3d4Spx2Oqzb069XhS7zUJMiP6y5hzNT4N+DQR5gYsP35KdoIIaBoShXq25MStZAlrOp8a50PaaONZj3BhEtojymygPEDNIWjOI88nfwNY13mzxAT8mG2h7ntFzf/uWQEF5CTpNS/kPwhdC7ia8C4euMAq2vaqdEDhHZPF2vax6UV/zZKiWPnnrzTAXXgBWAAeAmBKqA/z1ceDUAXgLgEP/hVwYf9gvwBORombjyORBAAAAABJRU5ErkJggg==">
<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}','_self')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Order</button>
</div>
</div>
</div>
@ -304,7 +309,9 @@ addEventListener("DOMContentLoaded", function() {
</tbody>
</table>
</div>
<!--<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Assign</button> -->
<!-- GPS Signal icon by Icons8 -->
<img class="icon icons8-GPS-Signal" width="40" height="40" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAEW0lEQVRYhe3YT0zbVhwH8HfgwKGHHnrYYYcddkBVT7t0kybNh8kvgTiBJlTdhCba0R03qVo3NBUtUkv88sdOgtapYu0mFQ1tY4BGK9qKaZmYkud/BFzKyBYYGmgRNCGBjf+ovB0SVyklJHEM7aR9pafIVmJ//Ht5z34G4P8AAJHQDxHegm48bkJCj4nFzZQzdPRZux4nByT5jUYRGbK4xZATmFhM1XmFXsoZqtJ7DMoZOkK7IjWQxS0Q4aE87FcVVdPE4pdsnJQ816muWznxViXIXcdthm4hk0PO6EJSzlB1PS/9cX04kYwlt8m7nWr6dFD5qVwkREI/jfBa9jPSSjlDRwAAwOwWXoQI/6JVsmyg2YM/uvD15N8zSztkZmmHxJLb5L0b6lq5ldzjPxiiUf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U4IAAAAASUVORK5CYII=">
<!--<button class="btn btn-default" onclick="window.open('{{ url_for('main.dashboard') }}','_self')"><span class="glyphicon glyphicon-plus" aria-hiddent="true"></span> Assign</button> -->
</div>
</div>
</div>

View file

@ -1,4 +1,5 @@
<br /><br >
<div class="page_wrap">
<p class="copyright">&copy; Copyright 2017 <a href="https://deflax.net">_sys</a>, All Rights Reserved.</p>
<p class="design_by"></p>
<p class="copyright" style="color:#708d3f;">&copy; Copyright 2017 <a style="color:#88af46" href="https://deflax.net">_sys</a>, All Rights Reserved.</p>
<p class="design_by" style="color:#708d3f;">Icons by <a style="color:#88af46" href="https://icons8.com">icons8.com</a></p>
</div><!--/page wrap-->

View file

@ -0,0 +1,53 @@
{% extends "base.html" %}
{% block head %}
{{ super() }}
<script type="text/javascript">
function getRecipeName()
{
var rselect = document.getElementById('recipe');
recipe = rselect.value;
return recipe;
}
function previewDetails()
{
var period = getRecipeName();
var divobj = document.getElementById('recipedetails');
divobj.innerHTML = "not implemented";
}
</script>
{% endblock %}
{% block title %}Apply Recipe{% endblock %}
{% block page_content %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Apply Recipe {{ deploy.machine_alias }}</div>
<div class="panel-body">
<form method="POST" action"{{ url_for('vmanager.recipe', itemid=deploy.machine_id) }}">
<h3>
{{ form.recipe.label }} {{ form.recipe(**{"onchange":"previewDetails()"}) }}<br />
{% for error in form.recipe.errors %}
{{ error }}<br />
{% endfor %}
---<br />
<div id="recipedetails">Preview</div>
</h3>
<p>
{{ form.csrf_token() }}
{{ form.submit }}
</p>
</div>
</div>
</div>
{% endblock %}

View file

@ -19,11 +19,6 @@ import ast
def randstr(n):
return ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(n))
#@vmanager.before_app_request
#def before_request():
# g.user = current_user
# print('current_user: %s, g.user: %s, leaving bef_req' % (current_user, g.user))
@vmanager.after_app_request
def after_request(response):
for query in get_debug_queries():
@ -31,58 +26,19 @@ 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))
return response
#APP STORE
@vmanager.route('/market/<int:group_id>', methods=['GET'])
@vmanager.route('/createvm', methods=['GET', 'POST'])
@login_required
def market(group_id=0):
page = { 'title': 'Market' }
allproducts = Product.get_products()
allgroups = current_app.config['GROUPS']
if group_id == 0:
return render_template('vmanager/market.html', groups=allgroups, products=allproducts)
filtered_products = {}
for key, value in allproducts.items():
if value['group'] == group_id:
filtered_products[key] = value
if filtered_products == {}:
abort(404)
return render_template('vmanager/marketgroup.html', groupname=allgroups[group_id], products=filtered_products)
@vmanager.route('/deploy/<int:product_id>', methods=['GET', 'POST'])
@login_required
def deploy(product_id=None):
#if current_user.wallet < 20:
# flash('Недостатъчно средства в сметката за тази операция')
# return redirect(url_for('uinvoice.addfunds'))
def createvm():
if current_user.name is None:
flash('Please update profile info for this operation.')
return redirect(url_for('uinvoice.profile'))
page = { 'title': 'Deploy' }
try:
product = Product.get_products()[product_id]
except:
current_app.logger.error('unknown product {}'.format(product_id))
abort(404)
product_pic = '..' + product['img']
product_name = product['name']
product_description = product['description']
return redirect(url_for('settings.profile'))
product_cpu = product['cpu']
product_mem = product['mem']
product_hdd = product['hdd']
product_recipe = product['recipe']
hostname = 'deploy-{}.local'.format(randstr(6))
form = DeployForm(servername=hostname, cpu=product_cpu, mem=product_mem, hdd=product_hdd, recipe=product_recipe)
form.region.choices = current_app.config['REGIONS']
form.recipe.choices = current_app.config['RECIPES']
deployment_seeds = Deployment.query.filter_by(protected=False).all()
if deployment_seeds != []:
flash('Offline deployments exist.')
return redirect(url_for('main.dashboard'))
if current_user.confirmed and form.validate_on_submit():
client_id = current_user.pid
@ -93,7 +49,6 @@ def deploy(product_id=None):
'vmpass': form.vmpassword.data,
'region': form.region.data,
'vps_type': 'kvm',
'vps_recipe': form.recipe.data,
'vps_cpu': form.cpu.data,
'vps_mem': form.mem.data,
'vps_hdd': form.hdd.data,
@ -117,7 +72,6 @@ def deploy(product_id=None):
return redirect(url_for('main.dashboard'))
return render_template('vmanager/deploy.html', page=page, form=form, product_id=product_id, product_pic=product_pic, product_name=product_name, product_description=product_description, product_recipe=product_recipe)
@vmanager.route('/activate/<int:itemid>', methods=['GET', 'POST'])
@login_required
@ -173,6 +127,7 @@ def activate(itemid=0):
return redirect(url_for('main.dashboard'))
return render_template('vmanager/activate.html', form=form, deploy=deploy, cpu_cost=cpu_cost, mem_cost=mem_cost, hdd_cost=hdd_cost, ppm=ppm, total=(ppm * deploy.period), currency=owner.currency)
@vmanager.route('/<cmd>/<int:vmid>')
@login_required
def command(cmd=None, vmid=0):
@ -205,3 +160,23 @@ def command(cmd=None, vmid=0):
return redirect(db_result['url'])
abort(404)
#APP STORE
@vmanager.route('/market/<int:group_id>', methods=['GET'])
@login_required
def market(group_id=0):
page = { 'title': 'Market' }
allproducts = Product.get_products()
allgroups = current_app.config['GROUPS']
if group_id == 0:
return render_template('vmanager/market.html', groups=allgroups, products=allproducts)
filtered_products = {}
for key, value in allproducts.items():
if value['group'] == group_id:
filtered_products[key] = value
if filtered_products == {}:
abort(404)
return render_template('vmanager/marketgroup.html', groupname=allgroups[group_id], products=filtered_products)