Commit 700671ee authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Do not allow actions to deleted networks

parent 46360658
...@@ -254,6 +254,8 @@ def update_network_name(request, network_id): ...@@ -254,6 +254,8 @@ def update_network_name(request, network_id):
net = util.get_network(network_id, request.user_uniq) net = util.get_network(network_id, request.user_uniq)
if net.public: if net.public:
raise Unauthorized('Can not rename the public network.') raise Unauthorized('Can not rename the public network.')
if net.deleted:
raise Network.DeletedError
net.name = name net.name = name
net.save() net.save()
return HttpResponse(status=204) return HttpResponse(status=204)
...@@ -275,9 +277,13 @@ def delete_network(request, network_id): ...@@ -275,9 +277,13 @@ def delete_network(request, network_id):
if net.public: if net.public:
raise Unauthorized('Can not delete the public network.') raise Unauthorized('Can not delete the public network.')
if net.deleted:
raise Network.DeletedError
if net.machines.all(): # Nics attached on network if net.machines.all(): # Nics attached on network
raise NetworkInUse('Machines are connected to network.') raise NetworkInUse('Machines are connected to network.')
net.action = 'DESTROY' net.action = 'DESTROY'
net.save() net.save()
...@@ -295,6 +301,8 @@ def network_action(request, network_id): ...@@ -295,6 +301,8 @@ def network_action(request, network_id):
net = util.get_network(network_id, request.user_uniq) net = util.get_network(network_id, request.user_uniq)
if net.public: if net.public:
raise Unauthorized('Can not modify the public network.') raise Unauthorized('Can not modify the public network.')
if net.deleted:
raise Network.DeletedError
key = req.keys()[0] key = req.keys()[0]
val = req[key] val = req[key]
......
...@@ -393,6 +393,9 @@ def api_method(http_method=None, atom_allowed=False): ...@@ -393,6 +393,9 @@ def api_method(http_method=None, atom_allowed=False):
except VirtualMachine.DeletedError: except VirtualMachine.DeletedError:
fault = BadRequest('Server has been deleted.') fault = BadRequest('Server has been deleted.')
return render_fault(request, fault) return render_fault(request, fault)
except Network.DeletedError:
fault = BadRequest('Network has been deleted.')
return render_fault(request, fault)
except VirtualMachine.BuildingError: except VirtualMachine.BuildingError:
fault = BuildInProgress('Server is being built.') fault = BuildInProgress('Server is being built.')
return render_fault(request, fault) return render_fault(request, fault)
......
...@@ -460,6 +460,9 @@ class Network(models.Model): ...@@ -460,6 +460,9 @@ class Network(models.Model):
def __str__(self): def __str__(self):
return repr(str(self._action)) return repr(str(self._action))
class DeletedError(Exception):
pass
@property @property
def backend_id(self): def backend_id(self):
"""Return the backend id by prepending backend-prefix.""" """Return the backend id by prepending backend-prefix."""
......
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