Commit 94b6493c by Guba Sándor

Merge branch 'issue-365' into 'master'

Issue 365

See merge request !6
parents d1909792 2cee7b06
...@@ -5,24 +5,28 @@ from os import getenv ...@@ -5,24 +5,28 @@ from os import getenv
from argparse import ArgumentParser from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-n", "--hostname", dest="hostname", def to_bool(value):
help="Define the full queue name with" return value.lower() in ("true", "yes", "y", "t")
"with priority", metavar="hostname.queue.priority")
(args, unknwon_args) = parser.parse_known_args() if to_bool(getenv("LIBVIRT_TEST", "False")):
HOSTNAME = vars(args).pop("hostname") HOSTNAME = "vmdriver.test"
if HOSTNAME is None: else:
raise Exception("You must define hostname as -n <hostname> or " parser = ArgumentParser()
"--hostname=<hostname>.\n" parser.add_argument("-n", "--hostname", dest="hostname",
"Hostname format must be hostname.module.priority.") 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') AMQP_URI = getenv('AMQP_URI')
CACHE_URI = getenv('CACHE_URI') CACHE_URI = getenv('CACHE_URI')
def to_bool(value):
return value.lower() in ("true", "yes", "y", "t")
# Global configuration parameters declaration # Global configuration parameters declaration
lib_connection = None lib_connection = None
native_ovs = False native_ovs = False
......
...@@ -13,6 +13,7 @@ from psutil import NUM_CPUS, virtual_memory, cpu_percent ...@@ -13,6 +13,7 @@ from psutil import NUM_CPUS, virtual_memory, cpu_percent
from celery.contrib.abortable import AbortableTask from celery.contrib.abortable import AbortableTask
from vm import VMInstance, VMDisk, VMNetwork from vm import VMInstance, VMDisk, VMNetwork
from vmcelery import celery, lib_connection, to_bool from vmcelery import celery, lib_connection, to_bool
sys.path.append(os.path.dirname(os.path.basename(__file__))) sys.path.append(os.path.dirname(os.path.basename(__file__)))
...@@ -550,6 +551,7 @@ def migrate(name, host, live=False): ...@@ -550,6 +551,7 @@ def migrate(name, host, live=False):
@req_connection @req_connection
@wrap_libvirtError @wrap_libvirtError
def attach_disk(name, disk): def attach_disk(name, disk):
""" Attach Disk to a running virtual machine. """
domain = lookupByName(name) domain = lookupByName(name)
disk = VMDisk.deserialize(disk) disk = VMDisk.deserialize(disk)
domain.attachDevice(disk.dump_xml()) domain.attachDevice(disk.dump_xml())
...@@ -559,9 +561,25 @@ def attach_disk(name, disk): ...@@ -559,9 +561,25 @@ def attach_disk(name, disk):
@req_connection @req_connection
@wrap_libvirtError @wrap_libvirtError
def detach_disk(name, disk): def detach_disk(name, disk):
""" Detach disk from a running virtual machine. """
domain = lookupByName(name) domain = lookupByName(name)
disk = VMDisk.deserialize(disk) disk = VMDisk.deserialize(disk)
domain.detachDevice(disk.dump_xml()) 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 @celery.task
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment