Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8bb951d9
authored
Nov 13, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add check_detach function
parent
8813e370
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
vmdriver.py
+17
-0
No files found.
vmdriver.py
View file @
8bb951d9
...
...
@@ -13,6 +13,7 @@ from psutil import NUM_CPUS, virtual_memory, cpu_percent
from
celery.contrib.abortable
import
AbortableTask
from
vm
import
VMInstance
,
VMDisk
,
VMNetwork
from
vmcelery
import
celery
,
lib_connection
,
to_bool
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
basename
(
__file__
)))
...
...
@@ -550,6 +551,7 @@ def migrate(name, host, live=False):
@req_connection
@wrap_libvirtError
def
attach_disk
(
name
,
disk
):
""" Attach Disk to a running virtual machine. """
domain
=
lookupByName
(
name
)
disk
=
VMDisk
.
deserialize
(
disk
)
domain
.
attachDevice
(
disk
.
dump_xml
())
...
...
@@ -559,9 +561,24 @@ def attach_disk(name, disk):
@req_connection
@wrap_libvirtError
def
detach_disk
(
name
,
disk
):
""" Detach disk from a running virtual machine. """
domain
=
lookupByName
(
name
)
disk
=
VMDisk
.
deserialize
(
disk
)
domain
.
detachDevice
(
disk
.
dump_xml
())
# Libvirt does NOT report failed detach so test it.
__check_detach
(
domain
,
disk
.
source
)
def
__check_detach
(
domain
,
disk
):
""" Test if detach was successfull by searching
for disk in the XML"""
xml
=
domain
.
XMLDesc
()
root
=
ET
.
fromstring
(
xml
)
devices
=
root
.
find
(
'devices'
)
for
d
in
devices
.
findall
(
"disk"
):
if
disk
in
d
.
find
(
'source'
)
.
attrib
.
values
()[
0
]:
raise
Exception
(
"Disk could not been detached. "
"Check if acpiphp module is loaded."
)
@celery.task
...
...
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