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
bf49a963
authored
Aug 30, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add disk to rest api
parent
5485381c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
5 deletions
+37
-5
circle/dashboard/serializers.py
+9
-3
circle/dashboard/urls.py
+2
-1
circle/dashboard/views/storage.py
+26
-0
circle/dashboard/views/template.py
+0
-1
No files found.
circle/dashboard/serializers.py
View file @
bf49a963
...
@@ -2,20 +2,25 @@ from rest_framework.renderers import JSONRenderer
...
@@ -2,20 +2,25 @@ from rest_framework.renderers import JSONRenderer
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
vm.models
import
InstanceTemplate
,
Lease
from
vm.models
import
InstanceTemplate
,
Lease
from
storage.models
import
Disk
class
InstanceTemplateSerializer
(
serializers
.
ModelSerializer
):
class
InstanceTemplateSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
model
=
InstanceTemplate
model
=
InstanceTemplate
resource_name
=
'template'
fields
=
[
'id'
,
'name'
,
'description'
,
'parent'
,
'owner'
,
'access_method'
,
'boot_menu'
,
fields
=
[
'id'
,
'name'
,
'description'
,
'parent'
,
'owner'
,
'access_method'
,
'boot_menu'
,
'lease'
,
'raw_data'
,
'cloud_init'
,
'ci_meta_data'
,
'ci_user_data'
,
'system'
,
'lease'
,
'raw_data'
,
'cloud_init'
,
'ci_meta_data'
,
'ci_user_data'
,
'system'
,
'has_agent'
,
'num_cores'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'priority'
]
'has_agent'
,
'num_cores'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'priority'
,
'disks'
]
class
LeaseSerializer
(
serializers
.
ModelSerializer
):
class
LeaseSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
model
=
Lease
model
=
Lease
resource_name
=
'lease'
fields
=
[
'id'
,
'name'
,
'suspend_interval_seconds'
,
'delete_interval_seconds'
]
fields
=
[
'id'
,
'name'
,
'suspend_interval_seconds'
,
'delete_interval_seconds'
]
class
DiskSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Disk
fields
=
[
'id'
,
'name'
,
'filename'
,
'datastore'
,
'type'
,
'bus'
,
'size'
,
'base'
,
'dev_num'
,
'destroyed'
,
'ci_disk'
,
'is_ready'
]
\ No newline at end of file
circle/dashboard/urls.py
View file @
bf49a963
...
@@ -54,7 +54,7 @@ from .views import (
...
@@ -54,7 +54,7 @@ from .views import (
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
OpenSearchDescriptionView
,
OpenSearchDescriptionView
,
NodeActivityView
,
NodeActivityView
,
UserList
,
TemplateREST
,
LeaseREST
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
StorageDetail
,
DiskDetail
,
StorageDetail
,
DiskDetail
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
EnableTwoFactorView
,
DisableTwoFactorView
,
...
@@ -68,6 +68,7 @@ urlpatterns = [
...
@@ -68,6 +68,7 @@ urlpatterns = [
path
(
'acpi/vm/'
,
iac_vm_list
),
path
(
'acpi/vm/'
,
iac_vm_list
),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/disk/'
,
DiskRest
.
as_view
()),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
name
=
"dashboard.views.user-list"
),
name
=
"dashboard.views.user-list"
),
...
...
circle/dashboard/views/storage.py
View file @
bf49a963
...
@@ -21,14 +21,21 @@ from django.urls import reverse
...
@@ -21,14 +21,21 @@ from django.urls import reverse
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic
import
UpdateView
from
django.views.generic
import
UpdateView
from
django.http
import
JsonResponse
from
braces.views
import
SuperuserRequiredMixin
from
braces.views
import
SuperuserRequiredMixin
from
sizefield.utils
import
filesizeformat
from
sizefield.utils
import
filesizeformat
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.views
import
APIView
from
rest_framework.parsers
import
JSONParser
from
common.models
import
WorkerNotFound
from
common.models
import
WorkerNotFound
from
storage.models
import
DataStore
,
Disk
from
storage.models
import
DataStore
,
Disk
from
..tables
import
DiskListTable
from
..tables
import
DiskListTable
from
..forms
import
DataStoreForm
,
DiskForm
from
..forms
import
DataStoreForm
,
DiskForm
from
dashboard.serializers
import
DiskSerializer
class
StorageDetail
(
SuperuserRequiredMixin
,
UpdateView
):
class
StorageDetail
(
SuperuserRequiredMixin
,
UpdateView
):
...
@@ -138,3 +145,21 @@ class DiskDetail(SuperuserRequiredMixin, UpdateView):
...
@@ -138,3 +145,21 @@ class DiskDetail(SuperuserRequiredMixin, UpdateView):
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
pass
pass
class
DiskRest
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
Disk
.
objects
.
all
()
serializer
=
DiskSerializer
(
templates
,
many
=
True
)
return
JsonResponse
({
'disks'
:
serializer
.
data
},
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
DiskSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
\ No newline at end of file
circle/dashboard/views/template.py
View file @
bf49a963
...
@@ -61,7 +61,6 @@ from dashboard.serializers import InstanceTemplateSerializer, LeaseSerializer
...
@@ -61,7 +61,6 @@ from dashboard.serializers import InstanceTemplateSerializer, LeaseSerializer
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.parsers
import
JSONParser
from
rest_framework.parsers
import
JSONParser
try
:
try
:
...
...
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