Add QubesVM.attached_volumes()
This commit is contained in:
parent
ef00ca5702
commit
bb2e6a2ad3
@ -25,7 +25,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from lxml import etree
|
|
||||||
|
|
||||||
import qubes
|
import qubes
|
||||||
import qubes.exc
|
import qubes.exc
|
||||||
@ -106,10 +105,9 @@ def list_volumes(args):
|
|||||||
domains = args.domains
|
domains = args.domains
|
||||||
else:
|
else:
|
||||||
domains = args.app.domains
|
domains = args.app.domains
|
||||||
|
|
||||||
for domain in domains: # gather the domain names
|
for domain in domains: # gather the domain names
|
||||||
try:
|
try:
|
||||||
for volume in domain.volumes.values():
|
for volume in domain.attached_volumes:
|
||||||
try:
|
try:
|
||||||
volume_data = vd_dict[volume.pool][volume.vid]
|
volume_data = vd_dict[volume.pool][volume.vid]
|
||||||
volume_data.domains += [domain.name]
|
volume_data.domains += [domain.name]
|
||||||
@ -120,19 +118,6 @@ def list_volumes(args):
|
|||||||
# Skipping domain without volumes
|
# Skipping domain without volumes
|
||||||
continue
|
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:
|
if hasattr(args, 'domains') and args.domains:
|
||||||
result = [x # reduce to only VolumeData with assigned domains
|
result = [x # reduce to only VolumeData with assigned domains
|
||||||
for p in vd_dict.itervalues() for x in p.itervalues()
|
for p in vd_dict.itervalues() for x in p.itervalues()
|
||||||
|
@ -42,6 +42,10 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
|
|||||||
default=None,
|
default=None,
|
||||||
doc='There are other ways to set kernel for Dom0.')
|
doc='There are other ways to set kernel for Dom0.')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def attached_volumes(self):
|
||||||
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def xid(self):
|
def xid(self):
|
||||||
'''Always ``0``.
|
'''Always ``0``.
|
||||||
|
@ -326,6 +326,22 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
|||||||
e.get_error_code()))
|
e.get_error_code()))
|
||||||
raise
|
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
|
@property
|
||||||
def libvirt_domain(self):
|
def libvirt_domain(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user