Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gabriel Monnerat
slapos.toolbox
Commits
3a41efec
Commit
3a41efec
authored
Feb 07, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
f3aa60e4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
23 deletions
+33
-23
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+32
-22
slapos/test/test_qemuqmpclient.py
slapos/test/test_qemuqmpclient.py
+1
-1
No files found.
slapos/qemuqmpclient/__init__.py
View file @
3a41efec
...
...
@@ -69,13 +69,20 @@ def getInitialQemuResourceDict(pid_file):
return
None
with
open
(
pid_file
)
as
f
:
try
:
pid
=
int
(
f
.
read
())
except
ValueError
,
e
:
raise
ValueError
(
"%r is empty or doesn't contain a valid pid number: %s"
%
(
pid_file
,
str
(
e
)))
try
:
process
=
psutil
.
Process
(
pid
)
except
psutil
.
NoSuchProcess
:
print
'No process with pid %s'
%
pid
return
None
raise
ValueError
(
'No process with pid %s'
%
pid
)
if
not
process
.
name
().
startswith
(
'qemu-system'
):
raise
ValueError
(
"The pid %s is used by %r and not a qemu process."
%
(
pid
,
process
.
name
()))
resource_dict
=
{
'cpu'
:
None
,
'ram'
:
None
}
cmd_list
=
process
.
cmdline
()
cpu_index
=
cmd_list
.
index
(
'-smp'
)
...
...
@@ -137,7 +144,10 @@ class QemuQMPWrapper(object):
data
=
self
.
sockf
.
readline
()
if
not
data
:
return
try
:
response
=
json
.
loads
(
data
)
except
ValueError
:
raise
ValueError
(
'Wrong data: %s'
%
data
)
if
'error'
in
response
:
raise
QmpCommandError
(
response
[
"error"
][
"desc"
])
if
'event'
in
response
:
...
...
@@ -148,18 +158,17 @@ class QemuQMPWrapper(object):
return
response
def
_send
(
self
,
message
):
def
_send
(
self
,
message
,
retry
=
0
,
sleep
=
0.5
):
self
.
socket
.
sendall
(
json
.
dumps
(
message
))
return
self
.
_readResponse
()
def
_sendRetry
(
self
,
message
):
"""
Send Qmp message and retry once if the result is None
"""
result
=
self
.
_send
(
message
)
if
result
is
None
:
return
self
.
_send
(
message
)
return
result
response
=
self
.
_readResponse
()
for
i
in
range
(
0
,
retry
):
if
response
is
not
None
:
break
print
"Retrying send command after %s second(s)..."
%
sleep
time
.
sleep
(
sleep
)
self
.
socket
.
sendall
(
json
.
dumps
(
message
))
response
=
self
.
_readResponse
()
return
response
def
_getVMStatus
(
self
):
response
=
self
.
_send
({
'execute'
:
'query-status'
})
...
...
@@ -317,9 +326,9 @@ class QemuQMPWrapper(object):
return some info about VM CPUs
"""
cpu_info_dict
=
{
'hotplugged'
:
[],
'base'
:
[]}
cpu_list
=
self
.
_send
Retry
({
cpu_list
=
self
.
_send
({
'execute'
:
'query-cpus'
})[
'return'
]
}
,
retry
=
5
)[
'return'
]
for
cpu
in
cpu_list
:
if
'unattached'
in
cpu
[
'qom_path'
]:
index
=
'base'
...
...
@@ -337,9 +346,9 @@ class QemuQMPWrapper(object):
return some info about VM Memory. Can only say info about hotplugged RAM
"""
mem_info_dict
=
{
'hotplugged'
:
[],
'base'
:
[]}
memory_list
=
self
.
_send
Retry
({
memory_list
=
self
.
_send
({
'execute'
:
'query-memory-devices'
})[
'return'
]
}
,
retry
=
5
)[
'return'
]
for
mem
in
memory_list
:
if
mem
[
'data'
][
'hotplugged'
]
==
True
:
mem_info_dict
[
'hotplugged'
].
append
(
mem
[
'data'
])
...
...
@@ -386,6 +395,7 @@ class QemuQMPWrapper(object):
raise
ValueError
(
"Cannot remove device %s"
%
dev_id
)
# try soft reboot of the VM
print
"Powering down the VM..."
self
.
powerdown
()
system_exited
=
False
# wait for ~10 seconds if the system exit, else quit Qemu
...
...
@@ -418,7 +428,7 @@ class QemuQMPWrapper(object):
unremovable_cpu
=
0
cpu_hotplugable_list
=
self
.
_send
({
'execute'
:
'query-hotpluggable-cpus'
})[
'return'
]
}
,
retry
=
5
)[
'return'
]
cpu_hotplugable_list
.
reverse
()
for
cpu
in
cpu_hotplugable_list
:
if
cpu
.
get
(
'qom-path'
,
''
)
==
''
:
...
...
@@ -508,8 +518,8 @@ class QemuQMPWrapper(object):
num_slot_used
=
0
memory_id_list
=
[]
# current hotplugged memory
cleanup_memdev_id_dict
=
{}
current_dimm_list
=
self
.
_send
({
"execute"
:
"query-memory-devices"
})
current_memdev_list
=
self
.
_send
({
"execute"
:
"query-memdev"
})
current_dimm_list
=
self
.
_send
({
"execute"
:
"query-memory-devices"
}
,
retry
=
5
)
current_memdev_list
=
self
.
_send
({
"execute"
:
"query-memdev"
}
,
retry
=
5
)
for
memdev
in
current_memdev_list
[
'return'
]:
cleanup_memdev_id_dict
[
memdev
[
'id'
]]
=
''
...
...
slapos/test/test_qemuqmpclient.py
View file @
3a41efec
...
...
@@ -76,7 +76,7 @@ class TestQemuQMPWrapper(unittest.TestCase):
if
message
[
'arguments'
][
'id'
].
startswith
(
'cpu'
):
self
.
setChange
(
'cpu'
,
-
1
)
if
self
.
fail
:
return
{
"error"
:
{
"class"
:
"CommandFailed"
,
"
message
"
:
""
}}
return
{
"error"
:
{
"class"
:
"CommandFailed"
,
"
desc
"
:
""
}}
return
{
"return"
:
{}}
def
fake_getEventList
(
self
,
timeout
=
0
,
cleanup
=
False
):
...
...
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