Commit 340d9070 by Őry Máté

one: add renew function

parent 47e39346
......@@ -27,6 +27,7 @@ urlpatterns = patterns('',
url(r'^vm/resume/(?P<iid>\d+)/$', 'one.views.vm_resume', name='vm_resume'),
url(r'^vm/power_off/(?P<iid>\d+)/$', 'one.views.vm_power_off', name='vm_power_off'),
url(r'^vm/restart/(?P<iid>\d+)/$', 'one.views.vm_restart', name='vm_restart'),
url(r'^vm/renew/(?P<which>(suspend|delete))/(?P<iid>\d+)/$', 'one.views.vm_renew', name='vm_renew'),
url(r'^vm/port_add/(?P<iid>\d+)/$', 'one.views.vm_port_add', name='vm_port_add'),
url(r'^vm/port_del/(?P<iid>\d+)/(?P<proto>tcp|udp)/(?P<public>\d+)/$', 'one.views.vm_port_del', name='vm_port_del'),
url(r'^vm/saveas/(?P<vmid>\d+)$', 'one.views.vm_saveas', name='vm_saveas'),
......
......@@ -581,6 +581,14 @@ class Instance(models.Model):
self._change_state("POWEROFF")
def restart(self):
self._change_state("RESET")
def renew(self, which):
if which == 'suspend':
self.time_of_suspend = self.share.get_type()['suspendx']
elif which == 'delete':
self.time_of_delete = self.share.get_type()['deletex']
else:
raise ValueError('No such expiration type.')
self.save()
def save_as(self):
"""
Save image and shut down.
......
......@@ -72,6 +72,14 @@ $(function() {
e.preventDefault(); e.stopPropagation();
restart_vm($(this).data('id'), $(this).data('name'));
});
$('.renew-suspend-vm-button').click(function(e) {
e.preventDefault(); e.stopPropagation();
renew_suspend_vm($(this).data('id'))
});
$('.renew-delete-vm-button').click(function(e) {
e.preventDefault(); e.stopPropagation();
renew_delete_vm($(this).data('id'))
});
$('#new-wm-button').click(function() {
$('#modal').show();
$('#modal-container').html($('#new-wm').html());
......@@ -195,6 +203,20 @@ $(function() {
manage_vm(id, "resume")
}
/**
* Renew vm suspend time.
*/
function renew_suspend_vm(id) {
manage_vm(id, "renew/suspend")
}
/**
* Renew vm deletion time.
*/
function renew_delete_vm(id) {
manage_vm(id, "renew/delete")
}
/**
* Manage VM State generic
*/
......
......@@ -88,6 +88,9 @@
<li class="date">
{% trans "time of suspend"|capfirst %}:
<span class="value"> <abbr title="{{i.time_of_suspend}}">{{i.time_of_suspend|timeuntil}}</abbr>
<a href="#" class="renew-vm-button renew-suspend-vm-button" data-id="{{ i.id }}" title="{% trans "Renew suspend time" %}">
<img src="/static/icons/control-double.png" alt="{% trans "Renew suspend time" %}" />
</a>
</span>
</li>
{% endif %}
......@@ -95,6 +98,9 @@
<li class="date">
{% trans "time of delete"|capfirst %}:
<span class="value"> <abbr title="{{i.time_of_delete}}">{{i.time_of_delete|timeuntil}}</abbr>
<a href="#" class="renew-vm-button renew-delete-vm-button" data-id="{{ i.id }}" title="{% trans "Renew deletion time" %}">
<img src="/static/icons/control-double.png" alt="{% trans "Renew deletion time" %}" />
</a>
</span>
</li>
{% endif %}
......
......@@ -421,6 +421,16 @@ def vm_resume(request, iid, *args, **kwargs):
@login_required
@require_POST
def vm_renew(request, which, iid, *args, **kwargs):
try:
get_object_or_404(Instance, id=iid, owner=request.user).renew(which)
messages.success(request, _('Virtual machine is successfully renewed.'))
except:
messages.error(request, _('Failed to renew virtual machine.'))
return redirect('/')
@login_required
@require_POST
def vm_power_off(request, iid, *args, **kwargs):
try:
get_object_or_404(Instance, id=iid, owner=request.user).poweroff()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment