Commit b663400a by Bach Dániel

vm: handle add_interface errors

fixes #223
parent f9d38eda
...@@ -94,12 +94,21 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -94,12 +94,21 @@ class AddInterfaceOperation(InstanceOperation):
"the VM.") "the VM.")
required_perms = () required_perms = ()
def rollback(self, net, activity):
with activity.sub_activity(
'destroying_net',
readable_name=ugettext_noop("destroy network (rollback)")):
net.destroy()
net.delete()
def check_precond(self): def check_precond(self):
super(AddInterfaceOperation, self).check_precond() super(AddInterfaceOperation, self).check_precond()
if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']: if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
raise self.instance.WrongStateError(self.instance) raise self.instance.WrongStateError(self.instance)
def _operation(self, activity, user, system, vlan, managed=None): def _operation(self, activity, user, system, vlan, managed=None):
if not vlan.has_level(user, 'user'):
raise PermissionDenied()
if managed is None: if managed is None:
managed = vlan.managed managed = vlan.managed
...@@ -107,8 +116,13 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -107,8 +116,13 @@ class AddInterfaceOperation(InstanceOperation):
managed=managed, owner=user, vlan=vlan) managed=managed, owner=user, vlan=vlan)
if self.instance.is_running: if self.instance.is_running:
try:
with activity.sub_activity('attach_network'): with activity.sub_activity('attach_network'):
self.instance.attach_network(net) self.instance.attach_network(net)
except Exception as e:
if hasattr(e, 'libvirtError'):
self.rollback(net, activity)
raise
net.deploy() net.deploy()
return net return net
......
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