Revision 99718617 snf-cyclades-app/synnefo/logic/subnets.py
b/snf-cyclades-app/synnefo/logic/subnets.py | ||
---|---|---|
44 | 44 |
from synnefo.db.models import Subnet, Network, IPPoolTable |
45 | 45 |
from synnefo.logic import networks |
46 | 46 |
|
47 |
from ipaddr import IPv4Network, IPv6Network, IPv4Address, IPAddress, IPNetwork
|
|
47 |
from ipaddr import IPv4Address, IPAddress, IPNetwork |
|
48 | 48 |
|
49 | 49 |
log = getLogger(__name__) |
50 | 50 |
|
... | ... | |
85 | 85 |
if ipversion not in [4, 6]: |
86 | 86 |
raise api.faults.BadRequest("Malformed IP version type") |
87 | 87 |
|
88 |
check_number_of_subnets(network, ipversion) |
|
89 |
|
|
88 | 90 |
# Returns the first available IP in the subnet |
89 |
if ipversion == 6: |
|
90 |
potential_gateway = str(IPv6Network(cidr).network + 1) |
|
91 |
check_number_of_subnets(network, 6) |
|
92 |
else: |
|
93 |
potential_gateway = str(IPv4Network(cidr).network + 1) |
|
94 |
check_number_of_subnets(network, 4) |
|
91 |
try: |
|
92 |
cidr_ip = IPNetwork(cidr) |
|
93 |
except ValueError: |
|
94 |
raise api.faults.BadRequest("Malformed CIDR") |
|
95 |
potential_gateway = str(IPNetwork(cidr).network + 1) |
|
95 | 96 |
|
96 |
if gateway is None:
|
|
97 |
if gateway is "":
|
|
97 | 98 |
gateway = potential_gateway |
98 | 99 |
|
99 | 100 |
if ipversion == 6: |
... | ... | |
109 | 110 |
name = check_name_length(name) |
110 | 111 |
|
111 | 112 |
gateway_ip = IPAddress(gateway) |
112 |
cidr_ip = IPNetwork(cidr) |
|
113 | 113 |
|
114 | 114 |
sub = Subnet.objects.create(name=name, network=network, cidr=cidr, |
115 | 115 |
ipversion=ipversion, gateway=gateway, |
Also available in: Unified diff