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
8179e8f6
authored
Sep 13, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add activities t rest api
parent
ec9774e5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
13 deletions
+48
-13
circle/dashboard/serializers.py
+6
-1
circle/dashboard/urls.py
+3
-0
circle/dashboard/views/util.py
+29
-0
circle/dashboard/views/vm.py
+4
-7
circle/locale/hu/LC_MESSAGES/django.po
+2
-2
circle/vm/operations.py
+4
-3
No files found.
circle/dashboard/serializers.py
View file @
8179e8f6
...
@@ -2,10 +2,15 @@ from rest_framework.renderers import JSONRenderer
...
@@ -2,10 +2,15 @@ from rest_framework.renderers import JSONRenderer
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.models
import
Group
,
User
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
,
Node
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
,
Node
,
InstanceActivity
from
firewall.models
import
Vlan
from
firewall.models
import
Vlan
from
storage.models
import
Disk
from
storage.models
import
Disk
class
InstanceActivitySerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
InstanceActivity
fields
=
(
'id'
,
'instance'
,
'resultant_state'
,
'interruptible'
,
'activity_code'
,
'readable_name_data'
,
'parent'
,
'task_uuid'
,
'user'
,
'started'
,
'finished'
,
'succeeded'
,
'result_data'
,
'created'
,
'modified'
)
class
GroupSerializer
(
serializers
.
ModelSerializer
):
class
GroupSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
...
...
circle/dashboard/urls.py
View file @
8179e8f6
...
@@ -60,6 +60,7 @@ from .views import (
...
@@ -60,6 +60,7 @@ from .views import (
GetLeaseREST
,
GetDiskRest
,
DeployInstanceREST
,
CreateDiskREST
,
GetLeaseREST
,
GetDiskRest
,
DeployInstanceREST
,
CreateDiskREST
,
VlanREST
,
ResizeDiskREST
,
GetVlanREST
,
VlanREST
,
ResizeDiskREST
,
GetVlanREST
,
StorageDetail
,
DiskDetail
,
UserREST
,
GroupREST
,
StorageDetail
,
DiskDetail
,
UserREST
,
GroupREST
,
InstanceActivityREST
,
GetInstanceActivityREST
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
...
@@ -69,6 +70,8 @@ from .views.node import node_ops, NodeREST, GetNodeREST
...
@@ -69,6 +70,8 @@ from .views.node import node_ops, NodeREST, GetNodeREST
from
.views.vm
import
vm_ops
,
vm_mass_ops
from
.views.vm
import
vm_ops
,
vm_mass_ops
urlpatterns
=
[
urlpatterns
=
[
path
(
'acpi/vmact/'
,
InstanceActivityREST
.
as_view
()),
path
(
'acpi/vmact/<int:pk>/'
,
GetInstanceActivityREST
.
as_view
()),
path
(
'acpi/user/'
,
UserREST
.
as_view
()),
path
(
'acpi/user/'
,
UserREST
.
as_view
()),
path
(
'acpi/group/'
,
GroupREST
.
as_view
()),
path
(
'acpi/group/'
,
GroupREST
.
as_view
()),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()),
...
...
circle/dashboard/views/util.py
View file @
8179e8f6
...
@@ -51,8 +51,17 @@ from braces.views import LoginRequiredMixin
...
@@ -51,8 +51,17 @@ from braces.views import LoginRequiredMixin
from
braces.views._access
import
AccessMixin
from
braces.views._access
import
AccessMixin
from
celery.exceptions
import
TimeoutError
from
celery.exceptions
import
TimeoutError
from
rest_framework
import
status
from
rest_framework.views
import
APIView
from
rest_framework.parsers
import
JSONParser
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
dashboard.serializers
import
InstanceActivitySerializer
from
common.models
import
HumanReadableException
,
HumanReadableObject
from
common.models
import
HumanReadableException
,
HumanReadableObject
from
..models
import
GroupProfile
,
Profile
from
..models
import
GroupProfile
,
Profile
from
vm.models
import
InstanceActivity
from
..forms
import
TransferOwnershipForm
from
..forms
import
TransferOwnershipForm
...
@@ -67,6 +76,26 @@ logger = logging.getLogger(__name__)
...
@@ -67,6 +76,26 @@ logger = logging.getLogger(__name__)
saml_available
=
hasattr
(
settings
,
"SAML_CONFIG"
)
saml_available
=
hasattr
(
settings
,
"SAML_CONFIG"
)
class
InstanceActivityREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
InstanceActivity
.
objects
.
all
()
serializer
=
InstanceActivitySerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GetInstanceActivityREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
interface
=
InstanceActivity
.
objects
.
get
(
pk
=
pk
)
serializer
=
InstanceActivitySerializer
(
interface
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
RedirectToLoginMixin
(
AccessMixin
):
class
RedirectToLoginMixin
(
AccessMixin
):
redirect_exception_classes
=
(
PermissionDenied
,
)
redirect_exception_classes
=
(
PermissionDenied
,
)
...
...
circle/dashboard/views/vm.py
View file @
8179e8f6
...
@@ -98,7 +98,7 @@ from rest_framework.permissions import IsAdminUser
...
@@ -98,7 +98,7 @@ from rest_framework.permissions import IsAdminUser
from
dashboard.serializers
import
(
from
dashboard.serializers
import
(
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
VMDeploySerializer
,
VlanSerializer
,
ResizeDiskSerializer
VMDeploySerializer
,
VlanSerializer
,
ResizeDiskSerializer
,
InstanceActivitySerializer
)
)
class
VlanREST
(
APIView
):
class
VlanREST
(
APIView
):
...
@@ -268,13 +268,10 @@ class DownloadDiskREST(APIView):
...
@@ -268,13 +268,10 @@ class DownloadDiskREST(APIView):
disk_url
=
str
(
data
[
'url'
])
disk_url
=
str
(
data
[
'url'
])
disk_name
=
str
(
data
[
'name'
])
disk_name
=
str
(
data
[
'name'
])
instance
=
Instance
.
objects
.
get
(
pk
=
vm_id
)
instance
=
Instance
.
objects
.
get
(
pk
=
vm_id
)
old_disks
=
list
(
instance
.
disks
.
all
())
DownloadDiskOperation
(
instance
)
.
_async
(
name
=
disk_name
,
url
=
disk_url
,
user
=
instance
.
owner
)
DownloadDiskOperation
(
instance
)
.
_async
(
name
=
disk_name
,
url
=
disk_url
,
user
=
instance
.
owner
)
new_disks
=
instance
.
disks
.
all
()
act
=
instance
.
get_latest_activity_in_progress
()
for
d
in
new_disks
:
serializer
=
InstanceActivitySerializer
(
act
,
many
=
False
)
if
d
not
in
old_disks
:
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
ret
=
DiskSerializer
(
d
,
many
=
False
)
return
JsonResponse
(
ret
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
def
size_util
(
size
:
str
):
def
size_util
(
size
:
str
):
...
...
circle/locale/hu/LC_MESSAGES/django.po
View file @
8179e8f6
...
@@ -7683,8 +7683,8 @@ msgstr ""
...
@@ -7683,8 +7683,8 @@ msgstr ""
#: vm/operations.py:344
#: vm/operations.py:344
#, python-format
#, python-format
msgid "download %(name)s"
msgid "download %(name)s
(id: %(disk_id)s)
"
msgstr "%(name)s letöltése"
msgstr "%(name)s letöltése
(id: %(disk_id)s)
"
#: vm/operations.py:347
#: vm/operations.py:347
#, python-format
#, python-format
...
...
circle/vm/operations.py
View file @
8179e8f6
...
@@ -341,12 +341,13 @@ class DownloadDiskOperation(InstanceOperation):
...
@@ -341,12 +341,13 @@ class DownloadDiskOperation(InstanceOperation):
disk
.
save
()
disk
.
save
()
self
.
instance
.
disks
.
add
(
disk
)
self
.
instance
.
disks
.
add
(
disk
)
activity
.
readable_name
=
create_readable
(
activity
.
readable_name
=
create_readable
(
ugettext_noop
(
"download
%(name)
s
"
),
name
=
disk
.
name
)
ugettext_noop
(
"download
%(name)
s
(id:
%(disk_id)
s)"
),
name
=
disk
.
name
,
disk_id
=
str
(
disk
.
id
)
)
activity
.
result
=
create_readable
(
ugettext_noop
(
activity
.
result
=
create_readable
(
ugettext_noop
(
"Downloading
%(url)
s is finished. The file md5sum "
"Downloading
%(url)
s is finished. The file md5sum "
"is: '
%(checksum)
s'."
),
"is: '
%(checksum)
s' (id:
%(disk_id)
s)."
),
url
=
url
,
checksum
=
disk
.
checksum
)
url
=
url
,
checksum
=
disk
.
checksum
,
disk_id
=
str
(
disk
.
id
))
activity
.
result_data
[
'params'
][
'disk_id'
]
=
disk
.
id
# TODO iso (cd) hot-plug is not supported by kvm/guests
# TODO iso (cd) hot-plug is not supported by kvm/guests
if
self
.
instance
.
is_running
and
disk
.
type
not
in
[
"iso"
]:
if
self
.
instance
.
is_running
and
disk
.
type
not
in
[
"iso"
]:
self
.
instance
.
_attach_disk
(
parent_activity
=
activity
,
disk
=
disk
)
self
.
instance
.
_attach_disk
(
parent_activity
=
activity
,
disk
=
disk
)
...
...
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