Commit 258adab7 by Czémán Arnold

vm, vmdriver: add CephVMDisk attach and detach functionality

parent 2934eb08
...@@ -76,7 +76,9 @@ class VMInstance: ...@@ -76,7 +76,9 @@ class VMInstance:
@classmethod @classmethod
def deserialize(cls, desc): def deserialize(cls, desc):
desc['disk_list'] = [VMDisk.deserialize(d) for d in desc['disk_list']] desc['disk_list'] = [CephVMDisk.deserialize(d)
if d["data_store_type"] == "ceph_block" else
VMDisk.deserialize(d) for d in desc['disk_list']]
desc['network_list'] = [VMNetwork.deserialize( desc['network_list'] = [VMNetwork.deserialize(
n) for n in desc['network_list']] n) for n in desc['network_list']]
return cls(**desc) return cls(**desc)
...@@ -211,6 +213,7 @@ class VMDisk(object): ...@@ -211,6 +213,7 @@ class VMDisk(object):
@classmethod @classmethod
def deserialize(cls, desc): def deserialize(cls, desc):
del desc["data_store_type"]
return cls(**desc) return cls(**desc)
def build_xml(self): def build_xml(self):
...@@ -276,6 +279,7 @@ class CephVMDisk(VMDisk): ...@@ -276,6 +279,7 @@ class CephVMDisk(VMDisk):
@classmethod @classmethod
def deserialize(cls, desc): def deserialize(cls, desc):
del desc["data_store_type"]
return cls(**desc) return cls(**desc)
def build_xml(self): def build_xml(self):
...@@ -286,9 +290,9 @@ class CephVMDisk(VMDisk): ...@@ -286,9 +290,9 @@ class CephVMDisk(VMDisk):
attrib={"name": self.source, attrib={"name": self.source,
"protocol": self.protocol}) "protocol": self.protocol})
for host in self.hosts: for name, port in self.hosts:
ET.SubElement(source, "host", ET.SubElement(source, "host",
attrib=self.__attrib_from_host(host)) attrib={"name": name, "port": unicode(port)})
if self.ceph_user is not None and self.secret_uuid is not None: if self.ceph_user is not None and self.secret_uuid is not None:
auth = ET.SubElement(xml_top, "auth", auth = ET.SubElement(xml_top, "auth",
...@@ -298,17 +302,6 @@ class CephVMDisk(VMDisk): ...@@ -298,17 +302,6 @@ class CephVMDisk(VMDisk):
return xml_top return xml_top
def __attrib_from_host(self, host):
port_pos = host.rfind(':')
port = ""
name = host
if port_pos != -1 and port_pos < len(host):
port = host[port_pos+1:]
name = host[:port_pos]
return {"name": name, "port": port}
class VMNetwork: class VMNetwork:
......
...@@ -12,7 +12,7 @@ from psutil import NUM_CPUS, virtual_memory, cpu_percent ...@@ -12,7 +12,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, CephVMDisk, VMNetwork
from vmcelery import celery, lib_connection, to_bool from vmcelery import celery, lib_connection, to_bool
...@@ -550,20 +550,29 @@ def migrate(name, host, live=False): ...@@ -550,20 +550,29 @@ def migrate(name, host, live=False):
@celery.task @celery.task
@req_connection @req_connection
@wrap_libvirtError @wrap_libvirtError
def attach_disk(name, disk): def attach_disk(name, disk_desc):
""" Attach Disk to a running virtual machine. """ """ Attach Disk to a running virtual machine. """
domain = lookupByName(name) domain = lookupByName(name)
disk = VMDisk.deserialize(disk) disk = None
if disk_desc["data_store_type"] == "ceph_block":
disk = CephVMDisk.deserialize(disk_desc)
else:
disk = VMDisk.deserialize(disk_desc)
domain.attachDevice(disk.dump_xml()) domain.attachDevice(disk.dump_xml())
@celery.task @celery.task
@req_connection @req_connection
@wrap_libvirtError @wrap_libvirtError
def detach_disk(name, disk): def detach_disk(name, disk_desc):
""" Detach disk from a running virtual machine. """ """ Detach disk from a running virtual machine. """
domain = lookupByName(name) domain = lookupByName(name)
disk = VMDisk.deserialize(disk) disk = None
if disk_desc["data_store_type"] == "ceph_block":
disk = CephVMDisk.deserialize(disk_desc)
else:
disk = VMDisk.deserialize(disk_desc)
domain.detachDevice(disk.dump_xml()) domain.detachDevice(disk.dump_xml())
# Libvirt does NOT report failed detach so test it. # Libvirt does NOT report failed detach so test it.
__check_detach(domain, disk.source) __check_detach(domain, disk.source)
......
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