Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e617a76
authored
Mar 07, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add subnet allocation from subnet pool on network creation
parent
1616b560
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
17 deletions
+40
-17
.idea/workspace.xml
+0
-0
circle/circle/settings/base.py
+3
-2
circle/network/models.py
+22
-12
circle/network/views.py
+15
-3
No files found.
.idea/workspace.xml
View file @
9e617a76
This diff is collapsed.
Click to expand it.
circle/circle/settings/base.py
View file @
9e617a76
...
...
@@ -576,4 +576,5 @@ USERNET_MAX = 2 ** 12
DEFAULT_SUBNETPOOL_NAME_FOR_USER
=
"default"
DEFAULT_SUBNETPOOL_PREFIXES
=
(
"10.0.0.0/8"
,
"172.16.0.0/12"
,
"192.168.0.0/16"
)
\ No newline at end of file
)
DEFAULT_SUBNETPOOL_PREFIX_LEN
=
20
\ No newline at end of file
circle/network/models.py
View file @
9e617a76
...
...
@@ -80,14 +80,25 @@ class Vxlan(models.Model):
def
get_absolute_url
(
self
):
return
reverse
(
'network.vxlan'
,
kwargs
=
{
'vni'
:
self
.
vni
})
def
create_subnet_pool
(
sender
,
user
,
request
,
**
kwargs
):
subnet_pools
=
openstack_api
.
neutron
.
subnetpool_list
(
request
)
subnet_pools
=
[
sp
for
sp
in
subnet_pools
if
sp
.
name
==
settings
.
DEFAULT_SUBNETPOOL_NAME_FOR_USER
]
if
(
len
(
subnet_pools
)
==
0
):
openstack_api
.
neutron
.
subnetpool_create
(
request
,
settings
.
DEFAULT_SUBNETPOOL_NAME_FOR_USER
,
settings
.
DEFAULT_SUBNETPOOL_PREFIXES
,
)
user_logged_in
.
connect
(
create_subnet_pool
)
\ No newline at end of file
class
SubnetPool
(
object
):
@classmethod
def
get
(
cls
,
request
):
subnet_pools
=
openstack_api
.
neutron
.
subnetpool_list
(
request
)
subnet_pools
=
[
sp
for
sp
in
subnet_pools
if
sp
.
name
==
settings
.
DEFAULT_SUBNETPOOL_NAME_FOR_USER
]
return
subnet_pools
[
0
]
if
len
(
subnet_pools
)
>
0
else
None
@classmethod
def
create_if_not_exists
(
cls
,
sender
,
user
,
request
,
**
kwargs
):
if
SubnetPool
.
get
(
request
)
is
None
:
openstack_api
.
neutron
.
subnetpool_create
(
request
,
settings
.
DEFAULT_SUBNETPOOL_NAME_FOR_USER
,
settings
.
DEFAULT_SUBNETPOOL_PREFIXES
,
default_prefixlen
=
settings
.
DEFAULT_SUBNETPOOL_PREFIX_LEN
)
@classmethod
def
get_id
(
cls
,
request
):
return
SubnetPool
.
get
(
request
)
.
id
user_logged_in
.
connect
(
SubnetPool
.
create_if_not_exists
)
circle/network/views.py
View file @
9e617a76
...
...
@@ -46,7 +46,7 @@ from firewall.models import (
SwitchPort
,
EthernetDevice
,
Firewall
)
from
netaddr
import
IPNetwork
from
network.models
import
Vxlan
,
EditorElement
from
network.models
import
Vxlan
,
EditorElement
,
SubnetPool
from
openstack_api.utils.lazy_encoder
import
LazyTranslationEncoder
from
vm.models
import
Interface
,
Instance
...
...
@@ -1002,8 +1002,20 @@ class VxlanCreate(LoginRequiredMixin, FormView):
if
form
.
cleaned_data
[
'isAdvancedConfig'
]:
pass
else
:
openstack_api
.
neutron
.
subnet_create
(
self
.
request
,
network_created
.
id
,
ip_version
=
4
)
# TODO: default ip version should read from SETTINGS
try
:
raise
Exception
# TODO: default ip version should read from SETTINGS
openstack_api
.
neutron
.
subnet_create
(
self
.
request
,
network_created
.
id
,
ip_version
=
4
,
subnetpool_id
=
SubnetPool
.
get_id
(
self
.
request
)
)
except
:
openstack_api
.
neutron
.
network_delete
(
self
.
request
,
network_created
.
id
)
#TODO: user friendly error handling
raise
Exception
(
"Could not create subnet for network, deleted network."
)
return
redirect
(
reverse_lazy
(
'network.vxlan'
,
kwargs
=
{
'pk'
:
network_created
.
id
}))
class
VxlanDelete
(
LoginRequiredMixin
,
DeleteView
):
#TODO: check user
...
...
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