Commit 008b0e4a authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

cyclades: Pass action params in server_command

Commission to be issued depends on extra parameters for some actions,
e.g., on the flavor when resizing a vm.
parent 755aa5fe
......@@ -56,7 +56,7 @@ def validate_server_action(vm, action):
def server_command(action):
def server_command(action, action_fields=None):
"""Handle execution of a server action.
Helper function to validate and execute a server action, handle quota
......@@ -85,6 +85,7 @@ def server_command(action):
commission_name = "client: api, resource: %s" % vm
quotas.handle_resource_commission(vm, action=action,
......@@ -275,14 +276,19 @@ def reboot(vm, reboot_type):
return backend.reboot_instance(vm, reboot_type.lower())
def resize(vm, flavor):
action_fields = {"beparams": {"vcpus": flavor.cpu,
"maxmem": flavor.ram}}
comm = server_command("RESIZE", action_fields=action_fields)
return comm(_resize)(vm, flavor)
def _resize(vm, flavor):
old_flavor = vm.flavor
# User requested the same flavor
if ==
raise faults.BadRequest("Server '%s' flavor is already '%s'."
% (vm, flavor))
return None
# Check that resize can be performed
if old_flavor.disk != flavor.disk:
raise faults.BadRequest("Cannot resize instance disk.")
......@@ -290,13 +296,6 @@ def resize(vm, flavor):
raise faults.BadRequest("Cannot change instance disk template.")"Resizing VM from flavor '%s' to '%s", old_flavor, flavor)
commission_info = {"cyclades.cpu": flavor.cpu - old_flavor.cpu,
"cyclades.ram": 1048576 * (flavor.ram - old_flavor.ram)}
# Save serial to VM, since it is needed by server_command decorator
vm.serial = quotas.issue_commission(user=vm.userid,
name="resource: %s. resize" % vm)
return backend.resize_instance(vm, vcpus=flavor.cpu, memory=flavor.ram)
......@@ -151,7 +151,8 @@ class ServerCommandTest(TransactionTestCase):
vm = mfactory.VirtualMachineFactory(operstate="STOPPED")
self.assertRaises(faults.BadRequest, servers.stop, vm)
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
self.assertRaises(faults.BadRequest, servers.resize, vm)
flavor = mfactory.FlavorFactory()
self.assertRaises(faults.BadRequest, servers.resize, vm, flavor)
# Check that connect/disconnect is allowed only in STOPPED vms
# if hotplug is disabled.
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
......@@ -350,7 +350,7 @@ def reverse_quantities(resources):
def handle_resource_commission(resource, action, commission_name,
commission_info=None, force=False,
auto_accept=False, action_fields=None):
"""Handle a issuing of a commission for a resource.
Create a new commission for a resource based on the action that
......@@ -364,7 +364,8 @@ def handle_resource_commission(resource, action, commission_name,
# Check if action is quotable and issue the corresponding commission
serial = None
if commission_info is None:
commission_info = get_commission_info(resource, action=action)
commission_info = get_commission_info(
resource, action=action, action_fields=action_fields)
if commission_info is not None:
# Issue new commission, associate it with the resource
if commission_name is None:
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 to comment