Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
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
355ad49c
authored
Sep 15, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs
parent
8a880eb5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
9 deletions
+57
-9
circle/dashboard/serializers.py
+3
-0
circle/dashboard/urls.py
+3
-1
circle/dashboard/views/group.py
+10
-0
circle/dashboard/views/user.py
+9
-0
circle/dashboard/views/vm.py
+30
-7
circle/vm/tasks/local_tasks.py
+2
-1
No files found.
circle/dashboard/serializers.py
View file @
355ad49c
...
...
@@ -128,6 +128,9 @@ class DestroyDiskSerializer(serializers.Serializer):
class
Meta
:
extra_kwargs
=
{
'instance'
:
{
'required'
:
False
,
'allow_null'
:
True
}}
class
AddPortSerializer
(
serializers
.
Serializer
):
port_type
=
serializers
.
CharField
(
max_length
=
5
)
port_number
=
serializers
.
IntegerField
()
class
VMDeploySerializer
(
serializers
.
Serializer
):
node
=
serializers
.
IntegerField
(
required
=
False
)
...
...
circle/dashboard/urls.py
View file @
355ad49c
...
...
@@ -60,7 +60,7 @@ from .views import (
GetLeaseREST
,
GetDiskRest
,
DeployInstanceREST
,
CreateDiskREST
,
VlanREST
,
ResizeDiskREST
,
GetVlanREST
,
DestroyDiskREST
,
StorageDetail
,
DiskDetail
,
UserREST
,
GroupREST
,
InstanceActivityREST
,
GetInstanceActivityREST
,
InstanceActivityREST
,
GetInstanceActivityREST
,
GetGroupREST
,
GetUserREST
,
SleepInstanceREST
,
WakeUpInstanceREST
,
DownloadPersistentDiskREST
,
CreatePersistentDiskREST
,
GetStorageActivityREST
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
...
...
@@ -78,7 +78,9 @@ urlpatterns = [
path
(
'acpi/vmact/'
,
InstanceActivityREST
.
as_view
()),
path
(
'acpi/vmact/<int:pk>/'
,
GetInstanceActivityREST
.
as_view
()),
path
(
'acpi/user/'
,
UserREST
.
as_view
()),
path
(
'acpi/user/<int:pk>/'
,
GetUserREST
.
as_view
()),
path
(
'acpi/group/'
,
GroupREST
.
as_view
()),
path
(
'acpi/group/<int:pk>/'
,
GetGroupREST
.
as_view
()),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()),
path
(
'acpi/node/'
,
NodeREST
.
as_view
()),
path
(
'acpi/node/<int:pk>/'
,
GetNodeREST
.
as_view
()),
...
...
circle/dashboard/views/group.py
View file @
355ad49c
...
...
@@ -80,6 +80,16 @@ class GroupREST(APIView):
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GetGroupREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
groups
=
Group
.
objects
.
get
(
pk
=
pk
)
serializer
=
GroupSerializer
(
groups
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GroupCodeMixin
(
object
):
@classmethod
...
...
circle/dashboard/views/user.py
View file @
355ad49c
...
...
@@ -91,6 +91,15 @@ class UserREST(APIView):
serializer
=
UserSerializer
(
users
,
many
=
True
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GetUserREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
users
=
User
.
objects
.
get
(
pk
=
pk
)
serializer
=
UserSerializer
(
users
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
set_session_expiry
(
request
,
user
):
if
user
.
is_superuser
:
messages
.
info
(
request
,
_
(
"You've logged in with an administrator "
...
...
circle/dashboard/views/vm.py
View file @
355ad49c
...
...
@@ -49,7 +49,7 @@ from braces.views import SuperuserRequiredMixin, LoginRequiredMixin
from
storage.tasks
import
storage_tasks
from
vm.tasks.local_tasks
import
abortable_async_downloaddisk_operation
from
vm.operations
import
(
DeployOperation
,
DestroyOperation
,
DownloadDiskOperation
,
ShutdownOperation
,
RenewOperation
,
ResizeDiskOperation
,
RemoveDiskOperation
,
SleepOperation
,
WakeUpOperation
ResizeDiskOperation
,
RemoveDiskOperation
,
SleepOperation
,
WakeUpOperation
,
AddPortOperation
,
)
from
common.models
import
(
...
...
@@ -105,6 +105,7 @@ from rest_framework.permissions import IsAdminUser
from
dashboard.serializers
import
(
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
VMDeploySerializer
,
VlanSerializer
,
ResizeDiskSerializer
,
InstanceActivitySerializer
,
DestroyDiskSerializer
,
StorageActivitySerializer
,
AddPortSerializer
,
)
def
size_util
(
size
:
str
):
...
...
@@ -216,6 +217,9 @@ class InstanceREST(APIView):
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
data
[
'pw'
]
=
pwgen
()
req_deploy
=
False
if
'status'
in
data
:
req_deploy
=
data
[
'status'
]
==
"RUNNING"
data
[
'status'
]
=
'STOPPED'
if
'owner'
not
in
data
:
data
[
'owner'
]
=
request
.
user
.
id
...
...
@@ -243,11 +247,16 @@ class InstanceREST(APIView):
owner
=
inst
.
owner
,
managed
=
net
.
managed
,
base_activity
=
act
)
if
'create_disk'
in
data
:
inst
.
create_disk
(
size
=
data
[
'create_disk'
][
'size'
],
user
=
inst
.
owner
,
name
=
data
[
'create_disk'
][
'name'
],
activity
=
None
)
if
'download_disk'
in
data
:
inst
.
download_disk
(
user
=
inst
.
owner
,
name
=
data
[
'download_disk'
][
'name'
])
if
'disks'
in
data
:
import
string
devnums
=
list
(
string
.
ascii_lowercase
)
for
l
in
data
[
'disks'
]:
disk
=
Disk
.
objects
.
get
(
pk
=
int
(
l
))
disk
.
dev_num
=
devnums
.
pop
(
0
)
disk
.
save
()
if
req_deploy
:
DeployOperation
(
inst
)
.
call
(
node
=
None
,
user
=
inst
.
owner
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
...
...
@@ -298,7 +307,21 @@ class DeployInstanceREST(APIView):
DeployOperation
(
instance
)
.
call
(
node
=
None
,
user
=
instance
.
owner
)
serializer
=
InstanceSerializer
(
instance
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
return
JsonResponse
(
deploy
.
errors
,
status
=
201
)
return
JsonResponse
(
deploy
.
errors
,
status
=
400
)
class
AddPortREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
post
(
self
,
request
,
pk
,
format
=
None
):
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
data
=
JSONParser
()
.
parse
(
request
)
addport
=
AddPortSerializer
(
data
=
data
)
if
addport
.
is_valid
():
AddPortOperation
(
instance
)
.
call
(
port
=
int
(
data
[
'port_number'
]),
proto
=
str
(
data
[
'port_type'
]))
return
JsonResponse
({},
status
=
201
)
return
JsonResponse
(
addport
.
errors
,
status
=
400
)
class
SleepInstanceREST
(
APIView
):
...
...
circle/vm/tasks/local_tasks.py
View file @
355ad49c
...
...
@@ -71,6 +71,6 @@ def abortable_async_downloaddisk_operation(task, activity_pk, url, name):
activity
.
disk
=
disk
activity
.
succeeded
=
True
activity
.
finished
=
timezone
.
now
()
#
activity.finished = timezone.now()
activity
.
save
()
return
\ No newline at end of file
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