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
daea0676
authored
Jul 11, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify instance create view, add flavor list view
parent
15057b46
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
7 deletions
+39
-7
Pipfile.lock
+0
-0
recircle/instance/serializers.py
+11
-4
recircle/instance/urls.py
+1
-0
recircle/instance/views.py
+27
-3
No files found.
Pipfile.lock
View file @
daea0676
This diff is collapsed.
Click to expand it.
recircle/instance/serializers.py
View file @
daea0676
from
rest_framework
import
serializers
from
.models
import
Flavor
from
.models
import
Instance
class
InstanceSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
()
description
=
serializers
.
CharField
()
system
=
serializers
.
CharField
()
lease
=
serializers
.
RelatedField
(
read_only
=
True
)
flavor
=
serializers
.
RelatedField
(
read_only
=
True
)
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
class
FlavorSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Instance
fields
=
"__all__"
model
=
Flavor
fields
=
'__all__'
recircle/instance/urls.py
View file @
daea0676
...
...
@@ -6,6 +6,7 @@ urlpatterns = [
path
(
"instances/"
,
views
.
InstanceList
.
as_view
()),
path
(
"instances/<int:pk>/"
,
views
.
InstanceDetail
.
as_view
()),
# path('instances/<int:pk>/action/', views.InstanceAction.as_view())
path
(
"flavors/"
,
views
.
FlavorListView
.
as_view
()),
]
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
recircle/instance/views.py
View file @
daea0676
from
instance.models
import
Instance
from
instance.serializers
import
InstanceSerializer
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
from
django.http
import
Http404
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
...
...
@@ -25,12 +25,15 @@ class InstanceList(APIView):
def
post
(
self
,
request
,
format
=
None
):
data
=
request
.
data
template
=
InstanceTemplate
(
name
=
"test1"
,
description
=
"adsasdasd"
,
remote_ID
=
"da51253f-867c-472d-8ce0-81e7b7126d60"
)
template
=
InstanceTemplate
(
name
=
"test1"
,
description
=
"adsasdasd"
,
remote_ID
=
"da51253f-867c-472d-8ce0-81e7b7126d60"
)
flavor
=
Flavor
(
name
=
"asd"
,
description
=
"asd"
,
remote_id
=
"1"
)
flavor
.
save
()
lease
=
Lease
(
name
=
"test_lease"
,
description
=
"test"
,
suspend_interval_in_sec
=
100
,
delete_interval_in_sec
=
100
)
lease
.
save
()
newInstance
=
Instance
.
create_instance_from_template
(
params
=
{
"name"
:
data
[
"name"
],
...
...
@@ -85,3 +88,24 @@ class InstanceDetail(APIView):
instance
=
self
.
get_object
(
pk
)
instance
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
class
FlavorListView
(
APIView
):
"""
Create, update or delete a flavor.
"""
def
get
(
self
,
request
,
format
=
None
):
flavors
=
Flavor
.
objects
.
all
()
return
Response
(
FlavorSerializer
(
flavors
,
many
=
True
)
.
data
)
def
post
(
self
,
request
,
format
=
None
):
data
=
request
.
data
new_flavor
=
Flavor
.
create
(
name
=
data
[
"name"
],
description
=
data
[
"description"
],
ram
=
data
[
"ram"
],
vcpu
=
data
[
"vcpu"
],
initial_disk
=
data
[
"initial_disk"
],
priority
=
data
[
"priority"
])
return
Response
(
new_flavor
.
pk
)
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