Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
94b6493c
authored
Nov 14, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-365' into 'master'
Issue 365 See merge request
!6
parents
d1909792
2cee7b06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
13 deletions
+35
-13
vmcelery.py
+17
-13
vmdriver.py
+18
-0
No files found.
vmcelery.py
View file @
94b6493c
...
...
@@ -5,24 +5,28 @@ from os import getenv
from
argparse
import
ArgumentParser
parser
=
ArgumentParser
()
parser
.
add_argument
(
"-n"
,
"--hostname"
,
dest
=
"hostname"
,
help
=
"Define the full queue name with"
"with priority"
,
metavar
=
"hostname.queue.priority"
)
(
args
,
unknwon_args
)
=
parser
.
parse_known_args
()
HOSTNAME
=
vars
(
args
)
.
pop
(
"hostname"
)
if
HOSTNAME
is
None
:
raise
Exception
(
"You must define hostname as -n <hostname> or "
"--hostname=<hostname>.
\n
"
"Hostname format must be hostname.module.priority."
)
def
to_bool
(
value
):
return
value
.
lower
()
in
(
"true"
,
"yes"
,
"y"
,
"t"
)
if
to_bool
(
getenv
(
"LIBVIRT_TEST"
,
"False"
)):
HOSTNAME
=
"vmdriver.test"
else
:
parser
=
ArgumentParser
()
parser
.
add_argument
(
"-n"
,
"--hostname"
,
dest
=
"hostname"
,
help
=
"Define the full queue name with"
"with priority"
,
metavar
=
"hostname.queue.priority"
)
(
args
,
unknwon_args
)
=
parser
.
parse_known_args
()
HOSTNAME
=
vars
(
args
)
.
pop
(
"hostname"
)
if
HOSTNAME
is
None
:
raise
Exception
(
"You must define hostname as -n <hostname> or "
"--hostname=<hostname>.
\n
"
"Hostname format must be hostname.module.priority."
)
AMQP_URI
=
getenv
(
'AMQP_URI'
)
CACHE_URI
=
getenv
(
'CACHE_URI'
)
def
to_bool
(
value
):
return
value
.
lower
()
in
(
"true"
,
"yes"
,
"y"
,
"t"
)
# Global configuration parameters declaration
lib_connection
=
None
native_ovs
=
False
...
...
vmdriver.py
View file @
94b6493c
...
...
@@ -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,25 @@ 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 hot plug support is "
"enabled (acpiphp module on Linux)."
)
@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