Adds plugin platform and min os version check

Some plugins support only a given platform and / or a minimum OS version.

ExtendVolumesPlugin is not supported on Windows XP.

This commit adds support for filtering the plugins based on OS
requirements.
This commit is contained in:
Alessandro Pilotti 2013-08-15 21:30:25 +03:00
parent bc9a082142
commit e9b28c51af
4 changed files with 39 additions and 4 deletions

View File

@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
from cloudbaseinit.metadata import factory as metadata_factory
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.osutils import factory as osutils_factory
@ -35,7 +37,7 @@ class InitManager(object):
self._PLUGINS_CONFIG_SECTION)
def _exec_plugin(self, osutils, service, plugin):
plugin_name = plugin.__class__.__name__
plugin_name = plugin.get_name()
status = self._get_plugin_status(osutils, plugin_name)
if status == plugins_base.PLUGIN_EXECUTION_DONE:
@ -53,6 +55,26 @@ class InitManager(object):
'with error \'%(ex)s\'' % locals())
LOG.exception(ex)
def _check_plugin_os_requirements(self, osutils, plugin):
supported = False
plugin_name = plugin.get_name()
(required_platform, min_os_version) = plugin.get_os_requirements()
if required_platform and sys.platform != required_platform:
LOG.debug('Skipping plugin: \'%s\'. Platform not supported' %
plugin_name)
else:
if not min_os_version:
supported = True
else:
os_version = map(int, osutils.get_os_version().split('.'))
if os_version >= list(min_os_version):
supported = True
else:
LOG.debug('Skipping plugin: \'%s\'. OS version not '
'supported' % plugin_name)
return supported
def configure_host(self):
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
osutils.wait_for_boot_completion()
@ -60,15 +82,16 @@ class InitManager(object):
mdsf = metadata_factory.MetadataServiceFactory()
service = mdsf.get_metadata_service()
LOG.info('Metadata service loaded: \'%s\'' %
service.__class__.__name__)
service.get_name())
plugins = plugins_factory.PluginFactory().load_plugins()
reboot_required = False
try:
for plugin in plugins:
if self._exec_plugin(osutils, service, plugin):
reboot_required = True
if self._check_plugin_os_requirements(osutils, plugin):
if self._exec_plugin(osutils, service, plugin):
reboot_required = True
finally:
service.cleanup()

View File

@ -46,6 +46,9 @@ class BaseMetadataService(object):
self._cache = {}
self._enable_retry = False
def get_name(self):
return self.__class__.__name__
def load(self):
self._cache = {}

View File

@ -19,5 +19,11 @@ PLUGIN_EXECUTE_ON_NEXT_BOOT = 2
class BasePlugin(object):
def get_name(self):
return self.__class__.__name__
def get_os_requirements(self):
return (None, None)
def execute(self, service):
pass

View File

@ -168,3 +168,6 @@ class ExtendVolumesPlugin(base.BasePlugin):
self._extend_volumes(pack, volumes_to_extend)
return (base.PLUGIN_EXECUTE_ON_NEXT_BOOT, False)
def get_os_requirements(self):
return ('win32', (5, 2))