def configure_host(self): LOG.info('Cloudbase-Init version: %s', version.get_version()) osutils = osutils_factory.get_os_utils() osutils.wait_for_boot_completion() service = metadata_factory.get_metadata_service() LOG.info('Metadata service loaded: \'%s\'' % service.get_name()) instance_id = service.get_instance_id() LOG.debug('Instance id: %s', instance_id) plugins = plugins_factory.load_plugins() plugins_shared_data = {} reboot_required = False try: for plugin in plugins: if self._check_plugin_os_requirements(osutils, plugin): if self._exec_plugin(osutils, service, plugin, instance_id, plugins_shared_data): reboot_required = True if CONF.allow_reboot: break finally: service.cleanup() if reboot_required and CONF.allow_reboot: try: osutils.reboot() except Exception as ex: LOG.error('reboot failed with error \'%s\'' % ex) elif CONF.stop_service_on_exit: osutils.terminate()
def configure_host(self): service = None osutils = osutils_factory.get_os_utils() if CONF.reset_service_password and sys.platform == 'win32': self._reset_service_password_and_respawn(osutils) LOG.info('Cloudbase-Init version: %s', version.get_version()) osutils.wait_for_boot_completion() reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_NETWORKING) self._check_latest_version() if not (reboot_required and CONF.allow_reboot): reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_METADATA_DISCOVERY) if not (reboot_required and CONF.allow_reboot): try: service = metadata_factory.get_metadata_service() except exception.MetadaNotFoundException: LOG.error("No metadata service found") if service: LOG.info('Metadata service loaded: \'%s\'' % service.get_name()) instance_id = service.get_instance_id() LOG.debug('Instance id: %s', instance_id) try: reboot_required = self._handle_plugins_stage( osutils, service, instance_id, plugins_base.PLUGIN_STAGE_MAIN) finally: service.cleanup() if reboot_required and CONF.allow_reboot: try: LOG.info("Rebooting") osutils.reboot() except Exception as ex: LOG.error('reboot failed with error \'%s\'' % ex) else: LOG.info("Plugins execution done") if CONF.stop_service_on_exit: LOG.info("Stopping Cloudbase-Init service") osutils.terminate()
def configure_host(self): LOG.info('Cloudbase-Init version: %s', version.get_version()) osutils = osutils_factory.get_os_utils() if CONF.reset_service_password: # Avoid pass the hash attacks from cloned instances osutils.reset_service_password() osutils.wait_for_boot_completion() reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_NETWORKING) self._check_latest_version() if not (reboot_required and CONF.allow_reboot): reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_METADATA_DISCOVERY) if not (reboot_required and CONF.allow_reboot): service = metadata_factory.get_metadata_service() LOG.info('Metadata service loaded: \'%s\'' % service.get_name()) instance_id = service.get_instance_id() LOG.debug('Instance id: %s', instance_id) try: reboot_required = self._handle_plugins_stage( osutils, service, instance_id, plugins_base.PLUGIN_STAGE_MAIN) finally: service.cleanup() if reboot_required and CONF.allow_reboot: try: LOG.info("Rebooting") osutils.reboot() except Exception as ex: LOG.error('reboot failed with error \'%s\'' % ex) else: LOG.info("Plugins execution done") if CONF.stop_service_on_exit: LOG.info("Stopping Cloudbase-Init service") osutils.terminate()
def configure_host(self): service = None osutils = osutils_factory.get_os_utils() if CONF.reset_service_password and sys.platform == 'win32': self._reset_service_password_and_respawn(osutils) LOG.info('Cloudbase-Init version: %s', version.get_version()) osutils.wait_for_boot_completion() stage_success, reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_NETWORKING) self._check_latest_version() if not (reboot_required and CONF.allow_reboot): stage_success, reboot_required = self._handle_plugins_stage( osutils, None, None, plugins_base.PLUGIN_STAGE_PRE_METADATA_DISCOVERY) if not (reboot_required and CONF.allow_reboot): try: service = metadata_factory.get_metadata_service() except exception.MetadaNotFoundException: LOG.error("No metadata service found") if service: LOG.info('Metadata service loaded: \'%s\'' % service.get_name()) if CONF.metadata_report_provisioning_started: LOG.info("Reporting provisioning started") service.provisioning_started() instance_id = service.get_instance_id() LOG.debug('Instance id: %s', instance_id) try: stage_success, reboot_required = self._handle_plugins_stage( osutils, service, instance_id, plugins_base.PLUGIN_STAGE_MAIN) finally: service.cleanup() if (CONF.metadata_report_provisioning_completed and not stage_success): try: LOG.info("Reporting provisioning failed") service.provisioning_failed() except Exception as ex: LOG.exception(ex) if reboot_required and CONF.allow_reboot: try: LOG.info("Rebooting") osutils.reboot() except Exception as ex: LOG.error('reboot failed with error \'%s\'' % ex) else: LOG.info("Plugins execution done") if (service and CONF.metadata_report_provisioning_completed and stage_success): try: LOG.info("Reporting provisioning completed") service.provisioning_completed() except Exception as ex: LOG.exception(ex) if CONF.stop_service_on_exit: LOG.info("Stopping Cloudbase-Init service") osutils.terminate()
def test_get_version(self, mock_version_info): package_version = version.get_version() mock_version_info.assert_called_once_with('cloudbase-init') release_string = mock_version_info.return_value.release_string self.assertEqual(release_string.return_value, package_version)