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
52626ae9
authored
Sep 02, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add update actions
parent
39705221
Pipeline
#860
passed with stage
in 1 minute 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
9 deletions
+79
-9
recircle/instance/models.py
+18
-0
recircle/instance/views.py
+60
-8
recircle/interface_openstack
+1
-1
No files found.
recircle/instance/models.py
View file @
52626ae9
...
...
@@ -186,6 +186,16 @@ class Instance(models.Model):
seconds
=
lease
.
delete_interval_in_sec
)
)
def
renew
(
self
,
lease
=
None
):
"""Renew virtual machine, if a new lease is provided it changes it as well.
"""
if
lease
is
None
:
lease
=
self
.
lease
else
:
self
.
lease
=
lease
self
.
time_of_suspend
,
self
.
time_of_delete
=
self
.
get_renew_times
(
lease
)
self
.
save
()
def
delete
(
self
):
try
:
interface
.
destroy_vm
(
self
.
remote_id
)
...
...
@@ -208,3 +218,11 @@ class Instance(models.Model):
return
User
.
objects
.
make_random_password
(
allowed_chars
=
'abcdefghijklmnopqrstuvwx'
'ABCDEFGHIJKLMNOPQRSTUVWX123456789'
)
def
change_name
(
self
,
new_name
):
self
.
name
=
new_name
self
.
save
()
def
change_description
(
self
,
new_description
):
self
.
description
=
new_description
self
.
save
()
recircle/instance/views.py
View file @
52626ae9
...
...
@@ -27,6 +27,23 @@ authorization = {
"reboot"
:
{
"object"
:
[
"operate_instance"
]},
}
update_actions
=
[
"change_name"
,
"change_description"
,
"renew"
,
"change_lease"
,
"change_flavor"
,
"attach_disk"
,
"resize_disk"
,
"add_permission"
,
"remove_permission"
,
"open_port"
,
"close_port"
,
"add_network"
,
"remove_network"
,
"new_password"
,
]
class
InstanceViewSet
(
AuthorizationMixin
,
ViewSet
):
...
...
@@ -85,15 +102,50 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
return
Response
(
merged_dict
)
# I think we need separate actions for this behaviour because of the access control - BAdam
def
update
(
self
,
request
,
pk
,
format
=
None
):
instance
=
self
.
get_object
(
pk
)
serializer
=
InstanceSerializer
(
instance
,
data
=
request
.
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
if
request
.
data
[
"action"
]
in
update_actions
:
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
)
action
=
request
.
data
[
"action"
]
if
action
==
"change_name"
:
instance
.
change_name
(
request
.
data
[
"name"
])
elif
action
==
"change_description"
:
instance
.
change_description
(
request
.
data
[
"description"
])
elif
action
==
"renew"
:
instance
.
renew
()
elif
action
==
"change_lease"
:
lease
=
Lease
.
objects
.
get
(
id
=
request
.
data
[
"lease"
])
instance
.
renew
(
lease
)
elif
action
==
"change_flavor"
:
pass
elif
action
==
"attach_disk"
:
pass
elif
action
==
"resize_disk"
:
pass
elif
action
==
"add_permission"
:
pass
elif
action
==
"remove_permission"
:
pass
elif
action
==
"open_port"
:
pass
elif
action
==
"close_port"
:
pass
elif
action
==
"add_network"
:
pass
elif
action
==
"remove_network"
:
pass
elif
action
==
"new_password"
:
pass
instanceDict
=
InstanceSerializer
(
instance
)
.
data
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
remoteInstance
.
__dict__
merged_dict
=
{
**
instanceDict
,
**
remoteInstanceDict
}
return
Response
(
merged_dict
)
else
:
return
Response
({
"error"
:
"Unknown update action."
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
def
destroy
(
self
,
request
,
pk
,
format
=
None
):
instance
=
self
.
get_object
(
pk
)
...
...
interface_openstack
@
1a19e435
Subproject commit
e01d873c78ac17fed0438936f979de3cbaca6a5e
Subproject commit
1a19e4355f4af1abb49a3f6e07dc3a6c3f8bdf47
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