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
00680aec
authored
Dec 28, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rest api hotplug
parent
1c898e2e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
1 deletions
+82
-1
circle/dashboard/urls.py
+3
-1
circle/dashboard/views/vm.py
+28
-0
circle/vm/operations.py
+21
-0
circle/vm/tasks/vm_tasks.py
+9
-0
demo.py
+21
-0
No files found.
circle/dashboard/urls.py
View file @
00680aec
...
...
@@ -68,7 +68,7 @@ from .views import (
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
RescheduleView
,
GroupImportView
,
GroupExportView
,
VariableREST
,
GetVariableREST
,
VariableREST
,
GetVariableREST
,
HotplugMemSetREST
,
HotplugVCPUSetREST
)
from
.views.node
import
node_ops
,
NodeREST
,
GetNodeREST
from
.views.vm
import
vm_ops
,
vm_mass_ops
...
...
@@ -102,6 +102,8 @@ urlpatterns = [
path
(
'acpi/interface/<int:pk>/'
,
GetInterfaceREST
.
as_view
()),
path
(
'acpi/ftusers/'
,
InstanceFTforUsersREST
.
as_view
()),
path
(
'acpi/ftusersid/'
,
InstanceFTforUsersIdREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/hotplugmem/'
,
HotplugVCPUSetREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/hotplugvcpu/'
,
HotplugMemSetREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/downloaddisk/'
,
DownloadDiskREST
.
as_view
()),
path
(
'acpi/vm/<int:vm_id>/port/<int:vlan_id>/'
,
SetupPortREST
.
as_view
()),
path
(
'acpi/vm/<int:vm_id>/rules/<int:vlan_id>/'
,
RulesREST
.
as_view
()),
...
...
circle/dashboard/views/vm.py
View file @
00680aec
...
...
@@ -188,6 +188,34 @@ class GetVlanREST(APIView):
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
HotplugMemSetREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
put
(
self
,
request
,
pk
,
format
=
None
):
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
data
=
JSONParser
()
.
parse
(
request
)
ram_size
=
int
(
data
[
"ram_size"
])
instance
.
hotplug_mem
(
user
=
request
.
user
,
memory
=
ram_size
)
instance
.
ram_size
=
ram_size
instance
.
save
()
serializer
=
InstanceSerializer
(
instance
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
class
HotplugVCPUSetREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
put
(
self
,
request
,
pk
,
format
=
None
):
instance
=
Instance
.
objects
.
get
(
pk
=
pk
)
data
=
JSONParser
()
.
parse
(
request
)
num_cores
=
int
(
data
[
"num_cores"
])
instance
.
hotplug_mem
(
user
=
request
.
user
,
vcpu
=
num_cores
)
instance
.
num_cores
=
num_cores
instance
.
save
()
serializer
=
InstanceSerializer
(
instance
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
class
InterfaceREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
...
...
circle/vm/operations.py
View file @
00680aec
...
...
@@ -1457,6 +1457,27 @@ class ScreenshotOperation(RemoteInstanceOperation):
@register_operation
class
HotPlugMem
(
RemoteInstanceOperation
):
id
=
'hotplug_mem'
name
=
_
(
"hotplug_mem"
)
description
=
_
(
""
)
acl_level
=
"owner"
required_perms
=
()
accept_states
=
(
'RUNNING'
,)
task
=
vm_tasks
.
hotplug_memset
@register_operation
class
HotPlugVCPU
(
RemoteInstanceOperation
):
id
=
'hotplug_vcpu'
name
=
_
(
"hotplug_vcpu"
)
description
=
_
(
""
)
acl_level
=
"owner"
required_perms
=
()
accept_states
=
(
'RUNNING'
,)
task
=
vm_tasks
.
hotplug_vcpuset
@register_operation
class
RecoverOperation
(
InstanceOperation
):
id
=
'recover'
name
=
_
(
"recover"
)
...
...
circle/vm/tasks/vm_tasks.py
View file @
00680aec
...
...
@@ -186,3 +186,11 @@ def get_node_metrics(params):
@celery.task
(
name
=
'vmdriver.screenshot'
)
def
screenshot
(
params
):
pass
@celery.task
(
name
=
'vmdriver.hotplug_memset'
)
def
hotplug_memset
(
name
,
memory
):
pass
@celery.task
(
name
=
'vmdriver.hotplug_vcpuset'
)
def
hotplug_vcpuset
(
name
,
vcpu
):
pass
\ No newline at end of file
demo.py
0 → 100644
View file @
00680aec
import
sys
import
libvirt
domName
=
'cloud-9'
conn
=
None
try
:
conn
=
libvirt
.
open
(
"qemu:///system"
)
except
libvirt
.
libvirtError
as
e
:
print
(
repr
(
e
),
file
=
sys
.
stderr
)
exit
(
1
)
dom
=
conn
.
lookupByID
(
7
)
if
dom
==
None
:
print
(
'Failed to find the domain '
+
domName
,
file
=
sys
.
stderr
)
exit
(
1
)
dom
.
setVcpus
(
4
)
conn
.
close
()
exit
(
0
)
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