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
d091507d
authored
Jul 22, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flake8 errors
parent
a017ac6d
Pipeline
#788
failed with stages
in 2 minutes 0 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
29 deletions
+25
-29
recircle/image/models.py
+3
-3
recircle/image/views.py
+4
-5
recircle/instance/views.py
+1
-0
recircle/recircle/urls.py
+0
-2
recircle/template/models.py
+6
-9
recircle/template/views.py
+11
-10
No files found.
recircle/image/models.py
View file @
d091507d
...
...
@@ -69,7 +69,6 @@ class Image(models.Model):
return
inst
@classmethod
def
create_from_instance
(
cls
,
user
,
instance
,
description
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
...
...
@@ -84,11 +83,12 @@ class Image(models.Model):
description
=
description
)
return
new_image
@classmethod
def
create_from_user
(
cls
,
description
,
file_format
,
image_file
,
name
,
user
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
remote_image
=
interface
.
upload_file
(
name
=
name
,
path
=
image_file
.
temporary_file_path
(),
format
=
file_format
)
remote_image
=
interface
.
upload_file
(
name
=
name
,
path
=
image_file
.
temporary_file_path
(),
format
=
file_format
)
new_image
=
cls
.
create
(
name
=
name
,
remote_id
=
remote_image
.
id
,
...
...
recircle/image/views.py
View file @
d091507d
# from django.shortcuts import render
from
rest_framework.viewsets
import
ModelViewSet
from
rest_framework.response
import
Response
from
django.http
import
HttpResponse
from
image.models
import
Image
from
image.serializers
import
ImageSerializer
class
ImageViewSet
(
ModelViewSet
):
serializer_class
=
ImageSerializer
queryset
=
Image
.
objects
.
all
()
serializer_class
=
ImageSerializer
queryset
=
Image
.
objects
.
all
()
# def list(self, request):
# return HttpResponse("list")
...
...
@@ -17,7 +16,7 @@ class ImageViewSet(ModelViewSet):
serializer
=
ImageSerializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
data
=
serializer
.
validated_data
new_image
=
Image
.
create_from_user
(
new_image
=
Image
.
create_from_user
(
description
=
data
[
'description'
],
file_format
=
data
[
'file_format'
],
image_file
=
data
[
'image_file'
],
...
...
@@ -26,7 +25,7 @@ class ImageViewSet(ModelViewSet):
)
serializer
=
ImageSerializer
(
instance
=
new_image
)
return
Response
(
serializer
.
data
)
# def retrieve(self, request, pk=None):
# return HttpResponse("retrive")
...
...
recircle/instance/views.py
View file @
d091507d
...
...
@@ -9,6 +9,7 @@ from interface_openstack.implementation.vm.instance import (
)
from
instance.models
import
Instance
,
Flavor
,
Lease
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
from
template.models
import
ImageTemplate
class
InstanceList
(
APIView
):
...
...
recircle/recircle/urls.py
View file @
d091507d
...
...
@@ -29,4 +29,3 @@ urlpatterns = [
re_path
(
r"^auth/"
,
include
(
"djoser.urls.authtoken"
)),
path
(
r"swagger"
,
schema_view
),
]
\ No newline at end of file
recircle/template/models.py
View file @
d091507d
...
...
@@ -6,8 +6,7 @@ from image.models import Disk
from
image.models
import
Image
from
instance.models
import
Lease
from
instance.models
import
Flavor
from
interface_openstack.implementation.storage.openstack_snapshot_manager
import
SnapshotManager
from
interface_openstack.implementation.vm.instance
import
OSVirtualMachineManager
from
interface_openstack.implementation.storage.openstack_snapshot_manager
import
SnapshotManager
class
BaseTemplate
(
models
.
Model
):
...
...
@@ -47,7 +46,7 @@ class BaseTemplate(models.Model):
related_name
=
'templates'
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
related_name
=
'templates'
)
class
DiskTemplate
(
BaseTemplate
):
disk
=
models
.
ForeignKey
(
...
...
@@ -71,13 +70,12 @@ class DiskTemplate(BaseTemplate):
)
return
new_template
class
ImageTemplate
(
BaseTemplate
):
TYPES
=
(
(
'U'
,
'User create the template from image'
),
(
'I'
,
'Template created from instance'
),
(
'P'
,
'"Pure" template'
),
)
image
=
models
.
ForeignKey
(
...
...
@@ -90,13 +88,12 @@ class ImageTemplate(BaseTemplate):
@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
=
cls
(
name
=
name
,
description
=
description
,
image
=
image
,
lease
=
lease
,
flavor
=
flavor
,
created_by
=
created_by
,
type
=
type
)
inst
.
full_clean
()
inst
.
save
()
return
inst
@classmethod
def
create_from_instance
(
cls
,
name
,
description
,
instance
,
user
):
image
=
Image
.
create_from_instance
(
user
,
instance
,
description
)
...
...
@@ -104,7 +101,7 @@ class ImageTemplate(BaseTemplate):
name
=
name
,
description
=
description
,
created_by
=
user
,
image
=
image
,
image
=
image
,
lease
=
instance
.
lease
,
flavor
=
instance
.
flavor
,
type
=
"I"
...
...
recircle/template/views.py
View file @
d091507d
...
...
@@ -9,8 +9,8 @@ from template.models import ImageTemplate
class
ImageTemplateViewSet
(
ModelViewSet
):
serializer_class
=
ImageTemplateModelSerializer
queryset
=
ImageTemplate
.
objects
.
all
()
serializer_class
=
ImageTemplateModelSerializer
queryset
=
ImageTemplate
.
objects
.
all
()
def
create
(
self
,
request
):
serializer
=
ImageTemplateModelSerializer
(
data
=
request
.
data
)
...
...
@@ -20,24 +20,24 @@ class ImageTemplateViewSet(ModelViewSet):
name
=
data
[
"name"
],
description
=
data
[
"description"
],
created_by
=
request
.
user
,
image
=
data
[
"image"
],
image
=
data
[
"image"
],
lease
=
data
[
"lease"
],
flavor
=
data
[
"flavor"
],
type
=
"U"
)
serializer
=
ImageTemplateModelSerializer
(
instance
=
new_template
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
# only the name, description, lease, flavor can be updated
allowed_keys
=
[
"name"
,
"description"
,
"lease"
,
"flavor"
]
#delete not allowed key
for
key
in
request
.
data
.
keys
():
#
delete not allowed key
for
key
in
request
.
data
.
keys
():
if
key
not
in
allowed_keys
:
request
.
data
.
pop
(
key
,
None
)
request
.
data
.
pop
(
key
,
None
)
return
super
(
Question
ViewSet
,
self
)
.
update
(
request
,
partial
=
True
)
return
super
(
ImageTemplate
ViewSet
,
self
)
.
update
(
request
,
partial
=
True
)
@action
(
detail
=
True
,
methods
=
[
"post"
])
def
template
(
self
,
request
,
pk
):
...
...
@@ -45,6 +45,7 @@ class ImageTemplateViewSet(ModelViewSet):
serializer
=
InstanceFromTemplateSerializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
data
=
serializer
.
validated_data
new_template
=
ImageTemplate
.
create_from_instance
(
data
[
"name"
],
data
[
"description"
],
instance
,
request
.
user
)
new_template
=
ImageTemplate
.
create_from_instance
(
data
[
"name"
],
data
[
"description"
],
instance
,
request
.
user
)
serializer
=
ImageTemplateModelSerializer
(
instance
=
new_template
)
return
Response
(
serializer
.
data
)
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