Commit 815d11ea by Kálmán Viktor

request: accept/decline requests

parent 11305fea
......@@ -22,16 +22,29 @@
{% if user.is_superuser %}
{% if ADMIN_ENABLED %}
<li>
<a href="/admin/"><i class="fa fa-cogs"></i> {% trans "Admin" %}</a>
<a href="/admin/">
<i class="fa fa-cogs"></i>
<span class="hidden-sm">{% trans "Admin" %}</span>
</a>
</li>
{% endif %}
<li>
<a href="{% url "dashboard.views.storage" %}"><i class="fa fa-database"></i>
{% trans "Storage" %}
<a href="{% url "dashboard.views.storage" %}">
<i class="fa fa-database"></i>
<span class="hidden-sm">{% trans "Storage" %}</span>
</a>
</li>
<li>
<a href="/network/"><i class="fa fa-globe"></i> {% trans "Network" %}</a>
<a href="{% url "network.index" %}">
<i class="fa fa-globe"></i>
<span class="hidden-sm">{% trans "Network" %}</span>
</a>
</li>
<li>
<a href="{% url "request.views.request-list" %}">
<i class="fa fa-phone"></i>
<span class="hidden-sm">{% trans "Requests" %}</span>
</a>
</li>
{% endif %}
<li>
......
......@@ -87,7 +87,8 @@ class Request(TimeStampedModel):
"DECLINED": "times",
}.get(self.status)
def accept(self):
def accept(self, user):
self.action.accept(user)
self.status = "ACCEPTED"
self.save()
......@@ -131,17 +132,17 @@ class ResourceChangeAction(RequestAction):
help_text=_('CPU priority.'),
validators=[MinValueValidator(0)])
def accept(self):
pass
# self.instance.change_resources(xy=xy)
def accept(self, user):
self.instance.resources_request.async(user=user, resource_request=self)
class ExtendLeaseAction(RequestAction):
instance = ForeignKey(Instance)
lease_type = ForeignKey(LeaseType)
def accept(self):
pass
def accept(self, user):
self.instance.renew(lease=self.lease_type.lease, save=True, force=True,
user=user)
class TemplateAccessAction(RequestAction):
......@@ -157,5 +158,6 @@ class TemplateAccessAction(RequestAction):
def get_readable_level(self):
return self.LEVELS[self.level]
def accept(self):
pass
def accept(self, user):
for t in self.template_type.templates.all():
t.set_user_level(self.user, self.level)
......@@ -3,7 +3,7 @@
{% load i18n %}
{% load render_table from django_tables2 %}
{% block title-page %}{% trans "Group list" %}{% endblock %}
{% block title-page %}{% trans "Request" %}{% endblock %}
{% block content %}
......@@ -16,7 +16,7 @@
</a>
<h3 class="no-margin">
<i class="fa fa-{{ object.get_request_icon }}"></i>
{% trans "Request" %}
{{ object.get_readable_type|capfirst }}
</h3>
</div>
<div class="panel-body">
......@@ -65,6 +65,11 @@
<dl>
<dt>{% trans "VM name" %}</dt>
<dd><a href="{{ action.instance.get_absolute_url }}">{{ action.instance.name }}</a></dd>
<dt>{% trans "Status" %}</dt>
<dd>
<i class="fa {{ action.instance.get_status_icon }}"></i>
{{ action.instance.get_status_display|upper }}
</dd>
<dt>{% trans "VM description" %}</dt>
<dd>{{ action.instance.description }}</dd>
<dt>
......@@ -89,20 +94,29 @@
{% csrf_token %}
<button class="btn btn-danger" type="submit">
<i class="fa fa-thumbs-down"></i>
nope
{% trans "Decline" %}
</button>
</form>
{{ acceptable_statuses }}
{% if object.type == "resource" and action.instance.status not in accept_states %}
{% trans "You can't accept this request because of the VM's state." %}
{% else %}
<form method="POST" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="accept" value="1"/>
<button class="btn btn-success">
<i class="fa fa-thumbs-up"></i>
yep
{% trans "Accept" %}
</button>
</form>
{% endif %}
</div>
{% else %}
close date
<div class="text-right">
{% blocktrans with close_date=object.modified %}
Closed at {{ close_date }}
{% endblocktrans %}
</div>
{% endif %}
</div><!-- .panel-body -->
</div>
......
......@@ -3,7 +3,7 @@
{% load i18n %}
{% load render_table from django_tables2 %}
{% block title-page %}{% trans "Group list" %}{% endblock %}
{% block title-page %}{% trans "Requests" %}{% endblock %}
{% block content %}
......@@ -11,16 +11,22 @@
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="no-margin"><i class="fa fa-group"></i> {% trans "Requests" %}</h3>
<a class="btn btn-xs btn-primary pull-right "href="{% url "request.views.type-list" %}">
{% trans "Request types" %}
</a>
<h3 class="no-margin"><i class="fa fa-phone"></i> {% trans "Requests" %}</h3>
</div>
<div class="panel-body">
<div id="table_container">
<div id="rendered_table" class="panel-body">
<div class="panel-body">
{% trans "Filter by status" %}:
<a href="{{ request.path }}">{% trans "ALL" %}</a>
{% for s in statuses %}
<a href="?status={{ s.0 }}">{{ s.1|upper }}</a>
{% endfor %}
<div class="table-responsive">
{% render_table table %}
</div>
</div>
</div>
</div><!-- .panel-body -->
</div>
</div>
......
......@@ -14,6 +14,7 @@ from request.models import (
ExtendLeaseAction, ResourceChangeAction,
)
from vm.models import Instance
from vm.operations import ResourcesRequestOperation
from request.tables import (
RequestTable, TemplateAccessTypeTable, LeaseTypeTable,
)
......@@ -47,12 +48,14 @@ class RequestDetail(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
template_name = "request/detail.html"
def post(self, *args, **kwargs):
if self.get_object().status in ["PENDING", "UNSEEN"]:
user = self.request.user
accept = self.request.POST.get("accept")
request = self.get_object() # not self.request!
if accept:
request.accept()
request.accept(user)
else:
request.decline()
request.decline(user)
return redirect(request.get_absolute_url())
......@@ -61,6 +64,7 @@ class RequestDetail(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
context = super(RequestDetail, self).get_context_data(**kwargs)
context['action'] = request.action
context['accept_states'] = ResourcesRequestOperation.accept_states
if request.status == Request.STATUSES.UNSEEN:
request.status = Request.STATUSES.PENDING
......
......@@ -1328,7 +1328,14 @@ class ResourcesOperation(InstanceOperation):
accept_states = ('STOPPED', 'PENDING', )
def _operation(self, user, activity,
num_cores, ram_size, max_ram_size, priority):
num_cores, ram_size, max_ram_size, priority,
with_shutdown=True):
if with_shutdown:
try:
self.instance.shutdown(parent_activity=activity,
user=user)
except Instance.WrongStateError:
pass
self.instance.num_cores = num_cores
self.instance.ram_size = ram_size
......@@ -1346,6 +1353,32 @@ class ResourcesOperation(InstanceOperation):
@register_operation
class ResourcesRequestOperation(InstanceOperation):
id = "resources_request"
name = _("resources request")
description = ""
required_perms = ()
accept_states = ("STOPPED", "RUNNING", "PENDING", )
async_queue = "localhost.man.slow"
def _operation(self, user, activity, resource_request, task=None):
try:
self.instance.shutdown(parent_activity=activity, task=task)
except Instance.WrongStateError:
pass
self.instance._update_status()
self.instance.resources_change(
parent_activity=activity,
num_cores=resource_request.num_cores,
ram_size=resource_request.ram_size,
max_ram_size=resource_request.ram_size,
priority=resource_request.priority
)
@register_operation
class PasswordResetOperation(RemoteAgentOperation):
id = 'password_reset'
name = _("password reset")
......
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