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
60007ab6
authored
Sep 12, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
download diks via rest
parent
ac664c40
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
15 deletions
+77
-15
circle/dashboard/serializers.py
+6
-0
circle/dashboard/urls.py
+6
-2
circle/dashboard/views/storage.py
+16
-3
circle/dashboard/views/template.py
+14
-4
circle/dashboard/views/vm.py
+35
-6
No files found.
circle/dashboard/serializers.py
View file @
60007ab6
...
...
@@ -59,4 +59,9 @@ class VlanSerializer(serializers.ModelSerializer):
class
CreateDiskSerializer
(
serializers
.
Serializer
):
size
=
serializers
.
IntegerField
()
name
=
serializers
.
CharField
(
max_length
=
100
)
class
DownloadDiskSerializer
(
serializers
.
Serializer
):
url
=
serializers
.
CharField
(
max_length
=
500
)
name
=
serializers
.
CharField
(
max_length
=
100
)
\ No newline at end of file
circle/dashboard/urls.py
View file @
60007ab6
...
...
@@ -56,7 +56,8 @@ from .views import (
NodeActivityView
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
InstanceREST
,
InterfaceREST
,
InstanceFromTemplateREST
,
InstanceFTforUsersREST
,
DownloadDiskREST
,
GetInstanceREST
,
DownloadDiskREST
,
GetInstanceREST
,
GetInterfaceREST
,
GetLeaseREST
,
GetDiskRest
,
StorageDetail
,
DiskDetail
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
...
...
@@ -72,10 +73,13 @@ urlpatterns = [
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/ft/'
,
InstanceFromTemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/lease/<int:pk>/'
,
GetLeaseREST
.
as_view
()),
path
(
'acpi/disk/'
,
DiskRest
.
as_view
()),
path
(
'acpi/disk/<int:pk>/'
,
GetDiskRest
.
as_view
()),
path
(
'acpi/interface/'
,
InterfaceREST
.
as_view
()),
path
(
'acpi/interface/<int:pk>/'
,
GetInterfaceREST
.
as_view
()),
path
(
'acpi/ftusers/'
,
InstanceFTforUsersREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/
create
disk/'
,
DownloadDiskREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/
download
disk/'
,
DownloadDiskREST
.
as_view
()),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
name
=
"dashboard.views.user-list"
),
...
...
circle/dashboard/views/storage.py
View file @
60007ab6
...
...
@@ -154,7 +154,7 @@ class DiskRest(APIView):
def
get
(
self
,
request
,
format
=
None
):
templates
=
Disk
.
objects
.
all
()
serializer
=
DiskSerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
{
'disks'
:
serializer
.
data
}
,
safe
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
...
...
@@ -162,4 +162,18 @@ class DiskRest(APIView):
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
\ No newline at end of file
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
GetDiskRest
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
disk
=
Disk
.
objects
.
get
(
pk
=
pk
)
serializer
=
DiskSerializer
(
disk
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
delete
(
self
,
request
,
pk
,
format
=
None
):
return
JsonResponse
(
status
=
204
)
circle/dashboard/views/template.py
View file @
60007ab6
...
...
@@ -200,7 +200,7 @@ class TemplateREST(APIView):
def
get
(
self
,
request
,
format
=
None
):
templates
=
InstanceTemplate
.
objects
.
all
()
serializer
=
InstanceTemplateSerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
{
'templates'
:
serializer
.
data
}
,
safe
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
...
...
@@ -243,7 +243,7 @@ class InstanceFromTemplateREST(APIView):
i
.
deploy
.
_async
(
user
=
user
)
serializer
=
InstanceSerializer
(
instances
,
many
=
True
)
return
JsonResponse
(
{
'instances'
:
serializer
.
data
}
,
status
=
201
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
class
InstanceFTforUsersREST
(
APIView
):
...
...
@@ -275,7 +275,7 @@ class InstanceFTforUsersREST(APIView):
missing_users
,
instances
=
Instance
.
mass_create_for_users
(
**
ikwargs
)
serializer
=
InstanceSerializer
(
instances
,
many
=
True
)
return
JsonResponse
(
{
'instances'
:
serializer
.
data
,
'missing_users'
:
missing_users
}
,
status
=
201
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
class
LeaseREST
(
APIView
):
...
...
@@ -285,7 +285,7 @@ class LeaseREST(APIView):
def
get
(
self
,
request
,
format
=
None
):
templates
=
Lease
.
objects
.
all
()
serializer
=
LeaseSerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
{
'leases'
:
serializer
.
data
}
,
safe
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
...
...
@@ -296,6 +296,16 @@ class LeaseREST(APIView):
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
GetLeaseREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
lease
=
Lease
.
objects
.
get
(
pk
=
pk
)
serializer
=
LeaseSerializer
(
lease
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
TemplateAclUpdateView
(
AclUpdateView
):
model
=
InstanceTemplate
...
...
circle/dashboard/views/vm.py
View file @
60007ab6
...
...
@@ -43,6 +43,7 @@ from django.views.generic import (
)
from
braces.views
import
SuperuserRequiredMixin
,
LoginRequiredMixin
from
vm.operations
import
DownloadDiskOperation
from
common.models
import
(
create_readable
,
HumanReadableException
,
fetch_human_exception
,
...
...
@@ -94,7 +95,7 @@ from rest_framework.parsers import JSONParser
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
dashboard.serializers
import
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
from
dashboard.serializers
import
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
class
InterfaceREST
(
APIView
):
...
...
@@ -104,16 +105,16 @@ class InterfaceREST(APIView):
def
get
(
self
,
request
,
format
=
None
):
templates
=
Interface
.
objects
.
all
()
serializer
=
InterfaceSerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
{
'interfaces'
:
serializer
.
data
}
,
safe
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GetIn
stan
ceREST
(
APIView
):
class
GetIn
terfa
ceREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
template
=
Instan
ce
.
objects
.
get
(
pk
=
pk
)
serializer
=
In
stanceSerializer
(
templat
e
,
many
=
False
)
interface
=
Interfa
ce
.
objects
.
get
(
pk
=
pk
)
serializer
=
In
terfaceSerializer
(
interfac
e
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
...
...
@@ -124,7 +125,7 @@ class InstanceREST(APIView):
def
get
(
self
,
request
,
format
=
None
):
templates
=
Instance
.
objects
.
exclude
(
status
=
'DESTROYED'
)
.
all
()
serializer
=
InstanceSerializer
(
templates
,
many
=
True
)
return
JsonResponse
(
{
'instances'
:
serializer
.
data
}
,
safe
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
...
...
@@ -163,12 +164,40 @@ class InstanceREST(APIView):
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
GetInstanceREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
serializer
=
InstanceSerializer
(
instance
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
DownloadDiskREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
post
(
self
,
request
,
pk
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
DownloadDiskSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
vm_id
=
pk
disk_url
=
str
(
data
[
'url'
])
disk_name
=
str
(
data
[
'name'
])
instance
=
Instance
.
objects
.
get
(
pk
=
vm_id
)
DownloadDiskOperation
(
instance
)
.
_async
(
name
=
disk_name
,
url
=
disk_url
,
user
=
instance
.
owner
)
ret
=
InstanceSerializer
(
instance
,
many
=
False
)
return
JsonResponse
(
ret
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
CreateDiskREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
post
(
self
,
request
,
pk
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
CreateDiskSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
vm_id
=
pk
...
...
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