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
94f951c4
authored
Oct 03, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add handling template to create
parent
256a2690
Pipeline
#905
passed with stage
in 1 minute 18 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
20 deletions
+10
-20
recircle/instance/views.py
+10
-20
No files found.
recircle/instance/views.py
View file @
94f951c4
...
...
@@ -76,30 +76,23 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if
not
self
.
has_perms_for_model
(
request
.
user
,
'create'
):
return
Response
({
"error"
:
"No permission to create Virtual Machine."
},
status
=
status
.
HTTP_401_UNAUTHORIZED
)
data
=
request
.
data
template
=
ImageTemplate
.
objects
.
get
(
pk
=
data
[
"template"
])
# TODO: if the user can select anouther lease and flavor
# That will be applied, not from the template
# flavor = Flavor.objects.get(pk=data["flavor"])
# lease = Lease.objects.get(pk=data["lease"])
params
=
request
.
data
template
=
ImageTemplate
.
objects
.
get
(
pk
=
params
[
"template"
])
flavor
=
Flavor
.
objects
.
get
(
pk
=
params
[
"flavor"
])
if
"flavor"
in
params
else
template
.
flavor
lease
=
Lease
.
objects
.
get
(
pk
=
params
[
"lease"
])
if
"lease"
in
params
else
template
.
lease
newInstance
=
Instance
.
create_instance_from_template
(
params
=
{
"name"
:
data
[
"name"
],
"description"
:
data
[
"description"
],
"access_method"
:
data
[
"access"
],
"system"
:
data
[
"system"
],
params
=
{
"name"
:
params
[
"name"
],
"description"
:
params
[
"description"
],
"access_method"
:
params
[
"access"
],
"system"
:
params
[
"system"
],
},
lease
=
template
.
lease
,
lease
=
lease
,
networks
=
[{
"uuid"
:
template
.
network_id
}],
template
=
template
,
flavor
=
template
.
flavor
,
flavor
=
flavor
,
owner
=
request
.
user
,
disks
=
None
)
return
Response
(
InstanceSerializer
(
newInstance
)
.
data
)
def
retrieve
(
self
,
request
,
pk
):
...
...
@@ -107,9 +100,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if
not
self
.
has_perms_for_object
(
request
.
user
,
'retrieve'
,
instance
):
return
Response
({
"error"
:
"No permission to access the Virtual Machine."
},
status
=
status
.
HTTP_401_UNAUTHORIZED
)
mergedInstance
=
self
.
get_merged_object
(
pk
)
return
Response
(
mergedInstance
)
def
update
(
self
,
request
,
pk
,
format
=
None
):
...
...
@@ -217,7 +208,6 @@ class FlavorViewSet(ViewSet):
vcpu
=
data
[
"vcpu"
],
initial_disk
=
data
[
"initial_disk"
],
priority
=
data
[
"priority"
])
return
Response
(
new_flavor
.
pk
)
def
update
(
self
,
request
,
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