Commit 4264edba authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Add transaction control to API methods

Specially for create_instance and create_network methods, since a
VirtualMachine, Network object is created before sending the request
to the backend.
parent c0c976a2
......@@ -62,6 +62,7 @@ def server_action(name):
return func
return decorator
def network_action(name):
'''Decorator for functions implementing network actions.
`name` is the key in the dict passed by the client.
......@@ -85,11 +86,6 @@ def change_password(request, vm, args):
# buildInProgress (409),
# overLimit (413)
try:
password = args['adminPass']
except KeyError:
raise BadRequest('Malformed request.')
raise ServiceUnavailable('Changing password is not supported.')
@server_action('reboot')
......@@ -195,6 +191,7 @@ def revert_resize(request, vm, args):
raise ServiceUnavailable('Resize not supported.')
@server_action('console')
def get_console(request, vm, args):
"""Arrange for an OOB console of the specified type
......@@ -270,7 +267,9 @@ def get_console(request, vm, args):
return HttpResponse(data, mimetype=mimetype, status=200)
@server_action('firewallProfile')
@transaction.commit_on_success
def set_firewall_profile(request, vm, args):
# Normal Response Code: 200
# Error Response Codes: computeFault (400, 500),
......@@ -281,7 +280,7 @@ def set_firewall_profile(request, vm, args):
# itemNotFound (404),
# buildInProgress (409),
# overLimit (413)
profile = args.get('profile', '')
if profile not in [x[0] for x in NetworkInterface.FIREWALL_PROFILES]:
raise BadRequest("Unsupported firewall profile")
......@@ -322,6 +321,7 @@ def add(request, net, args):
@network_action('remove')
@transaction.commit_on_success
def remove(request, net, args):
# Normal Response Code: 202
# Error Response Codes: computeFault (400, 500),
......@@ -332,7 +332,7 @@ def remove(request, net, args):
# itemNotFound (404),
# overLimit (413)
try: #attachment string: nic-<vm-id>-<nic-index>
try: # attachment string: nic-<vm-id>-<nic-index>
server_id = args.get('attachment', None).split('-')[1]
nic_index = args.get('attachment', None).split('-')[2]
except IndexError:
......
......@@ -36,6 +36,7 @@ from logging import getLogger
from django.conf.urls.defaults import patterns
from django.conf import settings
from django.db.models import Q
from django.db import transaction
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson as json
......@@ -141,6 +142,7 @@ def list_networks(request, detail=False):
@util.api_method('POST')
@transaction.commit_on_success
def create_network(request):
# Normal Response Code: 202
# Error Response Codes: computeFault (400, 500),
......@@ -241,6 +243,7 @@ def update_network_name(request, network_id):
@util.api_method('DELETE')
@transaction.commit_on_success
def delete_network(request, network_id):
# Normal Response Code: 204
# Error Response Codes: computeFault (400, 500),
......
......@@ -36,6 +36,7 @@ from logging import getLogger
from django.conf import settings
from django.conf.urls.defaults import patterns
from django.db import transaction
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson as json
......@@ -183,6 +184,7 @@ def list_servers(request, detail=False):
@util.api_method('POST')
@transaction.commit_on_success
def create_server(request):
# Normal Response Code: 202
# Error Response Codes: computeFault (400, 500),
......@@ -331,6 +333,7 @@ def update_server_name(request, server_id):
@util.api_method('DELETE')
@transaction.commit_on_success
def delete_server(request, server_id):
# Normal Response Codes: 204
# Error Response Codes: computeFault (400, 500),
......@@ -475,6 +478,7 @@ def get_metadata_item(request, server_id, key):
@util.api_method('PUT')
@transaction.commit_on_success
def create_metadata_item(request, server_id, key):
# Normal Response Code: 201
# Error Response Codes: computeFault (400, 500),
......@@ -509,6 +513,7 @@ def create_metadata_item(request, server_id, key):
@util.api_method('DELETE')
@transaction.commit_on_success
def delete_metadata_item(request, server_id, key):
# Normal Response Code: 204
# Error Response Codes: computeFault (400, 500),
......
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