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
70bd9c63
authored
Oct 10, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'api_changes' into 'DEV'
Api changes See merge request
!20
parents
b5fdffad
94f951c4
Pipeline
#922
passed with stage
in 1 minute 20 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
26 deletions
+27
-26
recircle/instance/views.py
+25
-26
recircle/template/serializers.py
+2
-0
No files found.
recircle/instance/views.py
View file @
70bd9c63
...
...
@@ -56,6 +56,18 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
except
Instance
.
DoesNotExist
:
raise
Http404
def
get_merged_object
(
self
,
pk
):
instance
=
self
.
get_object
(
pk
)
instanceDict
=
InstanceSerializer
(
instance
)
.
data
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
{
"remote_id"
:
remoteInstance
.
id
,
"status"
:
remoteInstance
.
status
,
"disks"
:
remoteInstance
.
disks
,
"addresses"
:
remoteInstance
.
addresses
,
}
return
({
**
instanceDict
,
**
remoteInstanceDict
})
def
list
(
self
,
request
):
instances
=
self
.
get_objects_with_perms
(
request
.
user
,
"list"
,
Instance
)
return
Response
(
InstanceSerializer
(
instances
,
many
=
True
)
.
data
)
...
...
@@ -64,44 +76,32 @@ 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
(
newInstance
.
pk
)
return
Response
(
InstanceSerializer
(
newInstance
)
.
data
)
def
retrieve
(
self
,
request
,
pk
):
instance
=
self
.
get_object
(
pk
)
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
)
instanceDict
=
InstanceSerializer
(
instance
)
.
data
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
remoteInstance
.
__dict__
merged_dict
=
{
**
instanceDict
,
**
remoteInstanceDict
}
return
Response
(
merged_dict
)
mergedInstance
=
self
.
get_merged_object
(
pk
)
return
Response
(
mergedInstance
)
def
update
(
self
,
request
,
pk
,
format
=
None
):
if
request
.
data
[
"action"
]
in
update_actions
:
...
...
@@ -208,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
):
...
...
recircle/template/serializers.py
View file @
70bd9c63
...
...
@@ -12,6 +12,7 @@ class ImageTemplateModelSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
ImageTemplate
fields
=
(
"id"
,
"name"
,
"description"
,
"created_at"
,
...
...
@@ -25,4 +26,5 @@ class ImageTemplateModelSerializer(serializers.ModelSerializer):
"created_at"
,
"created_by"
,
"type"
,
"id"
,
)
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