Add QubesVM.attached_volumes()
This commit is contained in:
parent
ef00ca5702
commit
bb2e6a2ad3
@ -25,7 +25,6 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from lxml import etree
|
||||
|
||||
import qubes
|
||||
import qubes.exc
|
||||
@ -106,10 +105,9 @@ def list_volumes(args):
|
||||
domains = args.domains
|
||||
else:
|
||||
domains = args.app.domains
|
||||
|
||||
for domain in domains: # gather the domain names
|
||||
try:
|
||||
for volume in domain.volumes.values():
|
||||
for volume in domain.attached_volumes:
|
||||
try:
|
||||
volume_data = vd_dict[volume.pool][volume.vid]
|
||||
volume_data.domains += [domain.name]
|
||||
@ -120,19 +118,6 @@ def list_volumes(args):
|
||||
# Skipping domain without volumes
|
||||
continue
|
||||
|
||||
for domain in domains:
|
||||
if domain.qid == 0:
|
||||
continue
|
||||
lvirt = domain.libvirt_domain
|
||||
xml = etree.fromstring(lvirt.XMLDesc())
|
||||
disks = xml.xpath("//domain/devices/disk")
|
||||
for disk in disks:
|
||||
if disk.find('backenddomain') is not None:
|
||||
pool = 'p_%s' % disk.find('backenddomain').get('name')
|
||||
vid = disk.find('source').get('dev').split('/dev/')[1]
|
||||
volume_data = vd_dict[pool][vid]
|
||||
volume_data.domains += [domain.name]
|
||||
|
||||
if hasattr(args, 'domains') and args.domains:
|
||||
result = [x # reduce to only VolumeData with assigned domains
|
||||
for p in vd_dict.itervalues() for x in p.itervalues()
|
||||
|
@ -42,6 +42,10 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
|
||||
default=None,
|
||||
doc='There are other ways to set kernel for Dom0.')
|
||||
|
||||
@property
|
||||
def attached_volumes(self):
|
||||
return []
|
||||
|
||||
@property
|
||||
def xid(self):
|
||||
'''Always ``0``.
|
||||
|
@ -326,6 +326,22 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
||||
e.get_error_code()))
|
||||
raise
|
||||
|
||||
@property
|
||||
def attached_volumes(self):
|
||||
result = []
|
||||
xml_desc = self.libvirt_domain.XMLDesc()
|
||||
xml = lxml.etree.fromstring(xml_desc)
|
||||
for disk in xml.xpath("//domain/devices/disk"):
|
||||
if disk.find('backenddomain') is not None:
|
||||
pool_name = 'p_%s' % disk.find('backenddomain').get('name')
|
||||
pool = self.app.pools[pool_name]
|
||||
vid = disk.find('source').get('dev').split('/dev/')[1]
|
||||
for volume in pool.volumes:
|
||||
if volume.vid == vid:
|
||||
result += [volume]
|
||||
break
|
||||
|
||||
return result + self.volumes.values()
|
||||
|
||||
@property
|
||||
def libvirt_domain(self):
|
||||
|
Loading…
Reference in New Issue
Block a user