adapt create data json

This commit is contained in:
deflax 2018-04-02 15:44:33 +03:00
parent 5d088b7dd7
commit 00e0848d26
3 changed files with 13 additions and 13 deletions

View file

@ -9,8 +9,8 @@ class OrderForm(FlaskForm):
region_choices = [(1, 'Plovdiv, Bulgaria'), (2, 'International Space Station')] region_choices = [(1, 'Plovdiv, Bulgaria'), (2, 'International Space Station')]
region = SelectField('Region:', choices=region_choices, coerce=int) region = SelectField('Region:', choices=region_choices, coerce=int)
vmtype_choices = [(1, 'RootVPS')] recipe_choices = [(1, 'RootVPS')]
vmtype = SelectField('Type:', choices=vmtype_choices, coerce=int) recipe = SelectField('Type:', choices=recipe_choices, coerce=int)
cpu = DecimalRangeField('Processor Cores', default=2) cpu = DecimalRangeField('Processor Cores', default=2)
memory = DecimalRangeField('Memory', default=2048) memory = DecimalRangeField('Memory', default=2048)

View file

@ -46,8 +46,8 @@ function storageUpdate(value) {
<div class="panel-heading">2. Image</div> <div class="panel-heading">2. Image</div>
<div class="panel-body"> <div class="panel-body">
<p> <p>
{{ form.vmtype.label }}<br /> {{ form.vmtype }}<br /> {{ form.recipe.label }}<br /> {{ form.recipe }}<br />
{% for error in form.vmtype.errors %} {% for error in form.recipe.errors %}
{{ error }}<br /> {{ error }}<br />
{% endfor %} {% endfor %}
</p> </p>

View file

@ -74,14 +74,14 @@ def vmcreate(orderid):
form = SlaveForm() form = SlaveForm()
if form.validate_on_submit(): if form.validate_on_submit():
data = { 'clientid': str(current_user.pid), data = { 'clientid': str(order.user_id),
'clientemail': str(current_user.email), 'clientemail': str(order.owner.email),
'hostname': 'c' + str(current_user.pid) + '-' + str(form.servername.data), 'hostname': 'c' + str(order.user_id) + '-' + str(order.parameter1),
'region': str(selected_region.name), 'region': str(order.region.name),
'type': 'kvm', 'type': 'kvm',
'cpu': '1', 'cpu': str(int(order.parameter2)),
'mem': '512', 'mem': str(int(order.parameter3)),
'hdd': '20', 'hdd': str(int(order.parameter4)),
'net0if': 'vmbr7' 'net0if': 'vmbr7'
} }
try: try:
@ -92,7 +92,7 @@ def vmcreate(orderid):
if query['status'] == 'kvm_created': if query['status'] == 'kvm_created':
selected_slave = Server.query.filter_by(name=query['slave']).first() selected_slave = Server.query.filter_by(name=query['slave']).first()
deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), period=1, 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)) deployment = Deployment(user_id=order.user_id, machine_alias=str(order.parameter1), period=1, 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.add(deployment)
db.session.commit() db.session.commit()
@ -103,7 +103,7 @@ def vmcreate(orderid):
order.status = 'accepted' order.status = 'accepted'
db.session.update(order) db.session.update(order)
db.session.commit() db.session.commit()
flash('A new deployment is created successfully in region "{}".'.format(str(selected_region.description))) flash('A new deployment is created successfully in region "{}".'.format(str(order.region.description)))
return redirect(url_for('panel.dashboard')) return redirect(url_for('panel.dashboard'))
else: else:
flash('Deployment could not be created! Please try again later...') flash('Deployment could not be created! Please try again later...')