XenStorage.format_disk_dev returns now BlockDevice

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-03-27 22:30:33 +02:00
parent cc7dd625d9
commit 47e89d84b6
2 changed files with 17 additions and 40 deletions

View File

@ -101,8 +101,7 @@ class Storage(object):
def other_dev_config(self): def other_dev_config(self):
if self.modules_img is not None: if self.modules_img is not None:
return self.format_disk_dev(self.modules_img, self.modules_dev, return BlockDevice(self.modules_img, 'kernel', rw=False)
rw=self.modules_img_rw)
elif self.drive is not None: elif self.drive is not None:
(drive_type, drive_domain, drive_path) = self.drive.split(":") (drive_type, drive_domain, drive_path) = self.drive.split(":")
if drive_type == 'hd': if drive_type == 'hd':
@ -114,19 +113,18 @@ class Storage(object):
drive_domain = None drive_domain = None
return self.format_disk_dev(drive_path, return self.format_disk_dev(drive_path,
self.modules_dev, 'other',
rw=rw, rw=rw,
devtype=drive_type, devtype=drive_type,
domain=drive_domain) domain=drive_domain)
else: else:
return '' return ''
def format_disk_dev(self, path, vdev, script=None, rw=True, devtype='disk', def format_disk_dev(self, path, name, script=None, rw=True, devtype='disk',
domain=None): domain=None):
raise NotImplementedError() raise NotImplementedError()
@property @property
def kernels_dir(self): def kernels_dir(self):
'''Directory where kernel resides. '''Directory where kernel resides.

View File

@ -31,12 +31,11 @@ import os.path
import re import re
import subprocess import subprocess
import lxml.etree
import qubes import qubes
import qubes.config import qubes.config
import qubes.storage import qubes.storage
import qubes.vm.templatevm import qubes.vm.templatevm
from qubes.devices import BlockDevice
class XenStorage(qubes.storage.Storage): class XenStorage(qubes.storage.Storage):
@ -92,39 +91,19 @@ class XenStorage(qubes.storage.Storage):
'''Path to the volatile image''' '''Path to the volatile image'''
return self.abspath(qubes.config.vm_files['volatile_img']) return self.abspath(qubes.config.vm_files['volatile_img'])
def format_disk_dev(self, path, name, script=None, rw=True, devtype='disk',
domain=None):
def format_disk_dev(self, path, vdev, script=None, rw=True, devtype='disk', return BlockDevice(path, name, script, rw, domain, devtype)
domain=None):
if path is None:
return ''
element = lxml.etree.Element('disk')
element.set('type', 'block')
element.set('device', devtype)
element.append(lxml.etree.Element('driver', name='phy'))
element.append(lxml.etree.Element('source', dev=path))
element.append(lxml.etree.Element('target', dev=vdev))
if not rw:
element.append(lxml.etree.Element('readonly'))
if domain is not None:
# XXX vm.name?
element.append(lxml.etree.Element('domain', name=domain))
if script:
element.append(lxml.etree.Element('script', path=script))
# TODO return element
return lxml.etree.tostring(element)
def root_dev_config(self): def root_dev_config(self):
dev_name = 'root'
if isinstance(self.vm, qubes.vm.templatevm.TemplateVM): if isinstance(self.vm, qubes.vm.templatevm.TemplateVM):
return self.format_disk_dev( return self.format_disk_dev(
'{root}:{rootcow}'.format( '{root}:{rootcow}'.format(
root=self.root_img, root=self.root_img,
rootcow=self.rootcow_img), rootcow=self.rootcow_img),
self.root_dev, dev_name,
script='block-origin') script='block-origin')
elif self.vm.hvm and hasattr(self.vm, 'template'): elif self.vm.hvm and hasattr(self.vm, 'template'):
@ -137,7 +116,7 @@ class XenStorage(qubes.storage.Storage):
'{root}:{volatile}'.format( '{root}:{volatile}'.format(
root=self.vm.template.storage.root_img, root=self.vm.template.storage.root_img,
volatile=self.volatile_img), volatile=self.volatile_img),
self.root_dev, dev_name,
script='block-snapshot') script='block-snapshot')
elif hasattr(self.vm, 'template'): elif hasattr(self.vm, 'template'):
@ -154,14 +133,14 @@ class XenStorage(qubes.storage.Storage):
else: else:
# standalone qube # standalone qube
return self.format_disk_dev(self.root_img, self.root_dev) return self.format_disk_dev(self.root_img, dev_name)
def private_dev_config(self): def private_dev_config(self):
return self.format_disk_dev(self.private_img, self.private_dev) return self.format_disk_dev(self.private_img, 'private')
def volatile_dev_config(self): def volatile_dev_config(self):
return self.format_disk_dev(self.volatile_img, self.volatile_dev) return self.format_disk_dev(self.volatile_img, 'volatile')
def create_on_disk_private_img(self, source_template=None): def create_on_disk_private_img(self, source_template=None):