Commit e092b35a by Bach Dániel

vm: remove ResourcesRequestOperation

parent aa47ae5b
......@@ -180,7 +180,11 @@ class ResourceChangeAction(RequestAction):
validators=[MinValueValidator(0)])
def accept(self, user):
self.instance.resources_request.async(user=user, resource_request=self)
self.instance.resources_change.async(
user=user, num_cores=self.num_cores, ram_size=self.ram_size,
max_ram_size=self.ram_size, priority=self.priority,
with_shutdown=True)
@property
def accept_msg(self):
......
......@@ -27,7 +27,7 @@ from vm.models import Instance, InstanceTemplate, Lease
from dashboard.models import Profile
from request.models import Request, LeaseType, TemplateAccessType
from dashboard.tests.test_views import LoginMixin
from vm.operations import ResourcesRequestOperation
from vm.operations import ResourcesOperation
class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
......@@ -85,9 +85,9 @@ class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
# workaround for NOSTATE
inst.emergency_change_state(new_state="STOPPED", system=True)
with patch.object(ResourcesRequestOperation, 'async') as mock_method:
with patch.object(ResourcesOperation, 'async') as mock_method:
mock_method.side_effect = (
new_request.action.instance.resources_request)
new_request.action.instance.resources_change)
new_request.accept(self.us)
inst = Instance.objects.get(pk=1)
......
......@@ -31,7 +31,7 @@ from request.models import (
ExtendLeaseAction, ResourceChangeAction,
)
from vm.models import Instance
from vm.operations import ResourcesRequestOperation
from vm.operations import ResourcesOperation
from request.tables import (
RequestTable, TemplateAccessTypeTable, LeaseTypeTable,
)
......@@ -91,7 +91,7 @@ class RequestDetail(LoginRequiredMixin, DetailView):
context = super(RequestDetail, self).get_context_data(**kwargs)
context['action'] = request.action
context['accept_states'] = ResourcesRequestOperation.accept_states
context['accept_states'] = ResourcesOperation.accept_states
return context
......
......@@ -1334,10 +1334,21 @@ class ResourcesOperation(InstanceOperation):
description = _("Change resources of a stopped virtual machine.")
acl_level = "owner"
required_perms = ('vm.change_resources', )
accept_states = ('STOPPED', 'PENDING', )
accept_states = ('STOPPED', 'PENDING', 'RUNNING')
def _operation(self, user, activity,
num_cores, ram_size, max_ram_size, priority):
num_cores, ram_size, max_ram_size, priority,
with_shutdown=False, task=None):
if self.instance.status == 'RUNNING' and not with_shutdown:
raise Instance.WrongStateError(self.instance)
try:
self.instance.shutdown(parent_activity=activity, task=task)
except Instance.WrongStateError:
pass
self.instance._update_status()
self.instance.num_cores = num_cores
self.instance.ram_size = ram_size
self.instance.max_ram_size = max_ram_size
......@@ -1354,32 +1365,6 @@ 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