Commit 17865cff authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

cyclades: Small bug fixes in logic/subnets.py

parent dea662ae
......@@ -109,7 +109,9 @@ def create_subnet(request):
name = subnet.get('name', None)
ipversion = subnet.get('ip_version', 4)
gateway = subnet.get('gateway_ip', None)
# If no gateway is specified, send an empty string, because None is used
# if the user wants no gateway at all
gateway = subnet.get('gateway_ip', "")
dhcp = subnet.get('enable_dhcp', True)
slac = subnet.get('enable_slac', None)
dns = subnet.get('dns_nameservers', None)
......
......@@ -44,7 +44,7 @@ from snf_django.lib.api import utils
from synnefo.db.models import Subnet, Network, IPPoolTable
from synnefo.logic import networks
from ipaddr import IPv4Network, IPv6Network, IPv4Address, IPAddress, IPNetwork
from ipaddr import IPv4Address, IPAddress, IPNetwork
log = getLogger(__name__)
......@@ -85,15 +85,16 @@ def create_subnet(network_id, cidr, name, ipversion, gateway, dhcp, slac,
if ipversion not in [4, 6]:
raise api.faults.BadRequest("Malformed IP version type")
check_number_of_subnets(network, ipversion)
# Returns the first available IP in the subnet
if ipversion == 6:
potential_gateway = str(IPv6Network(cidr).network + 1)
check_number_of_subnets(network, 6)
else:
potential_gateway = str(IPv4Network(cidr).network + 1)
check_number_of_subnets(network, 4)
try:
cidr_ip = IPNetwork(cidr)
except ValueError:
raise api.faults.BadRequest("Malformed CIDR")
potential_gateway = str(IPNetwork(cidr).network + 1)
if gateway is None:
if gateway is "":
gateway = potential_gateway
if ipversion == 6:
......@@ -109,7 +110,6 @@ def create_subnet(network_id, cidr, name, ipversion, gateway, dhcp, slac,
name = check_name_length(name)
gateway_ip = IPAddress(gateway)
cidr_ip = IPNetwork(cidr)
sub = Subnet.objects.create(name=name, network=network, cidr=cidr,
ipversion=ipversion, gateway=gateway,
......
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