39 QEMU virtual machines
This commit is contained in:
parent
4c0afeb1f7
commit
c44c890cde
4 changed files with 54 additions and 12 deletions
|
@ -6,7 +6,9 @@ class ControllerVMS(object):
|
|||
self.user_id = user_id
|
||||
pass
|
||||
|
||||
def get(self):
|
||||
def get(self, vm_id=None):
|
||||
if vm_id:
|
||||
return Vms.select().where(Vms.user == self.user_id, Vms.id == vm_id).get()
|
||||
return Vms.select().where(Vms.user == self.user_id)
|
||||
|
||||
def create(self, datacenter_id, server_id, vm_id,
|
||||
|
@ -27,3 +29,8 @@ class ControllerVMS(object):
|
|||
status=status
|
||||
)
|
||||
return True
|
||||
|
||||
def exists(self, vm_id):
|
||||
if Vms.select().where(Vms.user == self.user_id, Vms.id == vm_id).count() == 0:
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{# { url_for('vm.settings', vm_id=vm.id) } #}">Настройки</a>
|
||||
<a href="{{ url_for('vms.settings', vm_id=vm.id) }}">Настройки</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
35
SWSCloudCore/templates/default/vms/settings.html
Normal file
35
SWSCloudCore/templates/default/vms/settings.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% extends "default/_layout.html" %}
|
||||
|
||||
{% block title %}Статистика{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<h3>Настройки</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<h4>Статус</h4>
|
||||
{% if vm.status == 0 %}
|
||||
<p style="color: red">Неактивен</p>
|
||||
{% else %}
|
||||
<p style="color: green">Активен</p>
|
||||
{% endif %}
|
||||
<form action="{{ url_for('vms.settings', vm_id=vm.id) }}" method="post">
|
||||
<input type="hidden" name="action" value="set_status">
|
||||
<div class="input-group">
|
||||
<select name="status">
|
||||
<option value="active">Активировать</option>
|
||||
<option value="inactive">Деактивировать</option>
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" value="Изменить статус" class="button success small">
|
||||
</form>
|
||||
<h4>Удалить</h4>
|
||||
<a href="{{ url_for('vms.delete', vm_id=vm.id) }}">
|
||||
<button class="button alert">Удалить</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -182,8 +182,8 @@ def create():
|
|||
)
|
||||
|
||||
|
||||
@viewVMs.route('/delete/<uuid:container_id>.html', methods=['GET', 'POST'])
|
||||
def delete(container_id):
|
||||
@viewVMs.route('/delete/<uuid:vm_id>.html', methods=['GET', 'POST'])
|
||||
def delete(vm_id):
|
||||
# check session
|
||||
if not ControllerUsers().check_session():
|
||||
return redirect(url_for("account.logout"))
|
||||
|
@ -221,8 +221,8 @@ def delete(container_id):
|
|||
)
|
||||
|
||||
|
||||
@viewVMs.route('/settings/<uuid:container_id>', methods=['GET', 'POST'])
|
||||
def settings(container_id):
|
||||
@viewVMs.route('/settings/<uuid:vm_id>.html', methods=['GET', 'POST'])
|
||||
def settings(vm_id):
|
||||
# check session
|
||||
if not ControllerUsers().check_session():
|
||||
return redirect(url_for("account.logout"))
|
||||
|
@ -230,15 +230,15 @@ def settings(container_id):
|
|||
if not ControllerUsers().auth(session['email'], session['password']):
|
||||
return redirect(url_for("account.logout"))
|
||||
|
||||
containers = ControllerContainers(session['user_id'])
|
||||
vm = ControllerVMS(session['user_id'])
|
||||
|
||||
# check the user have a selected rule
|
||||
# if user not have a container then redirect to the container list
|
||||
if not containers.check_exists_item(container_id):
|
||||
return redirect(url_for('containers.index'))
|
||||
if not vm.exists(vm_id):
|
||||
return redirect(url_for('vms.index'))
|
||||
|
||||
# get container details
|
||||
container_details = containers.get_item(container_id)
|
||||
vm_details = vm.get(vm_id=vm_id)
|
||||
|
||||
if request.method == 'POST':
|
||||
if request.form['action'] == 'set_status':
|
||||
|
@ -273,8 +273,8 @@ def settings(container_id):
|
|||
return redirect(url_for('containers.settings', container_id=container_id))
|
||||
|
||||
return render_template(
|
||||
'default/containers/settings.html',
|
||||
container=container_details
|
||||
'default/vms/settings.html',
|
||||
vm=vm_details
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue