Commit aec96e6d authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Fix indentation, PEP8 and wrong imports

parent 2bd35f31
......@@ -23,8 +23,9 @@ log = getLogger(__name__)
urlpatterns = patterns(
'synnefo.api.networks',
(r'^(?:/|.json|.xml)?$', 'demux'),
(r'^/(\w+)(?:/|.json|.xml)?$', 'network_demux'))
(r'^(?:/|.json|.xml)?$', 'demux'),
(r'^/(\w+)(?:/|.json|.xml)?$', 'network_demux'))
def demux(request):
if request.method == 'GET':
......@@ -88,7 +89,7 @@ def create_network(request):
try:
flavor = d['type']
except KeyError:
raise faults.BadRequest("Missing request parameter 'type'")
raise api.faults.BadRequest("Missing request parameter 'type'")
if flavor not in Network.FLAVORS.keys():
raise api.faults.BadRequest("Invalid network type '%s'"
......
......@@ -206,7 +206,7 @@ def get_flavor_provider(flavor):
disk_template, provider = disk_template.split("_", 1)
return disk_template, provider
'''
def get_network(network_id, user_id, for_update=False, non_deleted=False):
"""Return a Network instance or raise ItemNotFound."""
......@@ -222,26 +222,13 @@ def get_network(network_id, user_id, for_update=False, non_deleted=False):
return network
except (ValueError, Network.DoesNotExist):
raise faults.ItemNotFound('Network not found.')
'''
def get_network(network_id, user_id, public=False, for_update=False):
def get_port(port_id, user_id, for_update=False):
"""
Return a Network instance or raise ItemNotFound.
Return a NetworkInteface instance or raise ItemNotFound.
"""
try:
objects = Network.objects
if for_update:
objects = objects.select_for_update()
if public:
objects = objects.filter(public=True)
return objects.get(Q(userid=user_id) | Q(public=True), id=network_id)
except (ValueError, Network.DoesNotExist):
raise faults.ItemNotFound('Network not found.')
def get_port(port_id, user_id, for_update=False):
"""
Return a NetworkInteface instance or raise ItemNotFound.
"""
try:
objects = NetworkInterface.objects
if for_update:
objects = objects.select_for_update()
......@@ -249,11 +236,12 @@ def get_port(port_id, user_id, for_update=False):
port = objects.get(network__userid=user_id, id=port_id)
if (port.device_owner != "vm") and for_update:
raise api.faults.BadRequest('Can not update non vm port')
raise faults.BadRequest('Can not update non vm port')
return port
except (ValueError, NetworkInterface.DoesNotExist):
raise faults.ItemNotFound('Port not found.')
except (ValueError, NetworkInterface.DoesNotExist):
raise faults.ItemNotFound('Port not found.')
def get_floating_ip(user_id, ipv4, for_update=False):
try:
......
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