Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
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
b89540e8
authored
Aug 28, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactor_template' into 'DEV'
Refactor template models, urls and views See merge request
!19
parents
19df44bb
46d067b1
Pipeline
#847
passed with stage
in 1 minute 20 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
77 deletions
+49
-77
recircle/template/models.py
+47
-76
recircle/template/urls.py
+1
-0
recircle/template/views.py
+1
-1
No files found.
recircle/template/models.py
View file @
b89540e8
...
...
@@ -8,71 +8,53 @@ from interface_openstack.implementation.storage.openstack_snapshot_manager impor
class
BaseTemplate
(
models
.
Model
):
"""Virtual machine template.
"""
name
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Human readable name of template."
)
description
=
models
.
TextField
(
verbose_name
=
"description"
,
blank
=
True
,
help_text
=
"Description of the template."
)
# remote_id = models.CharField(
# max_length=40,
# unique=True,
# verbose_name="remote_ID",
# help_text="ID, which helps access the template."
# )
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
,
editable
=
False
,
help_text
=
"Date, when the template created."
)
created_by
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
DO_NOTHING
,
related_name
=
"created_templates"
,
help_text
=
"The user, who create the template"
)
flavor
=
models
.
ForeignKey
(
Flavor
,
help_text
=
"Reasources given to the vm"
,
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
,
name
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Human readable name of template."
)
description
=
models
.
TextField
(
verbose_name
=
"description"
,
blank
=
True
,
help_text
=
"Description of the template."
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
,
editable
=
False
,
help_text
=
"Date, when the template created."
)
created_by
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
DO_NOTHING
,
related_name
=
"created_templates"
,
help_text
=
"The user, who create the template"
)
flavor
=
models
.
ForeignKey
(
Flavor
,
help_text
=
"Resources given to the vm"
,
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
,
related_name
=
'templates'
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
related_name
=
'templates'
)
network_id
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"network_id"
,
help_text
=
"The new instance will be in this network."
,
null
=
True
,
blank
=
True
)
network_id
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"network_id"
,
help_text
=
"The new instance will be in this network."
,
null
=
True
,
blank
=
True
)
class
DiskTemplate
(
BaseTemplate
):
disk
=
models
.
ForeignKey
(
Disk
,
related_name
=
"templates"
,
on_delete
=
models
.
CASCADE
,
help_text
=
"The disk where the template is located."
)
disk
=
models
.
ForeignKey
(
Disk
,
related_name
=
"templates"
,
on_delete
=
models
.
CASCADE
,
help_text
=
"The disk where the template is located."
)
@classmethod
def
create_from_volume
(
cls
,
name
,
description
,
disk
,
user
):
interface
=
SnapshotManager
(
settings
.
CONNECTION
)
remote_template
=
interface
.
create_from_volume
(
disk
.
remote_id
)
remote_id
=
remote_template
.
id
new_template
=
cls
.
create
(
name
=
name
,
description
=
description
,
disk
=
disk
,
remote_id
=
remote_id
,
created_by
=
user
)
new_template
=
DiskTemplate
.
objects
.
create
(
name
=
name
,
description
=
description
,
disk
=
disk
,
remote_id
=
remote_id
,
created_by
=
user
)
return
new_template
...
...
@@ -82,33 +64,22 @@ class ImageTemplate(BaseTemplate):
(
'I'
,
'Template created from instance'
),
(
'P'
,
'"Pure" template'
),
)
image
=
models
.
ForeignKey
(
Image
,
related_name
=
"templates"
,
on_delete
=
models
.
CASCADE
,
help_text
=
""
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
TYPES
,
default
=
"U"
)
@classmethod
def
create
(
cls
,
name
,
description
,
image
,
lease
,
flavor
,
created_by
,
type
=
'U'
):
inst
=
cls
(
name
=
name
,
description
=
description
,
image
=
image
,
lease
=
lease
,
flavor
=
flavor
,
created_by
=
created_by
,
type
=
type
)
inst
.
full_clean
()
inst
.
save
()
return
inst
image
=
models
.
ForeignKey
(
Image
,
related_name
=
"templates"
,
on_delete
=
models
.
CASCADE
,
help_text
=
""
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
TYPES
,
default
=
"U"
)
@classmethod
def
create_from_instance
(
cls
,
name
,
description
,
instance
,
user
):
image
=
Image
.
create_from_instance
(
user
,
instance
,
description
)
new_template
=
cls
.
create
(
name
=
name
,
description
=
description
,
created_by
=
user
,
image
=
image
,
lease
=
instance
.
lease
,
flavor
=
instance
.
flavor
,
type
=
"I"
)
new_template
=
ImageTemplate
.
objects
.
create
(
name
=
name
,
description
=
description
,
created_by
=
user
,
image
=
image
,
lease
=
instance
.
lease
,
flavor
=
instance
.
flavor
,
type
=
"I"
)
return
new_template
recircle/template/urls.py
View file @
b89540e8
from
rest_framework
import
routers
from
template
import
views
router
=
routers
.
DefaultRouter
()
...
...
recircle/template/views.py
View file @
b89540e8
# from django.shortcuts import render
from
rest_framework.response
import
Response
from
rest_framework.viewsets
import
ModelViewSet
from
template.serializers
import
ImageTemplateModelSerializer
from
template.models
import
ImageTemplate
...
...
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