Commit 46272d40 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

snf-cyclades: Various bug fixes in cyclades

* When creating a new subnet, check if the given network_id is an int
* Remove duplicate code from api/networks
* Check name length when updating a server
* Check name length when updating a network
* Validate NIC ID is an int
parent f5e7dc5f
......@@ -117,8 +117,6 @@ def create_network(request):
flavor = api.utils.get_attribute(network_dict, "type",
attr_type=basestring)
if flavor not in Network.FLAVORS.keys():
raise api.faults.BadRequest("Invalid network type '%s'" % flavor)
if flavor not in settings.API_ENABLED_NETWORK_FLAVORS:
raise api.faults.Forbidden("Cannot create network of type '%s'." %
flavor)
......
......@@ -310,9 +310,12 @@ def backend_public_networks(backend):
def get_vm_nic(vm, nic_id):
"""Get a VMs NIC by its ID."""
try:
nic_id = int(nic_id)
return vm.nics.get(id=nic_id)
except NetworkInterface.DoesNotExist:
raise faults.ItemNotFound("NIC '%s' not found" % nic_id)
except (ValueError, TypeError):
raise faults.BadRequest("Invalid NIC ID '%s'" % nic_id)
def get_nic(nic_id):
......
......@@ -141,6 +141,8 @@ def create_network_in_backends(network):
@network_command("RENAME")
def rename(network, name):
utils.check_name_length(name, Network.NETWORK_NAME_LENGTH, "Network name "
"is too long")
network.name = name
network.save()
return network
......
......@@ -416,6 +416,9 @@ def console(vm, console_type):
def rename(server, new_name):
"""Rename a VirtualMachine."""
utils.check_name_length(new_name,
VirtualMachine.VIRTUAL_MACHINE_NAME_LENGTH,
"Server name is too long")
old_name = server.name
server.name = new_name
server.save()
......
......@@ -82,10 +82,14 @@ def _create_subnet(network_id, user_id, cidr, name, ipversion=4, gateway=None,
network_id and the desired cidr are mandatory, everything else is optional
"""
try:
network_id = int(network_id)
network = Network.objects.get(id=network_id)
except (ValueError, TypeError):
raise api.faults.BadRequest("Malformed network ID")
except Network.DoesNotExist:
raise api.faults.ItemNotFound("No network found with that id")
raise api.faults.ItemNotFound("No network found with that ID")
if network.deleted:
raise api.faults.BadRequest("Network has been deleted")
......
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