From 1d5b89f0d58579247a94c6400fffcad7e3307809 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 27 Apr 2016 22:39:11 +0200 Subject: [PATCH] LinuxKernel keep track of own volumes This is squashed woju/qubes-core-admin#8 by @kalkin - LinuxKernel.volumes() lists all available kernels - LinuxKernel use kernel version as vid - LinuxKernel add docstrings - Linux.kernel use os.listdir instead of os.walk - LinuxKernel dynamically list available kernels --- qubes/storage/kernels.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/qubes/storage/kernels.py b/qubes/storage/kernels.py index febbc13c..f524849c 100644 --- a/qubes/storage/kernels.py +++ b/qubes/storage/kernels.py @@ -21,24 +21,27 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # +''' This module contains pool implementations for different OS kernels. ''' import os from qubes.storage import Pool, StoragePoolException, Volume class LinuxModules(Volume): + ''' A volume representing a ro linux kernel ''' rw = False def __init__(self, target_dir, kernel_version, **kwargs): + kwargs['vid'] = kernel_version super(LinuxModules, self).__init__(**kwargs) self.kernels_dir = os.path.join(target_dir, kernel_version) self.path = os.path.join(self.kernels_dir, 'modules.img') - self.vid = self.path self.vmlinuz = os.path.join(self.kernels_dir, 'vmlinuz') self.initramfs = os.path.join(self.kernels_dir, 'initramfs') class LinuxKernel(Pool): + ''' Provides linux kernels ''' driver = 'linux-kernel' def __init__(self, name=None, dir_path=None): @@ -100,6 +103,16 @@ class LinuxKernel(Pool): def stop(self, volume): pass + @property + def volumes(self): + ''' Return all known kernel volumes ''' + return [LinuxModules(self.dir_path, + kernel_version, + pool=self.name, + name=kernel_version, + volume_type='read-only') + for kernel_version in os.listdir(self.dir_path)] + def _check_path(path): ''' Raise an :py:class:`qubes.storage.StoragePoolException` if ``path`` does