1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +00:00

rename type variable, add bus info while getting media devices. remove unnecessary control while detaching the disk

This commit is contained in:
catborise 2018-11-23 15:05:30 +03:00
parent 08451a06a4
commit 469cc0560c

View file

@ -298,6 +298,7 @@ class wvmInstance(wvmConnect):
if device == 'cdrom': if device == 'cdrom':
try: try:
dev = media.xpath('target/@dev')[0] dev = media.xpath('target/@dev')[0]
bus = media.xpath('target/@bus')[0]
try: try:
src_fl = media.xpath('source/@file')[0] src_fl = media.xpath('source/@file')[0]
vol = self.get_volume_by_path(src_fl) vol = self.get_volume_by_path(src_fl)
@ -310,7 +311,7 @@ class wvmInstance(wvmConnect):
except: except:
pass pass
finally: finally:
result.append({'dev': dev, 'image': volume, 'storage': storage, 'path': src_fl}) result.append({'dev': dev, 'image': volume, 'storage': storage, 'path': src_fl, 'bus': bus})
return result return result
return util.get_xml_path(self._XMLDesc(0), func=disks) return util.get_xml_path(self._XMLDesc(0), func=disks)
@ -364,7 +365,7 @@ class wvmInstance(wvmConnect):
xmldom = ElementTree.tostring(tree) xmldom = ElementTree.tostring(tree)
self._defineXML(xmldom) self._defineXML(xmldom)
def attach_disk(self, source, target, sourcetype='file', type='disk', driver='qemu', subdriver='raw', cache='none', targetbus='ide'): def attach_disk(self, source, target, sourcetype='file', device='disk', driver='qemu', subdriver='raw', cache='none', targetbus='ide'):
tree = ElementTree.fromstring(self._XMLDesc(0)) tree = ElementTree.fromstring(self._XMLDesc(0))
xml_disk = """ xml_disk = """
<disk type='%s' device='%s'> <disk type='%s' device='%s'>
@ -372,7 +373,7 @@ class wvmInstance(wvmConnect):
<source file='%s'/> <source file='%s'/>
<target dev='%s' bus='%s'/> <target dev='%s' bus='%s'/>
</disk> </disk>
""" % (sourcetype, type, driver, subdriver, cache, source, target, targetbus) """ % (sourcetype, device, driver, subdriver, cache, source, target, targetbus)
if self.get_status() == 5: if self.get_status() == 5:
devices = tree.find('devices') devices = tree.find('devices')
elm_disk = ElementTree.fromstring(xml_disk) elm_disk = ElementTree.fromstring(xml_disk)
@ -380,19 +381,18 @@ class wvmInstance(wvmConnect):
xmldom = ElementTree.tostring(tree) xmldom = ElementTree.tostring(tree)
self._defineXML(xmldom) self._defineXML(xmldom)
def detach_disk(self, dev, image): def detach_disk(self, dev):
tree = ElementTree.fromstring(self._XMLDesc(0)) tree = ElementTree.fromstring(self._XMLDesc(0))
for disk in tree.findall("./devices/disk[@device='disk']"): for disk in tree.findall("./devices/disk"):
source = disk.find("source")
target = disk.find("target") target = disk.find("target")
if source.get("file") == image and target.get("dev") == dev: if target.get("dev") == dev:
devices = tree.find('devices') devices = tree.find('devices')
devices.remove(disk) devices.remove(disk)
if self.get_status() == 1: if self.get_status() == 1:
xml_disk = ElementTree.tostring(disk) xml_disk = ElementTree.tostring(disk)
yyy = self.instance.detachDevice(xml_disk) ret = self.instance.detachDevice(xml_disk)
xmldom = self._XMLDesc(VIR_DOMAIN_XML_SECURE) xmldom = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
if self.get_status() == 5: if self.get_status() == 5:
xmldom = ElementTree.tostring(tree) xmldom = ElementTree.tostring(tree)