Adds plugins shared_data support
This commit is contained in:
parent
44af45a1f8
commit
024758ff10
@ -48,7 +48,7 @@ class InitManager(object):
|
|||||||
osutils.set_config_value(plugin_name, status,
|
osutils.set_config_value(plugin_name, status,
|
||||||
self._PLUGINS_CONFIG_SECTION)
|
self._PLUGINS_CONFIG_SECTION)
|
||||||
|
|
||||||
def _exec_plugin(self, osutils, service, plugin):
|
def _exec_plugin(self, osutils, service, plugin, shared_data):
|
||||||
plugin_name = plugin.get_name()
|
plugin_name = plugin.get_name()
|
||||||
|
|
||||||
status = self._get_plugin_status(osutils, plugin_name)
|
status = self._get_plugin_status(osutils, plugin_name)
|
||||||
@ -59,7 +59,8 @@ class InitManager(object):
|
|||||||
LOG.info('Executing plugin \'%(plugin_name)s\'' %
|
LOG.info('Executing plugin \'%(plugin_name)s\'' %
|
||||||
locals())
|
locals())
|
||||||
try:
|
try:
|
||||||
(status, reboot_required) = plugin.execute(service)
|
(status, reboot_required) = plugin.execute(service,
|
||||||
|
shared_data)
|
||||||
self._set_plugin_status(osutils, plugin_name, status)
|
self._set_plugin_status(osutils, plugin_name, status)
|
||||||
return reboot_required
|
return reboot_required
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
@ -98,11 +99,14 @@ class InitManager(object):
|
|||||||
|
|
||||||
plugins = plugins_factory.PluginFactory().load_plugins()
|
plugins = plugins_factory.PluginFactory().load_plugins()
|
||||||
|
|
||||||
|
plugins_shared_data = {}
|
||||||
|
|
||||||
reboot_required = False
|
reboot_required = False
|
||||||
try:
|
try:
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
if self._check_plugin_os_requirements(osutils, plugin):
|
if self._check_plugin_os_requirements(osutils, plugin):
|
||||||
if self._exec_plugin(osutils, service, plugin):
|
if self._exec_plugin(osutils, service, plugin,
|
||||||
|
plugins_shared_data):
|
||||||
reboot_required = True
|
reboot_required = True
|
||||||
if CONF.allow_reboot:
|
if CONF.allow_reboot:
|
||||||
break
|
break
|
||||||
|
@ -25,5 +25,5 @@ class BasePlugin(object):
|
|||||||
def get_os_requirements(self):
|
def get_os_requirements(self):
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
pass
|
pass
|
||||||
|
18
cloudbaseinit/plugins/constants.py
Normal file
18
cloudbaseinit/plugins/constants.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
# Copyright 2013 Cloudbase Solutions Srl
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
SHARED_DATA_USERNAME = "admin_user"
|
||||||
|
SHARED_DATA_PASSWORD = "admin_password"
|
@ -21,16 +21,19 @@ opts = [
|
|||||||
cfg.ListOpt(
|
cfg.ListOpt(
|
||||||
'plugins',
|
'plugins',
|
||||||
default=[
|
default=[
|
||||||
'cloudbaseinit.plugins.windows.sethostname.SetHostNamePlugin',
|
'cloudbaseinit.plugins.windows.sethostname.SetHostNamePlugin',
|
||||||
'cloudbaseinit.plugins.windows.createuser.CreateUserPlugin',
|
'cloudbaseinit.plugins.windows.createuser.CreateUserPlugin',
|
||||||
'cloudbaseinit.plugins.windows.networkconfig.NetworkConfigPlugin',
|
'cloudbaseinit.plugins.windows.networkconfig.NetworkConfigPlugin',
|
||||||
'cloudbaseinit.plugins.windows.sshpublickeys.'
|
'cloudbaseinit.plugins.windows.sshpublickeys.'
|
||||||
'SetUserSSHPublicKeysPlugin',
|
'SetUserSSHPublicKeysPlugin',
|
||||||
'cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin',
|
'cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin',
|
||||||
'cloudbaseinit.plugins.windows.userdata.UserDataPlugin',
|
'cloudbaseinit.plugins.windows.userdata.UserDataPlugin',
|
||||||
'cloudbaseinit.plugins.windows.setuserpassword.SetUserPasswordPlugin',
|
'cloudbaseinit.plugins.windows.setuserpassword.'
|
||||||
'cloudbaseinit.plugins.windows.winrmlistener.'
|
'SetUserPasswordPlugin',
|
||||||
'ConfigWinRMListenerPlugin',
|
'cloudbaseinit.plugins.windows.winrmlistener.'
|
||||||
|
'ConfigWinRMListenerPlugin',
|
||||||
|
'cloudbaseinit.plugins.windows.winrmcertificateauth.'
|
||||||
|
'ConfigWinRMCertificateAuthPlugin',
|
||||||
],
|
],
|
||||||
help='List of enabled plugin classes, '
|
help='List of enabled plugin classes, '
|
||||||
'to executed in the provided order'),
|
'to executed in the provided order'),
|
||||||
|
@ -18,6 +18,7 @@ from cloudbaseinit.openstack.common import cfg
|
|||||||
from cloudbaseinit.openstack.common import log as logging
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.osutils import factory as osutils_factory
|
from cloudbaseinit.osutils import factory as osutils_factory
|
||||||
from cloudbaseinit.plugins import base
|
from cloudbaseinit.plugins import base
|
||||||
|
from cloudbaseinit.plugins import constants
|
||||||
|
|
||||||
opts = [
|
opts = [
|
||||||
cfg.StrOpt('username', default='Admin', help='User to be added to the '
|
cfg.StrOpt('username', default='Admin', help='User to be added to the '
|
||||||
@ -39,8 +40,9 @@ class CreateUserPlugin(base.BasePlugin):
|
|||||||
# by SetUserPasswordPlugin (starting from Grizzly)
|
# by SetUserPasswordPlugin (starting from Grizzly)
|
||||||
return osutils.generate_random_password(14)
|
return osutils.generate_random_password(14)
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
user_name = CONF.username
|
user_name = CONF.username
|
||||||
|
shared_data[constants.SHARED_DATA_USERNAME] = user_name
|
||||||
|
|
||||||
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
||||||
password = self._get_password(osutils)
|
password = self._get_password(osutils)
|
||||||
@ -58,6 +60,9 @@ class CreateUserPlugin(base.BasePlugin):
|
|||||||
True)
|
True)
|
||||||
osutils.close_user_logon_session(token)
|
osutils.close_user_logon_session(token)
|
||||||
|
|
||||||
|
# TODO(alexpilotti): encrypt with DPAPI
|
||||||
|
shared_data[constants.SHARED_DATA_PASSWORD] = password
|
||||||
|
|
||||||
for group_name in CONF.groups:
|
for group_name in CONF.groups:
|
||||||
try:
|
try:
|
||||||
osutils.add_user_to_local_group(user_name, group_name)
|
osutils.add_user_to_local_group(user_name, group_name)
|
||||||
|
@ -156,7 +156,7 @@ class ExtendVolumesPlugin(base.BasePlugin):
|
|||||||
if CONF.volumes_to_extend is not None:
|
if CONF.volumes_to_extend is not None:
|
||||||
return map(int, CONF.volumes_to_extend)
|
return map(int, CONF.volumes_to_extend)
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
svc = vds.load_vds_service()
|
svc = vds.load_vds_service()
|
||||||
providers = self._query_providers(svc)
|
providers = self._query_providers(svc)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ CONF.register_opts(opts)
|
|||||||
|
|
||||||
|
|
||||||
class NetworkConfigPlugin(base.BasePlugin):
|
class NetworkConfigPlugin(base.BasePlugin):
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
meta_data = service.get_meta_data('openstack')
|
meta_data = service.get_meta_data('openstack')
|
||||||
if 'network_config' not in meta_data:
|
if 'network_config' not in meta_data:
|
||||||
return (base.PLUGIN_EXECUTION_DONE, False)
|
return (base.PLUGIN_EXECUTION_DONE, False)
|
||||||
|
@ -22,7 +22,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class SetHostNamePlugin(base.BasePlugin):
|
class SetHostNamePlugin(base.BasePlugin):
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
meta_data = service.get_meta_data('openstack')
|
meta_data = service.get_meta_data('openstack')
|
||||||
if 'hostname' not in meta_data:
|
if 'hostname' not in meta_data:
|
||||||
LOG.debug('Hostname not found in metadata')
|
LOG.debug('Hostname not found in metadata')
|
||||||
|
@ -21,6 +21,7 @@ from cloudbaseinit.openstack.common import cfg
|
|||||||
from cloudbaseinit.openstack.common import log as logging
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.osutils import factory as osutils_factory
|
from cloudbaseinit.osutils import factory as osutils_factory
|
||||||
from cloudbaseinit.plugins import base
|
from cloudbaseinit.plugins import base
|
||||||
|
from cloudbaseinit.plugins import constants
|
||||||
from cloudbaseinit.utils import crypt
|
from cloudbaseinit.utils import crypt
|
||||||
|
|
||||||
opts = [
|
opts = [
|
||||||
@ -73,6 +74,9 @@ class SetUserPasswordPlugin(base.BasePlugin):
|
|||||||
LOG.warn('Using admin_pass metadata user password. Consider '
|
LOG.warn('Using admin_pass metadata user password. Consider '
|
||||||
'changing it as soon as possible')
|
'changing it as soon as possible')
|
||||||
else:
|
else:
|
||||||
|
# TODO(alexpilotti): setting a random password can be skipped
|
||||||
|
# if it's already present in the shared_data, as it has already
|
||||||
|
# been set by the CreateUserPlugin
|
||||||
LOG.debug('Generating a random user password')
|
LOG.debug('Generating a random user password')
|
||||||
# Generate a random password
|
# Generate a random password
|
||||||
# Limit to 14 chars for compatibility with NT
|
# Limit to 14 chars for compatibility with NT
|
||||||
@ -104,8 +108,11 @@ class SetUserPasswordPlugin(base.BasePlugin):
|
|||||||
osutils.set_user_password(user_name, password)
|
osutils.set_user_password(user_name, password)
|
||||||
return password
|
return password
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
user_name = CONF.username
|
# TODO(alexpilotti): The username selection logic must be set in the
|
||||||
|
# CreateUserPlugin instead if using CONF.username
|
||||||
|
user_name = shared_data.get(constants.SHARED_DATA_USERNAME,
|
||||||
|
CONF.username)
|
||||||
|
|
||||||
if (service.can_post_password and
|
if (service.can_post_password and
|
||||||
service.is_password_set(self._post_password_md_ver)):
|
service.is_password_set(self._post_password_md_ver)):
|
||||||
@ -114,6 +121,9 @@ class SetUserPasswordPlugin(base.BasePlugin):
|
|||||||
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
||||||
if osutils.user_exists(user_name):
|
if osutils.user_exists(user_name):
|
||||||
password = self._set_password(service, osutils, user_name)
|
password = self._set_password(service, osutils, user_name)
|
||||||
|
# TODO(alexpilotti): encrypt with DPAPI
|
||||||
|
shared_data[constants.SHARED_DATA_PASSWORD] = password
|
||||||
|
|
||||||
if not service.can_post_password:
|
if not service.can_post_password:
|
||||||
LOG.info('Cannot set the password in the metadata as it '
|
LOG.info('Cannot set the password in the metadata as it '
|
||||||
'is not supported by this service')
|
'is not supported by this service')
|
||||||
|
@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class SetUserSSHPublicKeysPlugin(base.BasePlugin):
|
class SetUserSSHPublicKeysPlugin(base.BasePlugin):
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
meta_data = service.get_meta_data('openstack')
|
meta_data = service.get_meta_data('openstack')
|
||||||
if not 'public_keys' in meta_data:
|
if not 'public_keys' in meta_data:
|
||||||
return (base.PLUGIN_EXECUTION_DONE, False)
|
return (base.PLUGIN_EXECUTION_DONE, False)
|
||||||
|
@ -50,7 +50,7 @@ class UserDataPlugin(base.BasePlugin):
|
|||||||
os.path.dirname(os.path.realpath(__file__))),
|
os.path.dirname(os.path.realpath(__file__))),
|
||||||
"windows/userdata-plugins")
|
"windows/userdata-plugins")
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
try:
|
try:
|
||||||
user_data = service.get_user_data('openstack')
|
user_data = service.get_user_data('openstack')
|
||||||
except metadata_services_base.NotExistingMetadataException:
|
except metadata_services_base.NotExistingMetadataException:
|
||||||
|
@ -36,7 +36,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ConfigWinRMListenerPlugin(base.BasePlugin):
|
class ConfigWinRMListenerPlugin(base.BasePlugin):
|
||||||
_cert_subject = "CN=Cloudbase-Init"
|
_cert_subject = "CN=Cloudbase-Init WinRM"
|
||||||
_winrm_service_name = "WinRM"
|
_winrm_service_name = "WinRM"
|
||||||
|
|
||||||
def _check_winrm_service(self, osutils):
|
def _check_winrm_service(self, osutils):
|
||||||
@ -59,7 +59,7 @@ class ConfigWinRMListenerPlugin(base.BasePlugin):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, service):
|
def execute(self, service, shared_data):
|
||||||
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
osutils = osutils_factory.OSUtilsFactory().get_os_utils()
|
||||||
|
|
||||||
if not self._check_winrm_service(osutils):
|
if not self._check_winrm_service(osutils):
|
||||||
|
Loading…
Reference in New Issue
Block a user