Commit a9cb4a8f by Bach Dániel

Merge branch 'issue-154'

Conflicts:
	circle/vm/operations.py
parents 5d753e30 e19eaa8e
...@@ -396,8 +396,7 @@ class VmDetailView(CheckedDetailView): ...@@ -396,8 +396,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)
......
...@@ -58,10 +58,6 @@ class Interface(Model): ...@@ -58,10 +58,6 @@ class Interface(Model):
return 'cloud-' + str(self.instance.id) + '-' + str(self.vlan.vid) return 'cloud-' + str(self.instance.id) + '-' + str(self.vlan.vid)
@property @property
def destroyed(self):
return self.instance.destroyed_at
@property
def mac(self): def mac(self):
try: try:
return self.host.mac return self.host.mac
...@@ -138,34 +134,16 @@ class Interface(Model): ...@@ -138,34 +134,16 @@ class Interface(Model):
return iface return iface
def deploy(self): def deploy(self):
if self.destroyed: queue_name = self.instance.get_remote_queue_name('net')
from .instance import Instance return net_tasks.create.apply_async(args=[self.get_vmnetwork_desc()],
raise Instance.InstanceDestroyedError(self.instance, queue=queue_name).get()
"The associated instance "
"(%s) has already been "
"destroyed" % self.instance)
net_tasks.create.apply_async(
args=[self.get_vmnetwork_desc()],
queue=self.instance.get_remote_queue_name('net'))
def shutdown(self): def shutdown(self):
if self.destroyed:
from .instance import Instance
raise Instance.InstanceDestroyedError(self.instance,
"The associated instance "
"(%s) has already been "
"destroyed" % self.instance)
queue_name = self.instance.get_remote_queue_name('net') queue_name = self.instance.get_remote_queue_name('net')
net_tasks.destroy.apply_async(args=[self.get_vmnetwork_desc()], return net_tasks.destroy.apply_async(args=[self.get_vmnetwork_desc()],
queue=queue_name) queue=queue_name).get()
def destroy(self): def destroy(self):
if self.destroyed:
return
self.shutdown()
if self.host is not None: if self.host is not None:
self.host.delete() self.host.delete()
......
...@@ -11,7 +11,8 @@ from celery.exceptions import TimeLimitExceeded ...@@ -11,7 +11,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,
) )
...@@ -56,6 +57,29 @@ class InstanceOperation(Operation): ...@@ -56,6 +57,29 @@ class InstanceOperation(Operation):
user=user) user=user)
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_operation(AddInterfaceOperation)
class DeployOperation(InstanceOperation): class DeployOperation(InstanceOperation):
activity_code_suffix = 'deploy' activity_code_suffix = 'deploy'
id = 'deploy' id = 'deploy'
...@@ -107,6 +131,7 @@ class DestroyOperation(InstanceOperation): ...@@ -107,6 +131,7 @@ class DestroyOperation(InstanceOperation):
if self.instance.node: if self.instance.node:
# Destroy networks # Destroy networks
with activity.sub_activity('destroying_net'): with activity.sub_activity('destroying_net'):
self.instance.shutdown_net()
self.instance.destroy_net() self.instance.destroy_net()
# Delete virtual machine # Delete virtual machine
...@@ -179,6 +204,23 @@ class RebootOperation(InstanceOperation): ...@@ -179,6 +204,23 @@ class RebootOperation(InstanceOperation):
register_operation(RebootOperation) register_operation(RebootOperation)
class RemoveInterfaceOperation(InstanceOperation):
activity_code_suffix = 'remove_interface'
id = 'remove_interface'
name = _("remove interface")
description = _("Remove the specified network interface from the VM.")
def _operation(self, activity, user, system, interface):
if self.instance.is_running:
interface.shutdown()
interface.destroy()
interface.delete()
register_operation(RemoveInterfaceOperation)
class ResetOperation(InstanceOperation): class ResetOperation(InstanceOperation):
activity_code_suffix = 'reset' activity_code_suffix = 'reset'
id = 'reset' id = '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