Commit 269d97c7 by Kálmán Viktor

Merge branch 'master' into issue-vm-detail-fixes

parents dedcfc62 a9cb4a8f
......@@ -419,8 +419,7 @@ class VmDetailView(CheckedDetailView):
if not vlan.has_level(request.user, 'user'):
raise PermissionDenied()
try:
Interface.create(vlan=vlan, instance=self.object,
managed=vlan.managed, owner=request.user)
self.object.add_interface(vlan=vlan, user=request.user)
messages.success(request, _("Successfully added new interface!"))
except Exception, e:
error = u' '.join(e.messages)
......
......@@ -59,10 +59,6 @@ class Interface(Model):
return 'cloud-' + str(self.instance.id) + '-' + str(self.vlan.vid)
@property
def destroyed(self):
return self.instance.destroyed_at
@property
def mac(self):
try:
return self.host.mac
......@@ -139,34 +135,16 @@ class Interface(Model):
return iface
def deploy(self):
if self.destroyed:
from .instance import Instance
raise Instance.InstanceDestroyedError(self.instance,
"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'))
queue_name = self.instance.get_remote_queue_name('net')
return net_tasks.create.apply_async(args=[self.get_vmnetwork_desc()],
queue=queue_name).get()
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')
net_tasks.destroy.apply_async(args=[self.get_vmnetwork_desc()],
queue=queue_name)
return net_tasks.destroy.apply_async(args=[self.get_vmnetwork_desc()],
queue=queue_name).get()
def destroy(self):
if self.destroyed:
return
self.shutdown()
if self.host is not None:
self.host.delete()
......
......@@ -11,7 +11,8 @@ from celery.exceptions import TimeLimitExceeded
from common.operations import Operation, register_operation
from .tasks.local_tasks import async_instance_operation, async_node_operation
from .models import (
Instance, InstanceActivity, InstanceTemplate, Node, NodeActivity,
Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity,
)
......@@ -56,6 +57,29 @@ class InstanceOperation(Operation):
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):
activity_code_suffix = 'deploy'
id = 'deploy'
......@@ -107,6 +131,7 @@ class DestroyOperation(InstanceOperation):
if self.instance.node:
# Destroy networks
with activity.sub_activity('destroying_net'):
self.instance.shutdown_net()
self.instance.destroy_net()
# Delete virtual machine
......@@ -179,6 +204,23 @@ class RebootOperation(InstanceOperation):
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):
activity_code_suffix = '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