domain: Switch disk listing to return VirtualDisk objects
This commit is contained in:
parent
a5f7f437fb
commit
40d8fc3092
|
@ -1169,7 +1169,7 @@ class vmmAddHardware(gobject.GObject):
|
|||
disks = (self.vm.get_disk_devices() +
|
||||
self.vm.get_disk_devices(inactive=True))
|
||||
for d in disks:
|
||||
used.append(d[2])
|
||||
used.append(d.target)
|
||||
|
||||
disk.generate_target(used)
|
||||
|
||||
|
|
|
@ -289,11 +289,11 @@ class vmmCloneVM(gobject.GObject):
|
|||
all_targets = map(lambda d: d[1], diskinfos)
|
||||
|
||||
for disk in diskinfos:
|
||||
force_target = disk[1]
|
||||
path = disk[3]
|
||||
ro = disk[6]
|
||||
shared = disk[7]
|
||||
devtype = disk[4]
|
||||
force_target = disk.target
|
||||
path = disk.path
|
||||
ro = disk.read_only
|
||||
shared = disk.shareable
|
||||
devtype = disk.device
|
||||
|
||||
size = None
|
||||
clone_path = None
|
||||
|
|
|
@ -232,10 +232,10 @@ def populate_storage_list(storage_list, vm, conn):
|
|||
for disk in vm.get_disk_devices():
|
||||
vol = None
|
||||
|
||||
target = disk[1]
|
||||
path = disk[3]
|
||||
ro = disk[6]
|
||||
shared = disk[7]
|
||||
target = disk.target
|
||||
path = disk.path
|
||||
ro = disk.read_only
|
||||
shared = disk.shareable
|
||||
|
||||
# There are a few pieces here
|
||||
# 1) Can we even delete the storage? If not, make the checkbox
|
||||
|
|
|
@ -1218,13 +1218,13 @@ class vmmDetails(gobject.GObject):
|
|||
|
||||
# CDROM Eject/Connect
|
||||
def toggle_storage_media(self, src):
|
||||
diskinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not diskinfo:
|
||||
disk = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not disk:
|
||||
return
|
||||
|
||||
dev_id_info = diskinfo[1]
|
||||
curpath = diskinfo[3]
|
||||
devtype = diskinfo[4]
|
||||
dev_id_info = disk.target
|
||||
curpath = disk.path
|
||||
devtype = disk.device
|
||||
|
||||
if curpath:
|
||||
# Disconnect cdrom
|
||||
|
@ -1792,17 +1792,17 @@ class vmmDetails(gobject.GObject):
|
|||
|
||||
|
||||
def refresh_disk_page(self):
|
||||
diskinfo = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not diskinfo:
|
||||
disk = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||
if not disk:
|
||||
return
|
||||
|
||||
path = diskinfo[3]
|
||||
devtype = diskinfo[4]
|
||||
ro = diskinfo[6]
|
||||
share = diskinfo[7]
|
||||
bus = diskinfo[8]
|
||||
idx = diskinfo[9]
|
||||
cache = diskinfo[10]
|
||||
path = disk.path
|
||||
devtype = disk.device
|
||||
ro = disk.read_only
|
||||
share = disk.shareable
|
||||
bus = disk.bus
|
||||
idx = disk.disk_bus_index
|
||||
cache = disk.driver_cache
|
||||
|
||||
size = _("Unknown")
|
||||
if not path:
|
||||
|
@ -2140,16 +2140,19 @@ class vmmDetails(gobject.GObject):
|
|||
insertAt += 1
|
||||
|
||||
# Add the new HW row
|
||||
devtype = info[0]
|
||||
if type(info) is list:
|
||||
devtype = info[0]
|
||||
else:
|
||||
devtype = info.virtual_device_type
|
||||
add_hw_list_option(insertAt, name, hwtype, info, icon_name, key,
|
||||
devtype)
|
||||
|
||||
# Populate list of disks
|
||||
for diskinfo in self.vm.get_disk_devices():
|
||||
key = str(diskinfo[1])
|
||||
devtype = diskinfo[4]
|
||||
bus = diskinfo[8]
|
||||
idx = diskinfo[9]
|
||||
for disk in self.vm.get_disk_devices():
|
||||
key = disk.target
|
||||
devtype = disk.device
|
||||
bus = disk.bus
|
||||
idx = disk.disk_bus_index
|
||||
|
||||
currentDisks[key] = 1
|
||||
icon = "drive-harddisk"
|
||||
|
@ -2160,7 +2163,7 @@ class vmmDetails(gobject.GObject):
|
|||
|
||||
label = prettyify_disk(devtype, bus, idx)
|
||||
|
||||
update_hwlist(HW_LIST_TYPE_DISK, diskinfo, label, icon, key)
|
||||
update_hwlist(HW_LIST_TYPE_DISK, disk, label, icon, key)
|
||||
|
||||
# Populate list of NICs
|
||||
for netinfo in self.vm.get_network_devices():
|
||||
|
|
|
@ -409,61 +409,30 @@ class vmmDomainBase(vmmLibvirtObject):
|
|||
# ----------------
|
||||
|
||||
def get_disk_devices(self, refresh_if_necc=True, inactive=False):
|
||||
def _parse_disk_devs(ctx):
|
||||
disks = []
|
||||
ret = ctx.xpathEval("/domain/devices/disk")
|
||||
for node in ret:
|
||||
typ = node.prop("type")
|
||||
srcpath = None
|
||||
devdst = None
|
||||
bus = None
|
||||
readonly = False
|
||||
sharable = False
|
||||
devtype = node.prop("device")
|
||||
cache = None
|
||||
if devtype == None:
|
||||
devtype = "disk"
|
||||
for child in node.children:
|
||||
if child.name == "source":
|
||||
propname = disk_type_to_target_prop(typ)
|
||||
srcpath = child.prop(propname)
|
||||
elif child.name == "target":
|
||||
devdst = child.prop("dev")
|
||||
bus = child.prop("bus")
|
||||
elif child.name == "readonly":
|
||||
readonly = True
|
||||
elif child.name == "shareable":
|
||||
sharable = True
|
||||
elif child.name == "driver":
|
||||
cache = child.prop("cache")
|
||||
device_type = "disk"
|
||||
guest = self._get_guest(refresh_if_necc, inactive)
|
||||
|
||||
if srcpath == None:
|
||||
if devtype == "cdrom" or devtype == "floppy":
|
||||
typ = "block"
|
||||
# [ devicetype, unique, device target, source path,
|
||||
# disk device type, disk type, readonly?, sharable?,
|
||||
# bus type, disk idx ]
|
||||
|
||||
# [ devicetype, unique, device target, source path,
|
||||
# disk device type, disk type, readonly?, sharable?,
|
||||
# bus type, disk idx ]
|
||||
disks.append(["disk", devdst, devdst, srcpath, devtype, typ,
|
||||
readonly, sharable, bus, 0, cache])
|
||||
disks = guest.get_devices(device_type)
|
||||
|
||||
# Iterate through all disks and calculate what number they are
|
||||
idx_mapping = {}
|
||||
for disk in disks:
|
||||
devtype = disk[4]
|
||||
bus = disk[8]
|
||||
key = devtype + (bus or "")
|
||||
# Iterate through all disks and calculate what number they are
|
||||
# HACK: We are making a variable in VirtualDisk to store the index
|
||||
idx_mapping = {}
|
||||
for disk in disks:
|
||||
devtype = disk.device
|
||||
bus = disk.bus
|
||||
key = devtype + (bus or "")
|
||||
|
||||
if not idx_mapping.has_key(key):
|
||||
idx_mapping[key] = 1
|
||||
if not idx_mapping.has_key(key):
|
||||
idx_mapping[key] = 1
|
||||
|
||||
disk[9] = idx_mapping[key]
|
||||
idx_mapping[key] += 1
|
||||
disk.disk_bus_index = idx_mapping[key]
|
||||
idx_mapping[key] += 1
|
||||
|
||||
return disks
|
||||
|
||||
return self._parse_device_xml(_parse_disk_devs, refresh_if_necc,
|
||||
inactive)
|
||||
return disks
|
||||
|
||||
def get_network_devices(self, refresh_if_necc=True):
|
||||
def _parse_network_devs(ctx):
|
||||
|
@ -953,7 +922,7 @@ class vmmDomainBase(vmmLibvirtObject):
|
|||
return rd, wr
|
||||
|
||||
for disk in self.get_disk_devices(refresh_if_necc=False):
|
||||
dev = disk[2]
|
||||
dev = disk.target
|
||||
if not dev:
|
||||
continue
|
||||
|
||||
|
|
Loading…
Reference in New Issue