Commit 034b1471 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Remove VM/Network DeletedError and BuildingError

Handle these errors explicitly in the code instead of the "api_method"
decorator.
parent ee570a7a
......@@ -282,7 +282,7 @@ def update_network_name(request, network_id):
if net.public:
raise faults.Forbidden('Can not rename the public network.')
if net.deleted:
raise Network.DeletedError
raise faults.BadRequest("Network has been deleted.")
net.name = name
net.save()
return HttpResponse(status=204)
......@@ -305,7 +305,7 @@ def delete_network(request, network_id):
raise faults.Forbidden('Can not delete the public network.')
if net.deleted:
raise Network.DeletedError
raise faults.BadRequest("Network has been deleted.")
if net.machines.all(): # Nics attached on network
raise faults.NetworkInUse('Machines are connected to network.')
......@@ -328,7 +328,7 @@ def network_action(request, network_id):
if net.public:
raise faults.Forbidden('Can not modify the public network.')
if net.deleted:
raise Network.DeletedError
raise faults.BadRequest("Network has been deleted.")
try:
key = req.keys()[0]
......
......@@ -513,11 +513,11 @@ def start_action(vm, action):
# No actions to deleted VMs
if vm.deleted:
raise VirtualMachine.DeletedError
raise faults.BadRequest("VirtualMachine has been deleted.")
# No actions to machines being built. They may be destroyed, however.
if vm.operstate == 'BUILD' and action != 'DESTROY':
raise VirtualMachine.BuildingError
raise faults.BuildInProgress("Server is being build.")
vm.action = action
vm.backendjobid = None
......
......@@ -470,15 +470,6 @@ def api_method(http_method=None, atom_allowed=False):
resp = func(request, *args, **kwargs)
update_response_headers(request, resp)
return resp
except VirtualMachine.DeletedError:
fault = faults.BadRequest('Server has been deleted.')
return render_fault(request, fault)
except Network.DeletedError:
fault = faults.BadRequest('Network has been deleted.')
return render_fault(request, fault)
except VirtualMachine.BuildingError:
fault = faults.BuildInProgress('Server is being built.')
return render_fault(request, fault)
except NotAllowedError:
# Image Backend Unathorized
fault = faults.Forbidden('Request not allowed.')
......
......@@ -395,12 +395,6 @@ class VirtualMachine(models.Model):
def __str__(self):
return repr(str(self._action))
class DeletedError(Exception):
pass
class BuildingError(Exception):
pass
class VirtualMachineMetadata(models.Model):
meta_key = models.CharField(max_length=50)
......@@ -578,12 +572,6 @@ class Network(models.Model):
def __str__(self):
return repr(str(self._action))
class DeletedError(Exception):
pass
class BuildingError(Exception):
pass
class BackendNetwork(models.Model):
OPER_STATES = (
......
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