Commit 815d11ea by Kálmán Viktor

request: accept/decline requests

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