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
0cfffed4
authored
Apr 16, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor default network resource creations. Add Internet Access checkbox to plain VM creation,
parent
c4d12b46
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
26 deletions
+111
-26
.idea/workspace.xml
+0
-0
circle/circle/settings/base.py
+4
-0
circle/dashboard/forms.py
+1
-7
circle/dashboard/templates/dashboard/vm-plain-image-create.html
+1
-1
circle/dashboard/views/vm.py
+20
-12
circle/network/models.py
+85
-6
No files found.
.idea/workspace.xml
View file @
0cfffed4
This diff is collapsed.
Click to expand it.
circle/circle/settings/base.py
View file @
0cfffed4
...
...
@@ -582,6 +582,10 @@ DEFAULT_SUBNETPOOL_PREFIXES = (
)
DEFAULT_SUBNETPOOL_PREFIX_LEN
=
20
DEFAULT_PUBLIC_NETWORK_NAME
=
"public"
DEFAULT_PUBLIC_ROUTER_NAME_FOR_USER
=
"default_public"
DEFAULT_PUBLIC_ROUTED_NET_NAME_FOR_USER
=
"default_public_routed"
OPENSTACK_KEYSTONE_DEFAULT_DOMAIN
=
"bme"
OPENSTACK_KEYSTONE_URL
=
"https://oscircle.guest.ik.bme.hu:5000"
WEBSSO_ENABLED
=
True
#TODO: it is always enabled, refactor openstack_auth
...
...
circle/dashboard/forms.py
View file @
0cfffed4
...
...
@@ -120,9 +120,7 @@ class VmFromPlainImageForm(forms.Form):
'class'
:
"form-control input-tags"
,
}))
network
=
forms
.
ChoiceField
([],
widget
=
forms
.
Select
(
attrs
=
{
'class'
:
"form-control input-tags"
,
}))
internet_access
=
forms
.
BooleanField
(
initial
=
True
,
required
=
False
)
def
__init__
(
self
,
request
,
*
args
,
**
kwargs
):
super
(
VmFromPlainImageForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -145,10 +143,6 @@ class VmFromPlainImageForm(forms.Form):
(
flavor
.
id
,
'
%
s -
%
s CPUs,
%
s MB RAM'
%
(
flavor
.
name
,
flavor
.
vcpus
,
flavor
.
ram
))
for
flavor
in
flavors
)
networks
=
openstack_api
.
neutron
.
network_list_for_tenant
(
request
,
request
.
user
.
tenant_id
)
self
.
fields
[
'network'
]
.
choices
=
(
(
network
.
id
,
'
%
s'
%
(
network
.
name
))
for
network
in
networks
)
class
VmCustomizeForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
widget
=
forms
.
TextInput
(
attrs
=
{
...
...
circle/dashboard/templates/dashboard/vm-plain-image-create.html
View file @
0cfffed4
...
...
@@ -10,7 +10,7 @@
{{ form.name|as_crispy_field }}
{{ form.image|as_crispy_field }}
{{ form.flavor|as_crispy_field }}
{# {{ form.network|as_crispy_field }}#
}
{{ form.internet_access|as_crispy_field }
}
<button
class=
"btn btn-success btn-xs vm-create-start pull-right text-right"
type=
"submit"
>
<i
class=
"fa fa-play"
></i>
{% trans "Start" %}
</button>
...
...
circle/dashboard/views/vm.py
View file @
0cfffed4
...
...
@@ -48,6 +48,7 @@ from common.models import (
)
from
firewall.models
import
Vlan
,
Host
,
Rule
from
manager.scheduler
import
SchedulerError
from
network.models
import
DefaultPublicRouter
,
DefaultPublicRoutedNet
from
openstack_api.nova
import
Server
from
request.forms
import
TemplateRequestForm
from
request.models
import
TemplateAccessType
...
...
@@ -1049,18 +1050,25 @@ class VmPlainImageCreate(LoginRequiredMixin, TemplateView):
return
self
.
render_to_response
(
context
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
#TODO: if there is a network available use it, of there isn't use none
# there could be some checkboxes for the user to decide
# could create default network, setup internet access
server_created
=
openstack_api
.
nova
.
server_create
(
request
,
request
.
POST
.
get
(
"name"
),
request
.
POST
.
get
(
"image"
),
request
.
POST
.
get
(
"flavor"
),
# nics=({
# 'uuid': 'fc7ba14c-53d8-4810-9030-a0f00985c036'
# })
)
server_created
=
None
if
request
.
POST
.
get
(
"internet_access"
):
default_public_routed_net_id
=
DefaultPublicRoutedNet
.
get_id
(
request
)
server_created
=
openstack_api
.
nova
.
server_create
(
request
,
request
.
POST
.
get
(
"name"
),
request
.
POST
.
get
(
"image"
),
request
.
POST
.
get
(
"flavor"
),
nics
=
({
'net-id'
:
default_public_routed_net_id
,
},)
)
else
:
server_created
=
openstack_api
.
nova
.
server_create
(
request
,
request
.
POST
.
get
(
"name"
),
request
.
POST
.
get
(
"image"
),
request
.
POST
.
get
(
"flavor"
),
)
return
HttpResponseRedirect
(
"vm/
%
s#activity"
%
server_created
.
id
)
...
...
circle/network/models.py
View file @
0cfffed4
...
...
@@ -78,23 +78,101 @@ class Vxlan(models.Model):
class
SubnetPool
(
object
):
@classmethod
def
get
(
cls
,
request
):
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
(
def
__create_if_not_exists
(
cls
,
request
):
default_subnet_pool
=
SubnetPool
.
__get
(
request
)
if
default_subnet_pool
is
None
:
return
openstack_api
.
neutron
.
subnetpool_create
(
request
,
settings
.
DEFAULT_SUBNETPOOL_NAME_FOR_USER
,
settings
.
DEFAULT_SUBNETPOOL_PREFIXES
,
default_prefixlen
=
settings
.
DEFAULT_SUBNETPOOL_PREFIX_LEN
)
else
:
return
default_subnet_pool
@classmethod
def
get_id
(
cls
,
request
):
return
SubnetPool
.
get
(
request
)
.
id
return
SubnetPool
.
__create_if_not_exists
(
request
)
.
id
class
DefaultPublicRouter
(
object
):
@classmethod
def
__get_default_public_network
(
cls
,
request
):
nets
=
openstack_api
.
neutron
.
network_list
(
request
)
nets
=
[
n
for
n
in
nets
if
n
.
name
==
settings
.
DEFAULT_PUBLIC_NETWORK_NAME
]
return
nets
[
0
]
if
len
(
nets
)
>
0
else
None
user_logged_in
.
connect
(
SubnetPool
.
create_if_not_exists
)
@classmethod
def
__get
(
cls
,
request
):
routers
=
openstack_api
.
neutron
.
router_list
(
request
)
routers
=
[
rtr
for
rtr
in
routers
if
rtr
.
name
==
settings
.
DEFAULT_PUBLIC_ROUTER_NAME_FOR_USER
]
return
routers
[
0
]
if
len
(
routers
)
>
0
else
None
@classmethod
def
create_if_not_exists
(
cls
,
request
,
subnet_id
):
default_public_router
=
DefaultPublicRouter
.
__get
(
request
)
if
default_public_router
is
None
:
default_public_router
=
openstack_api
.
neutron
.
router_create
(
request
,
name
=
settings
.
DEFAULT_PUBLIC_ROUTER_NAME_FOR_USER
,
external_gateway_info
=
{
"network_id"
:
DefaultPublicRouter
.
__get_default_public_network
(
request
)
.
id
}
)
openstack_api
.
neutron
.
router_add_interface
(
request
,
default_public_router
.
id
,
subnet_id
=
subnet_id
)
return
default_public_router
class
DefaultPublicRoutedNet
(
object
):
@classmethod
def
__connect_router
(
cls
,
request
,
default_routed_net
):
DefaultPublicRouter
.
create_if_not_exists
(
request
,
default_routed_net
.
subnets
[
0
]
.
id
)
@classmethod
def
__create_network
(
cls
,
request
):
network_created
=
openstack_api
.
neutron
.
network_create
(
request
,
name
=
settings
.
DEFAULT_PUBLIC_ROUTED_NET_NAME_FOR_USER
)
try
:
# TODO: default ip version should read from SETTINGS
subnet_created
=
openstack_api
.
neutron
.
subnet_create
(
request
,
network_created
.
id
,
ip_version
=
4
,
subnetpool_id
=
SubnetPool
.
get_id
(
request
)
)
network_created
.
subnets
.
append
(
subnet_created
)
except
:
openstack_api
.
neutron
.
network_delete
(
request
,
network_created
.
id
)
# TODO: user friendly error handling
raise
Exception
(
"Could not create subnet for network, deleted network."
)
return
network_created
@classmethod
def
__get
(
cls
,
request
):
nets
=
openstack_api
.
neutron
.
network_list_for_tenant
(
request
,
request
.
user
.
project_id
)
nets
=
[
n
for
n
in
nets
if
n
.
name
==
settings
.
DEFAULT_PUBLIC_ROUTED_NET_NAME_FOR_USER
]
return
nets
[
0
]
if
len
(
nets
)
>
0
else
None
@classmethod
def
__create_if_not_exists
(
cls
,
request
):
default_routed_net
=
DefaultPublicRoutedNet
.
__get
(
request
)
if
default_routed_net
is
None
:
default_routed_net
=
DefaultPublicRoutedNet
.
__create_network
(
request
)
DefaultPublicRoutedNet
.
__connect_router
(
request
,
default_routed_net
)
return
default_routed_net
@classmethod
def
get_id
(
cls
,
request
):
return
DefaultPublicRoutedNet
.
__create_if_not_exists
(
request
)
.
id
\ No newline at end of file
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