Ejemplo n.º 1
0
def notify(_context, message):
    """Notifies the recipient of the desired event given the model.
    Log notifications using openstack's default logging system"""

    priority = message.get('priority', CONF.default_notification_level)
    priority = priority.lower()
    logger = logging.getLogger(
        'cloudbaseinit.openstack.common.notification.%s' %
        message['event_type'])
    getattr(logger, priority)(jsonutils.dumps(message))
Ejemplo n.º 2
0
def notify(_context, message):
    """Notifies the recipient of the desired event given the model.
    Log notifications using openstack's default logging system"""

    priority = message.get('priority',
                           CONF.default_notification_level)
    priority = priority.lower()
    logger = logging.getLogger(
        'cloudbaseinit.openstack.common.notification.%s' %
        message['event_type'])
    getattr(logger, priority)(jsonutils.dumps(message))
Ejemplo n.º 3
0
def setup(product_name):
    openstack_logging.setup(product_name)

    if CONF.logging_serial_port_settings:
        log_root = openstack_logging.getLogger(product_name).logger

        serialportlog = SerialPortHandler()
        log_root.addHandler(serialportlog)

        datefmt = CONF.log_date_format
        serialportlog.setFormatter(
            openstack_logging.ContextFormatter(project=product_name,
                                               datefmt=datefmt))
Ejemplo n.º 4
0
def setup(product_name):
    openstack_logging.setup(product_name)

    if CONF.logging_serial_port_settings:
        log_root = openstack_logging.getLogger(product_name).logger

        serialportlog = SerialPortHandler()
        log_root.addHandler(serialportlog)

        datefmt = CONF.log_date_format
        serialportlog.setFormatter(
            openstack_logging.ContextFormatter(project=product_name,
                                               datefmt=datefmt))
#         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.

from cloudbaseinit import exception
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.plugins import base
from cloudbaseinit.plugins import constants
from cloudbaseinit.utils.windows import winrmconfig
from cloudbaseinit.utils.windows import x509

LOG = logging.getLogger(__name__)


class ConfigWinRMCertificateAuthPlugin(base.BasePlugin):
    def _get_credentials(self, shared_data):
        user_name = shared_data.get(constants.SHARED_DATA_USERNAME)
        if not user_name:
            raise exception.CloudbaseInitException(
                "Cannot execute plugin as the username has not been set in "
                "the plugins shared data")

        password = shared_data.get(constants.SHARED_DATA_PASSWORD)
        if not password:
            raise exception.CloudbaseInitException(
                "Cannot execute plugin as the password has not been set in the"
                " plugins shared data")
Ejemplo n.º 6
0
    cfg.ListOpt('groups',
                default=['Administrators'],
                help='List of local '
                'groups to which the user specified in \'username\' will '
                'be added'),
    cfg.BoolOpt('inject_user_password',
                default=True,
                help='Set the password '
                'provided in the configuration. If False or no password is '
                'provided, a random one will be set'),
]

CONF = cfg.CONF
CONF.register_opts(opts)

LOG = logging.getLogger(__name__)


class CreateUserPlugin(base.BasePlugin):
    def _get_password(self, service, osutils):
        meta_data = service.get_meta_data('openstack')
        meta = meta_data.get('meta')

        if CONF.inject_user_password and meta and 'admin_pass' in meta:
            LOG.warn('Using admin_pass metadata user password. Consider '
                     'changing it as soon as possible')
            password = meta['admin_pass']
        else:
            # Generate a temporary random password to be replaced
            # by SetUserPasswordPlugin (starting from Grizzly)
            password = osutils.generate_random_password(14)
Ejemplo n.º 7
0
#
#         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.

import os
import tempfile

from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.osutils import factory as osutils_factory

LOG = logging.getLogger("cloudbaseinit")


def get_plugin(parent_set):
    return ShellScriptHandler(parent_set)


class ShellScriptHandler:
    def __init__(self, parent_set):
        LOG.info("Shell-script part handler is loaded.")
        self.type = "text/x-shellscript"
        self.name = "Shell-script userdata plugin"

    def process(self, part):
        osutils = osutils_factory.OSUtilsFactory().get_os_utils()
Ejemplo n.º 8
0
from cloudbaseinit.openstack.common import log as openstack_logging

opts = [
    cfg.StrOpt('logging_serial_port_settings',
               default=None,
               help='Serial port logging settings. Format: '
               '"port,baudrate,parity,bytesize", e.g.: "COM1,115200,N,8". '
               'Set to None (default) to disable.'),
]

CONF = cfg.CONF
CONF.register_opts(opts)
CONF.import_opt('log_date_format', 'cloudbaseinit.openstack.common.log')

LOG = openstack_logging.getLogger(__name__)


class SerialPortHandler(logging.StreamHandler):
    class _UnicodeToBytesStream(object):
        def __init__(self, stream):
            self._stream = stream

        def write(self, data):
            if self._stream and not self._stream.isOpen():
                self._stream.open()

            if isinstance(data, six.text_type):
                self._stream.write(data.encode("utf-8"))
            else:
                self._stream.write(data)
Ejemplo n.º 9
0
#
#    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.

from cloudbaseinit.openstack.common import log as logging

LOG = logging.getLogger("cloudbaseinit")


def get_plugin(parent_set):
    return CloudConfigHandler(parent_set)


class CloudConfigHandler:

    def __init__(self, parent_set):
        LOG.info("Cloud-config part handler is loaded.")
        self.type = "text/cloud-config"
        self.name = "Cloud-config userdata plugin"

    def process(self, part):
        pass
Ejemplo n.º 10
0
from oslo.config import cfg

from cloudbaseinit.openstack.common import log as openstack_logging

opts = [
    cfg.StrOpt('logging_serial_port_settings', default=None,
               help='Serial port logging settings. Format: '
               '"port,baudrate,parity,bytesize", e.g.: "COM1,115200,N,8". '
               'Set to None (default) to disable.'),
]

CONF = cfg.CONF
CONF.register_opts(opts)
CONF.import_opt('log_date_format', 'cloudbaseinit.openstack.common.log')

LOG = openstack_logging.getLogger(__name__)


class SerialPortHandler(logging.StreamHandler):
    class _UnicodeToBytesStream(object):
        def __init__(self, stream):
            self._stream = stream

        def write(self, data):
            if isinstance(data, six.text_type):
                self._stream.write(data.encode("utf-8"))
            else:
                self._stream.write(data)

    def __init__(self):
        self._port = None
Ejemplo n.º 11
0
 def __init__(self, logger_name):
     self._logger_name = logger_name
     self._snatch_handler = SnatchHandler()
     self._logger = logging.getLogger(self._logger_name)
     self._previous_level = self._logger.logger.getEffectiveLevel()
Ejemplo n.º 12
0
 def __init__(self, logger_name):
     self._logger_name = logger_name
     self._snatch_handler = SnatchHandler()
     self._logger = logging.getLogger(self._logger_name)
     self._previous_level = self._logger.logger.getEffectiveLevel()