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
183bc1db
authored
Jul 10, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement create from volume function
parent
a920b540
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
7 deletions
+33
-7
recircle/template/models.py
+33
-7
No files found.
recircle/template/models.py
View file @
183bc1db
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
image.models
import
Disk
from
image.models
import
Image
from
interface_openstack.implementation.storage.openstack_snapshot_manager
import
SnapshotManager
class
BaseTemplate
(
models
.
Model
):
...
...
@@ -29,7 +33,15 @@ class BaseTemplate(models.Model):
editable
=
False
,
help_text
=
"Date, when the template created."
)
# owner = models.ForeignKey(User)
created_by
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
DO_NOTHING
,
related_name
=
(
"created_templates"
)
)
# lease
# flavour
class
Template
(
BaseTemplate
):
...
...
@@ -40,10 +52,24 @@ class Template(BaseTemplate):
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
.
object
.
create
(
name
=
name
,
description
=
description
,
disk
=
disk
,
remote_ID
=
remote_id
,
created_by
=
user
)
return
new_template
# class PureTemplate(BaseTemplate):
# images = modesl.ForeignKey(
# Image,
# related_name="templates",
# on_delete=models.CASCADE
# )
class
PureTemplate
(
BaseTemplate
):
images
=
models
.
ForeignKey
(
Image
,
related_name
=
"templates"
,
on_delete
=
models
.
CASCADE
)
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