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
5485381c
authored
Aug 30, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lease and template serializers and api points
parent
70545e0d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
3 deletions
+86
-3
circle/dashboard/serializers.py
+21
-0
circle/dashboard/urls.py
+4
-2
circle/dashboard/views/template.py
+46
-1
circle/dashboard/views/vm.py
+15
-0
No files found.
circle/dashboard/serializers.py
0 → 100644
View file @
5485381c
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework
import
serializers
from
vm.models
import
InstanceTemplate
,
Lease
class
InstanceTemplateSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
InstanceTemplate
resource_name
=
'template'
fields
=
[
'id'
,
'name'
,
'description'
,
'parent'
,
'owner'
,
'access_method'
,
'boot_menu'
,
'lease'
,
'raw_data'
,
'cloud_init'
,
'ci_meta_data'
,
'ci_user_data'
,
'system'
,
'has_agent'
,
'num_cores'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'priority'
]
class
LeaseSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Lease
resource_name
=
'lease'
fields
=
[
'id'
,
'name'
,
'suspend_interval_seconds'
,
'delete_interval_seconds'
]
circle/dashboard/urls.py
View file @
5485381c
...
...
@@ -54,7 +54,7 @@ from .views import (
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
OpenSearchDescriptionView
,
NodeActivityView
,
UserList
,
UserList
,
TemplateREST
,
LeaseREST
,
StorageDetail
,
DiskDetail
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
...
...
@@ -65,7 +65,9 @@ from .views.node import node_ops
from
.views.vm
import
vm_ops
,
vm_mass_ops
urlpatterns
=
[
path
(
'acpi/vmlist'
,
iac_vm_list
),
path
(
'acpi/vm/'
,
iac_vm_list
),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
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/template.py
View file @
5485381c
...
...
@@ -26,7 +26,7 @@ from django.contrib.messages.views import SuccessMessageMixin
from
django.urls
import
reverse
,
reverse_lazy
from
django.core.exceptions
import
PermissionDenied
,
SuspiciousOperation
from
django.db.models
import
Count
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
JsonResponse
from
django.shortcuts
import
redirect
,
get_object_or_404
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext
as
_
,
ugettext_noop
...
...
@@ -56,6 +56,14 @@ from .util import (
GraphMixin
)
from
dashboard.serializers
import
InstanceTemplateSerializer
,
LeaseSerializer
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.parsers
import
JSONParser
try
:
# Python 2: "unicode" is built-in
unicode
...
...
@@ -184,6 +192,43 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
return
reverse_lazy
(
"dashboard.views.template-list"
)
class
TemplateREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
InstanceTemplate
.
objects
.
all
()
serializer
=
InstanceTemplateSerializer
(
templates
,
many
=
True
)
return
JsonResponse
({
'templates'
:
serializer
.
data
},
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
InstanceTemplateSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
LeaseREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
Lease
.
objects
.
all
()
serializer
=
LeaseSerializer
(
templates
,
many
=
True
)
return
JsonResponse
({
'leases'
:
serializer
.
data
},
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
LeaseSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
TemplateAclUpdateView
(
AclUpdateView
):
model
=
InstanceTemplate
...
...
circle/dashboard/views/vm.py
View file @
5485381c
...
...
@@ -105,10 +105,25 @@ def iac_vm_list(request):
'host'
:
i
.
short_hostname
,
'status'
:
i
.
get_status_display
(),
'owner'
:
(
i
.
owner
.
profile
.
get_display_name
()),
'node'
:
i
.
node
,
'timesuspend'
:
i
.
time_of_suspend
,
'timedelete'
:
i
.
time_of_delete
,
'timedestroy'
:
i
.
destroyed_at
,
'userdata'
:
i
.
get_user_data
,
'metadata'
:
i
.
get_meta_data
,
'template'
:
i
.
template
.
pk
if
i
.
template
else
None
,
'users'
:
list
({
'username'
:
u
.
username
,
'level'
:
l
}
for
u
,
l
in
i
.
get_users_with_level
()),
}
for
i
in
instances
]
return
Response
(
instances
)
@api_view
([
'POST'
])
@authentication_classes
([
TokenAuthentication
])
@permission_classes
([
IsAdminUser
])
def
iac_vm_create
(
request
):
return
Response
()
class
VmDetailVncTokenView
(
CheckedDetailView
):
template_name
=
"dashboard/vm-detail.html"
model
=
Instance
...
...
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