Commit c7920a85 by Dudás Ádám

vm: operation for adding a new network interface to a VM

parent 9dc923fd
...@@ -404,8 +404,7 @@ class VmDetailView(CheckedDetailView): ...@@ -404,8 +404,7 @@ class VmDetailView(CheckedDetailView):
if not vlan.has_level(request.user, 'user'): if not vlan.has_level(request.user, 'user'):
raise PermissionDenied() raise PermissionDenied()
try: try:
Interface.create(vlan=vlan, instance=self.object, self.object.add_interface(vlan=vlan, user=request.user)
managed=vlan.managed, owner=request.user)
messages.success(request, _("Successfully added new interface!")) messages.success(request, _("Successfully added new interface!"))
except Exception, e: except Exception, e:
error = u' '.join(e.messages) error = u' '.join(e.messages)
......
...@@ -10,7 +10,8 @@ from celery.exceptions import TimeLimitExceeded ...@@ -10,7 +10,8 @@ from celery.exceptions import TimeLimitExceeded
from common.operations import Operation, register_operation from common.operations import Operation, register_operation
from .tasks.local_tasks import async_instance_operation, async_node_operation from .tasks.local_tasks import async_instance_operation, async_node_operation
from .models import ( from .models import (
Instance, InstanceActivity, InstanceTemplate, Node, NodeActivity, Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity,
) )
...@@ -58,6 +59,29 @@ def register_instance_operation(op_cls, op_id=None): ...@@ -58,6 +59,29 @@ def register_instance_operation(op_cls, op_id=None):
return register_operation(Instance, op_cls, op_id) return register_operation(Instance, op_cls, op_id)
class AddInterfaceOperation(InstanceOperation):
activity_code_suffix = 'add_interface'
id = 'add_interface'
name = _("add interface")
description = _("Add a new network interface for the specified VLAN to "
"the VM.")
def _operation(self, activity, user, system, vlan, managed=None):
if managed is None:
managed = vlan.managed
net = Interface.create(base_activity=activity, instance=self.instance,
managed=managed, owner=user, vlan=vlan)
if self.instance.is_running:
net.deploy()
return net
register_instance_operation(AddInterfaceOperation)
class DeployOperation(InstanceOperation): class DeployOperation(InstanceOperation):
activity_code_suffix = 'deploy' activity_code_suffix = 'deploy'
id = 'deploy' id = 'deploy'
......
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