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
39db4eb2
authored
Sep 16, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template deploy
parent
355ad49c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
10 deletions
+46
-10
circle/dashboard/serializers.py
+4
-1
circle/dashboard/urls.py
+4
-2
circle/dashboard/views/template.py
+12
-0
circle/dashboard/views/vm.py
+23
-4
circle/vm/operations.py
+3
-3
No files found.
circle/dashboard/serializers.py
View file @
39db4eb2
...
...
@@ -31,7 +31,7 @@ class GroupSerializer(serializers.ModelSerializer):
class
UserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
fields
=
(
'id'
,
'username'
,
'email'
,
'is_staff'
,
'groups'
)
fields
=
(
'id'
,
'username'
,
'email'
,
'is_staff'
,
'groups'
,
'is_superuser'
,
'first_name'
,
'last_name'
)
class
NodeSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -121,6 +121,9 @@ class DownloadDiskSerializer(serializers.Serializer):
url
=
serializers
.
CharField
(
max_length
=
500
)
name
=
serializers
.
CharField
(
max_length
=
100
)
class
CreateTemplateSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
(
max_length
=
100
)
class
DestroyDiskSerializer
(
serializers
.
Serializer
):
disk
=
serializers
.
IntegerField
()
instance
=
serializers
.
IntegerField
(
required
=
False
)
...
...
circle/dashboard/urls.py
View file @
39db4eb2
...
...
@@ -59,10 +59,10 @@ from .views import (
DownloadDiskREST
,
GetInstanceREST
,
GetInterfaceREST
,
ShutdownInstanceREST
,
GetLeaseREST
,
GetDiskRest
,
DeployInstanceREST
,
CreateDiskREST
,
VlanREST
,
ResizeDiskREST
,
GetVlanREST
,
DestroyDiskREST
,
StorageDetail
,
DiskDetail
,
UserREST
,
GroupREST
,
StorageDetail
,
DiskDetail
,
UserREST
,
GroupREST
,
CreateTemplateREST
,
InstanceActivityREST
,
GetInstanceActivityREST
,
GetGroupREST
,
GetUserREST
,
SleepInstanceREST
,
WakeUpInstanceREST
,
DownloadPersistentDiskREST
,
CreatePersistentDiskREST
,
GetStorageActivityREST
,
CreatePersistentDiskREST
,
GetStorageActivityREST
,
GetTemplateREST
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
...
...
@@ -85,6 +85,7 @@ urlpatterns = [
path
(
'acpi/node/'
,
NodeREST
.
as_view
()),
path
(
'acpi/node/<int:pk>/'
,
GetNodeREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/'
,
GetInstanceREST
.
as_view
()),
path
(
'acpi/template/<int:pk>/'
,
GetTemplateREST
.
as_view
()),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/ft/'
,
InstanceFromTemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
...
...
@@ -104,6 +105,7 @@ urlpatterns = [
path
(
'acpi/vm/<int:pk>/wakeup/'
,
WakeUpInstanceREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/resizedisk/'
,
ResizeDiskREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/destroydisk/'
,
DestroyDiskREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/saveastemplate/'
,
CreateTemplateREST
.
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 @
39db4eb2
...
...
@@ -211,6 +211,18 @@ class TemplateREST(APIView):
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
GetTemplateREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
templates
=
InstanceTemplate
.
objects
.
get
(
pk
=
pk
)
serializer
=
InstanceTemplateSerializer
(
templates
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
delete
(
self
,
request
,
pk
,
format
=
None
):
return
JsonResponse
(
status
=
400
)
class
InstanceFromTemplateREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
...
...
circle/dashboard/views/vm.py
View file @
39db4eb2
...
...
@@ -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
,
AddPortOperation
,
ResizeDiskOperation
,
RemoveDiskOperation
,
SleepOperation
,
WakeUpOperation
,
AddPortOperation
,
SaveAsTemplateOperation
,
)
from
common.models
import
(
...
...
@@ -103,7 +103,7 @@ from rest_framework.authentication import TokenAuthentication, BasicAuthenticati
from
rest_framework.permissions
import
IsAdminUser
from
dashboard.serializers
import
(
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
CreateTemplateSerializer
,
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
VMDeploySerializer
,
VlanSerializer
,
ResizeDiskSerializer
,
InstanceActivitySerializer
,
DestroyDiskSerializer
,
StorageActivitySerializer
,
AddPortSerializer
,
)
...
...
@@ -219,6 +219,7 @@ class InstanceREST(APIView):
data
[
'pw'
]
=
pwgen
()
req_deploy
=
False
if
'status'
in
data
:
logger
.
debug
(
' vm-status: '
+
data
[
'status'
])
req_deploy
=
data
[
'status'
]
==
"RUNNING"
data
[
'status'
]
=
'STOPPED'
if
'owner'
not
in
data
:
...
...
@@ -255,8 +256,9 @@ class InstanceREST(APIView):
disk
.
dev_num
=
devnums
.
pop
(
0
)
disk
.
save
()
if
req_deploy
:
DeployOperation
(
inst
)
.
call
(
node
=
None
,
user
=
inst
.
owner
)
if
req_deploy
:
DeployOperation
(
inst
)
.
call
(
node
=
None
,
user
=
inst
.
owner
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
...
...
@@ -375,6 +377,23 @@ class DownloadDiskREST(APIView):
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
CreateTemplateREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
post
(
self
,
request
,
pk
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
CreateTemplateSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
vm_id
=
pk
template_name
=
str
(
data
[
'name'
])
instance
=
Instance
.
objects
.
get
(
pk
=
vm_id
)
SaveAsTemplateOperation
(
instance
)
.
_async
(
name
=
template_name
,
user
=
instance
.
owner
)
act
=
instance
.
get_latest_activity_in_progress
()
serializer
=
InstanceActivitySerializer
(
act
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
CreateDiskREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
...
...
circle/vm/operations.py
View file @
39db4eb2
...
...
@@ -36,7 +36,7 @@ from django.urls import reverse
from
django.db.models
import
Q
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext
as
_
,
ugettext_noop
from
re
import
search
from
re
import
search
,
template
from
sizefield.utils
import
filesizeformat
from
common.models
import
(
...
...
@@ -929,8 +929,8 @@ class SaveAsTemplateOperation(InstanceOperation):
raise
else
:
return
create_readable
(
ugettext_noop
(
"New template:
%(template)
s"
),
template
=
reverse
(
'dashboard.views.template-detail'
,
ugettext_noop
(
"New template:
%(template)
s
(
%(template_id)
s)
"
),
template
_id
=
tmpl
.
id
,
template
=
reverse
(
'dashboard.views.template-detail'
,
kwargs
=
{
'pk'
:
tmpl
.
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