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

View File

@ -31,12 +31,11 @@ import os.path
import re
import subprocess
import lxml.etree
import qubes
import qubes.config
import qubes.storage
import qubes.vm.templatevm
from qubes.devices import BlockDevice
class XenStorage(qubes.storage.Storage):
@ -92,39 +91,19 @@ class XenStorage(qubes.storage.Storage):
'''Path to the volatile image'''
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',
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)
return BlockDevice(path, name, script, rw, domain, devtype)
def root_dev_config(self):
dev_name = 'root'
if isinstance(self.vm, qubes.vm.templatevm.TemplateVM):
return self.format_disk_dev(
'{root}:{rootcow}'.format(
root=self.root_img,
rootcow=self.rootcow_img),
self.root_dev,
dev_name,
script='block-origin')
elif self.vm.hvm and hasattr(self.vm, 'template'):
@ -137,7 +116,7 @@ class XenStorage(qubes.storage.Storage):
'{root}:{volatile}'.format(
root=self.vm.template.storage.root_img,
volatile=self.volatile_img),
self.root_dev,
dev_name,
script='block-snapshot')
elif hasattr(self.vm, 'template'):
@ -154,14 +133,14 @@ class XenStorage(qubes.storage.Storage):
else:
# 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):
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):
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):