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
49465117
authored
Apr 16, 2020
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging information messages about instance methods
parent
720ab1e4
Pipeline
#1073
passed with stage
in 1 minute 29 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
recircle/instance/views.py
+16
-0
No files found.
recircle/instance/views.py
View file @
49465117
...
@@ -14,7 +14,9 @@ from template.models import ImageTemplate
...
@@ -14,7 +14,9 @@ from template.models import ImageTemplate
from
template.serializers
import
ImageTemplateModelSerializer
from
template.serializers
import
ImageTemplateModelSerializer
from
authorization.mixins
import
AuthorizationMixin
from
authorization.mixins
import
AuthorizationMixin
from
guardian.shortcuts
import
get_perms_for_model
,
assign_perm
from
guardian.shortcuts
import
get_perms_for_model
,
assign_perm
import
logging
logger
=
logging
.
getLogger
(
__name__
)
authorization
=
{
authorization
=
{
"list"
:
{
"filter"
:
[
"use_instance"
]},
"list"
:
{
"filter"
:
[
"use_instance"
]},
...
@@ -59,6 +61,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -59,6 +61,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
try
:
try
:
return
Instance
.
objects
.
get
(
pk
=
pk
)
return
Instance
.
objects
.
get
(
pk
=
pk
)
except
Instance
.
DoesNotExist
:
except
Instance
.
DoesNotExist
:
logger
.
warn
(
f
"Unexistent instance was requested with id: {pk}"
)
raise
Http404
raise
Http404
def
list
(
self
,
request
):
def
list
(
self
,
request
):
...
@@ -89,10 +92,15 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -89,10 +92,15 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
owner
=
request
.
user
,
owner
=
request
.
user
,
)
)
logger
.
info
(
f
"New virt. machine instance created by {request.user.id}:"
f
"ID: {newInstance.id}"
)
for
perm
in
get_perms_for_model
(
Instance
):
for
perm
in
get_perms_for_model
(
Instance
):
print
(
perm
)
print
(
perm
)
assign_perm
(
perm
,
request
.
user
,
newInstance
)
assign_perm
(
perm
,
request
.
user
,
newInstance
)
logger
.
info
(
f
"All permission granted to user: {request.user.id} to instance:"
f
"{newInstance.id}"
)
return
Response
(
InstanceSerializer
(
newInstance
)
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
InstanceSerializer
(
newInstance
)
.
data
,
status
=
status
.
HTTP_201_CREATED
)
def
retrieve
(
self
,
request
,
pk
):
def
retrieve
(
self
,
request
,
pk
):
...
@@ -113,6 +121,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -113,6 +121,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
instance
.
change_name
(
request
.
data
[
"name"
])
instance
.
change_name
(
request
.
data
[
"name"
])
if
"description"
in
request
.
data
:
if
"description"
in
request
.
data
:
instance
.
change_description
(
request
.
data
[
"description"
])
instance
.
change_description
(
request
.
data
[
"description"
])
logger
.
info
(
f
"Instance (ID: {instance.id}) was updated."
)
return
Response
(
InstanceSerializer
(
instance
)
.
data
)
return
Response
(
InstanceSerializer
(
instance
)
.
data
)
def
destroy
(
self
,
request
,
pk
):
def
destroy
(
self
,
request
,
pk
):
...
@@ -120,6 +130,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -120,6 +130,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if
not
instance
:
if
not
instance
:
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
instance
.
destroy
()
instance
.
destroy
()
logger
.
info
(
f
"Instance (ID: {instance.id}) was deleted by user: {request.user.id}"
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
@action
(
detail
=
True
,
methods
=
[
"post"
])
@action
(
detail
=
True
,
methods
=
[
"post"
])
...
@@ -138,6 +149,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -138,6 +149,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
data
[
"description"
],
data
[
"description"
],
instance
,
instance
,
request
.
user
)
request
.
user
)
logger
.
info
(
f
"A new template created with id: {new_template.id} from instance:"
f
"{instance.id}"
)
serializer
=
ImageTemplateModelSerializer
(
instance
=
new_template
)
serializer
=
ImageTemplateModelSerializer
(
instance
=
new_template
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
...
@@ -147,6 +160,9 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
...
@@ -147,6 +160,9 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if
not
self
.
has_perms_for_object
(
request
.
user
,
request
.
data
[
"action"
],
instance
):
if
not
self
.
has_perms_for_object
(
request
.
user
,
request
.
data
[
"action"
],
instance
):
return
Response
({
"error"
:
"No permission to use this action on the VM."
},
return
Response
({
"error"
:
"No permission to use this action on the VM."
},
status
=
status
.
HTTP_401_UNAUTHORIZED
)
status
=
status
.
HTTP_401_UNAUTHORIZED
)
if
"action"
in
request
.
data
:
action
=
request
.
data
[
"action"
]
logger
.
info
(
f
"Action {action} initiatied in instance: {instance.id}"
)
success
=
instance
.
execute_common_action
(
action
=
request
.
data
[
"action"
])
success
=
instance
.
execute_common_action
(
action
=
request
.
data
[
"action"
])
return
Response
(
success
)
return
Response
(
success
)
...
...
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