Commit fe1928ae authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

cyclades: Fix some bugs in subnets

* Fix a bug, where a user could change the name of a subnet without
being the owner of said subnet.
* Fix two bugs in snf-manage subnet-create. Fix no-dhcp option and a
potential crash if the user specified an invalid IP version type.
* Fix a bug in logic/, where if the user specified a gateway
IP, the program crashed.
parent 1c591049
......@@ -72,7 +72,8 @@ class Command(BaseCommand):
" The IP must be inside the CIDR range and cannot be the"
" subnet or broadcast IP. If no value is specified, the"
" first available IP of the subnet will be used."),
make_option("--dhcp", action="store_true", dest="dhcp", default=True,
make_option("--no-dhcp", action="store_true", dest="dhcp",
help="True/False value for DHCP/SLAAC. True by default."),
make_option("--dns", dest="dns",
help="DNS nameservers to be used by the VMs in the subnet."
......@@ -92,22 +93,27 @@ class Command(BaseCommand):
cidr = options["cidr"]
if not network_id:
raise CommandError("network_id is mandatory")
raise CommandError("network-id is mandatory")
if not cidr:
raise CommandError("cidr is mandatory")
user_id = common.get_network(network_id).userid
name = options["name"]
allocation_pools = options["allocation_pools"]
ipversion = int(options["ipversion"])
ipversion = options["ipversion"]
if not ipversion:
ipversion = 4
ipversion = int(ipversion)
except ValueError:
raise CommandError("ip-version must be 4 or 6")
gateway = options["gateway"]
if not gateway:
gateway = ""
dhcp = options["dhcp"]
if not dhcp:
dhcp = True
dhcp = False if dhcp else True
dns = options["dns"]
host_routes = options["host_routes"]
......@@ -177,7 +177,7 @@ def update_subnet(request, sub_id):
name = subnet.get("name", None)
subnet_dict = subnet_to_dict(subnets.update_subnet(sub_id, name))
subnet_dict = subnet_to_dict(subnets.update_subnet(sub_id, name, user_id))
data = json.dumps({'subnet': subnet_dict})
return HttpResponse(data, status=200)
......@@ -129,8 +129,8 @@ def create_subnet(network_id, cidr, name, ipversion, gateway, dhcp, slac,
# If the gateway isn't the first available ip, create two different
# ip pools adjacent to said ip
allocation_pools.append([ + 1, gateway_ip - 1])
allocation_pools.append([gateway_ip + 1, cidr_ip.broadcast - 1])
allocation_pools = (([ + 1, gateway_ip - 1]),
([gateway_ip + 1, cidr_ip.broadcast - 1]))
if allocation_pools:
create_ip_pools(allocation_pools, cidr_ip, sub)
......@@ -158,7 +158,7 @@ def delete_subnet():
def update_subnet(sub_id, name):
def update_subnet(sub_id, name, user_id):
"""Update the fields of a subnet
Only the name can be updated
......@@ -170,6 +170,9 @@ def update_subnet(sub_id, name):
raise api.faults.ItemNotFound("Subnet not found")
if user_id !=
raise api.faults.Unauthorized("Unauthorized operation")
check_name_length(name) = name
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