From 7d14377eba16ed21f78bc0e6001371c733862407 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Mon, 18 Jan 2016 16:53:08 +0300 Subject: [PATCH] Make base class for data drivers more granular Some data drivers may not have properties, defined in the base, also data driver may implement its own abstract classes. For example Dynamic Allocator provides a driver which implements partition_scheme property. Change-Id: Ifc005db73a7b52c7bf3a5038d28f17e7de05aa98 blueprint: pluggable-do-actions --- bareon/drivers/base.py | 24 ++++++++++++++++++++---- bareon/drivers/nailgun.py | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/bareon/drivers/base.py b/bareon/drivers/base.py index 7fb7f10..9586e7c 100644 --- a/bareon/drivers/base.py +++ b/bareon/drivers/base.py @@ -29,22 +29,38 @@ class BaseDataDriver(object): def __init__(self, data): self.data = copy.deepcopy(data) + +@six.add_metaclass(abc.ABCMeta) +class PartitioningDataDriverMixin(object): + @abc.abstractproperty def partition_scheme(self): """Retruns instance of PartionScheme object""" + +@six.add_metaclass(abc.ABCMeta) +class ProvisioningDataDriverMixin(object): + @abc.abstractproperty def image_scheme(self): """Returns instance of ImageScheme object""" - @abc.abstractproperty - def grub(self): - """Returns instance of Grub object""" - @abc.abstractproperty def operating_system(self): """Returns instance of OperatingSystem object""" + +@six.add_metaclass(abc.ABCMeta) +class ConfigDriveDataDriverMixin(object): + @abc.abstractproperty def configdrive_scheme(self): """Returns instance of ConfigDriveScheme object""" + + +@six.add_metaclass(abc.ABCMeta) +class GrubBootloaderDataDriverMixin(object): + + @abc.abstractproperty + def grub(self): + """Returns instance of Grub object""" diff --git a/bareon/drivers/nailgun.py b/bareon/drivers/nailgun.py index 462a24f..1d3b152 100644 --- a/bareon/drivers/nailgun.py +++ b/bareon/drivers/nailgun.py @@ -24,6 +24,10 @@ from six.moves.urllib.parse import urlsplit import yaml from bareon.drivers.base import BaseDataDriver +from bareon.drivers.base import ConfigDriveDataDriverMixin +from bareon.drivers.base import GrubBootloaderDataDriverMixin +from bareon.drivers.base import PartitioningDataDriverMixin +from bareon.drivers.base import ProvisioningDataDriverMixin from bareon.drivers import ks_spaces_validator from bareon import errors from bareon import objects @@ -71,7 +75,11 @@ def match_device(hu_disk, ks_disk): return False -class Nailgun(BaseDataDriver): +class Nailgun(BaseDataDriver, + PartitioningDataDriverMixin, + ProvisioningDataDriverMixin, + ConfigDriveDataDriverMixin, + GrubBootloaderDataDriverMixin): """Driver for parsing regular volumes metadata from Nailgun.""" def __init__(self, data): @@ -624,7 +632,10 @@ class Ironic(Nailgun): return super(Ironic, self).parse_partition_scheme() -class NailgunBuildImage(BaseDataDriver): +class NailgunBuildImage(BaseDataDriver, + ProvisioningDataDriverMixin, + ConfigDriveDataDriverMixin, + GrubBootloaderDataDriverMixin): # TODO(kozhukalov): # This list of packages is used by default only if another