def deprecated(self, msg, *args, **kwargs): """Call this method when a deprecated feature is used. If the system is configured for fatal deprecations then the message is logged at the 'critical' level and :class:`DeprecatedConfig` will be raised. Otherwise, the message will be logged (once) at the 'warn' level. :param kwargs: :param args: :param msg: :raises: :class:`DeprecatedConfig` if the system is configured for fatal deprecations. """ stdmsg = _("Deprecated: %s") % msg if CONF.fatal_deprecations: self.critical(stdmsg, *args, **kwargs) raise DeprecatedConfig(msg=stdmsg) # Using a list because a tuple with dict can't be stored in a set. sent_args = self._deprecated_messages_sent.setdefault(msg, list()) if args in sent_args: # Already logged this message, so don't log it again. return sent_args.append(args) self.warn(stdmsg, *args, **kwargs)
class LogConfigError(Exception): message = _('Error loading logging config %(log_config)s: %(err_msg)s') def __init__(self, log_config, err_msg): self.log_config = log_config self.err_msg = err_msg def __str__(self): return self.message % dict(log_config=self.log_config, err_msg=self.err_msg)
def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_puppet.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = {'success': True, 'response': resp_launch} LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook deployment exception %s" % e)) raise CookbookDeploymentException(cookbook=cookbook) return msg
def run_deploy(self, user, blueprint, spec, image): """ Run blueprint deployment :param blueprint: blueprint to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_murano.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = {'success': True, 'response': resp_launch} LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint deployment exception %s" % e)) raise CookbookDeploymentException(blueprint=blueprint) return msg
def run_test(self, user, blueprint, image): """ Test blueprint syntax :param blueprint: blueprint to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint) resp_test = self.dc.execute_command(cmd_syntax) msg = {'success': True, 'response': resp_test} for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint syntax exception %s" % e)) raise CookbookSyntaxException(blueprint=blueprint) return msg
def run_install(self, user, blueprint, image): """Run download and install command :param blueprint: blueprint to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_murano.cmd_install.format(blueprint) resp_install = self.dc.execute_command(cmd_install) msg = {'success': True, 'response': resp_install} for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Murano install exception: %s" % e)) raise CookbookInstallException(blueprint=blueprint) return msg
class OpenstackException(Exception): """Base Exception class. To correctly use this class, inherit from it and define a 'msg_fmt' property. That message will get printf'd with the keyword arguments provided to the constructor. """ msg_fmt = _("An unknown exception occurred") def __init__(self, **kwargs): try: self._error_string = self.msg_fmt % kwargs except Exception: if _FATAL_EXCEPTION_FORMAT_ERRORS: raise else: self._error_string = self.msg_fmt def __str__(self): return self._error_string
def run_install(self, user, blueprint, image): """Run download and install command :param blueprint: blueprint to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_murano.cmd_install.format(blueprint) resp_install = self.dc.execute_command(cmd_install) msg = { 'success': True, 'response': resp_install } for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Murano install exception: %s" % e)) raise CookbookInstallException(blueprint=blueprint) return msg
def run_test(self, user, blueprint, image): """ Test blueprint syntax :param blueprint: blueprint to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint) resp_test = self.dc.execute_command(cmd_syntax) msg = { 'success': True, 'response': resp_test } for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint syntax exception %s" % e)) raise CookbookSyntaxException(blueprint=blueprint) return msg
def run_deploy(self, user, blueprint, spec, image): """ Run blueprint deployment :param blueprint: blueprint to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_murano.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = { 'success': True, 'response': resp_launch } LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint deployment exception %s" % e)) raise CookbookDeploymentException(blueprint=blueprint) return msg
def _find_facility_from_conf(): facility_names = logging.handlers.SysLogHandler.facility_names facility = getattr(logging.handlers.SysLogHandler, CONF.syslog_log_facility, None) if facility is None and CONF.syslog_log_facility in facility_names: facility = facility_names.get(CONF.syslog_log_facility) if facility is None: valid_facilities = facility_names.keys() consts = ['LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON', 'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS', 'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP', 'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3', 'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7'] valid_facilities.extend(consts) raise TypeError(_('syslog facility must be one of: %s') % ', '.join("'%s'" % fac for fac in valid_facilities)) return facility
def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_puppet.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = { 'success': True, 'response': resp_launch } LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook deployment exception %s" % e)) raise CookbookDeploymentException(cookbook=cookbook) return msg
class DeprecatedConfig(Exception): message = _("Fatal call to deprecated config: %(msg)s") def __init__(self, msg): super(Exception, self).__init__(self.message % dict(msg=msg))
class AuthorizationFailure(OpenstackException): msg_fmt = _("Authorization failed.")
class InvalidContentType(OpenstackException): msg_fmt = _("Invalid content type %(content_type)s")
class DockerContainerException(OpenstackException): msg_fmt = _("Error deploying the provided image: %(image)s")
class CookbookSyntaxException(OpenstackException): msg_fmt = _( "The provided cookbook syntax is incorrect for cookbook: %(cookbook)s")
class CookbookDeploymentException(OpenstackException): msg_fmt = _("Error deploying the provided cookbook: %(cookbook)s")
class SerialConnectException(OpenstackException): msg_fmt = _("The Serial connection to %(host)s could not be stablished.")
class CookbookInstallException(OpenstackException): msg_fmt = _("Error installing cookbook %(cookbook)s")
class AmbiguousNameException(OpenstackException): msg_fmt = _("Image name %(name)s is ambiguous")
class ImageNotFound(OpenstackException): msg_fmt = _("The Image %(name)s doesn't exist for the given user")
class EntityNotFound(OpenstackException): msg_fmt = _("The %(entity)s (%(name)s) could not be found.")
class NotAuthenticated(OpenstackException): msg_fmt = _("Authentication failed.")
class MalformedRequestBody(OpenstackException): msg_fmt = _("Malformed message body: %(reason)s")