Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
17865cff
Commit
17865cff
authored
Oct 25, 2013
by
Dionysis Grigoropoulos
Browse files
cyclades: Small bug fixes in logic/subnets.py
parent
dea662ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
snf-cyclades-app/synnefo/api/subnets.py
View file @
17865cff
...
...
@@ -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
)
...
...
snf-cyclades-app/synnefo/logic/subnets.py
View file @
17865cff
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment