def printError(msg, exitCode=1, exit=True): # TODO: Revisit this design; having exit in API is not good. err = ' [ERROR] %s' % msg if exit: raise SystemExit(err) else: LogUtil.error(msg)
def __init__(self, configHolder): self.creator = None super(StratusLabClientCloud, self).__init__(configHolder) self.slConfigHolder = StratuslabConfigHolder(configHolder.options, configHolder.config) self._set_listener( CreatorBaseListener(verbose=(self.verboseLevel > 1))) self._set_capabilities(contextualization=True, direct_ip_assignment=True, orchestrator_can_kill_itself_or_its_vapp=True) if self.verboseLevel > 2: LogUtil.set_logger_level(level=logging.DEBUG) # Temporary workaround: Try to increase to the maximum the limit of the number of open file descriptors. # This is a workaround to a bug where some connections to the StratusLab frontend stays in CLOSE_WAIT. # The standard limit is hit when the Run contains a huge amount of VMs (> 1000). try: import resource l = resource.getrlimit(resource.RLIMIT_NOFILE) resource.setrlimit(resource.RLIMIT_NOFILE, (l[1], l[1])) except: pass
def initialize_logger(log_direction, verbosity): level = (0 == verbosity) and logging.INFO or logging.DEBUG if 'console' == log_direction: return LogUtil.get_console_logger(level=level) elif 'syslog' == log_direction: return LogUtil.get_syslog_logger(level=level) else: raise ConfigurationException('Wrong value for log_direction: %s' % log_direction)
import sys from stratuslab.commandbase.AuthnCommand import AuthnCommand sys.path.append('/var/lib/stratuslab/python') from stratuslab.ConfigHolder import ConfigHolder from stratuslab.marketplace.Deprecator import Deprecator from stratuslab.Exceptions import InputException # initialize console logging import stratuslab.api.LogUtil as LogUtil LogUtil.get_console_logger() class MainProgram(AuthnCommand): """A command-line program to deprecate a StratusLab metadata entry.""" def __init__(self): self.imageid = None super(MainProgram, self).__init__() def parse(self): Deprecator.buildDeprecatorParser(self.parser) self.options, self.args = self.parser.parse_args() def checkOptions(self):
from .stratuslabPatch import patch_stratuslab patch_stratuslab() from stratuslab.ConfigHolder import ConfigHolder as StratuslabConfigHolder from stratuslab.marketplace.ManifestDownloader import ManifestDownloader from stratuslab.Creator import Creator from stratuslab.Creator import CreatorBaseListener from stratuslab.vm_manager.Runner import Runner from stratuslab.volume_manager.volume_manager_factory import VolumeManagerFactory from stratuslab.Exceptions import OneException from stratuslab.api import LogUtil from stratuslab.Monitor import Monitor from stratuslab.CloudInfo import CloudInfo LogUtil.get_console_logger() import slipstream.exceptions.Exceptions as Exceptions import slipstream.util as util from slipstream.cloudconnectors.BaseCloudConnector import BaseCloudConnector from slipstream.utils.ssh import generate_ssh_keypair from slipstream.util import override from .vmrootdisk import (populate_vms_with_disk_sizes, get_root_disk_size_from_disk_source, UnknownRootDiskSizeSourceError) def getConnector(configHolder): return getConnectorClass()(configHolder)
cfg_filename = 'monitoring.cfg' def _configure(): fsroot = os.path.splitdrive(sys.executable)[0] or '/' cfg_paths = [os.path.join(os.getcwd(), cfg_filename), os.path.join(os.path.expanduser('~'), '.stratuslab', cfg_filename), os.path.join(fsroot, 'etc', 'stratuslab', cfg_filename)] config = ConfigParser.ConfigParser() config.add_section('vm_usage') config.set('vm_usage', 'bucket', 'default') config.set('vm_usage', 'password', '') used_cfg_files = config.read(cfg_paths) return (config, used_cfg_files) logger = LogUtil.get_syslog_logger(__name__) (config, used_cfg_files) = _configure() logger.debug('publisher read configuration from %s' % str(used_cfg_files)) host = config.get('vm_usage', 'host') if not host: logger.debug('logging host not defined; skipping VM usage logging') sys.exit(0) logger.debug('starting VM usage history publishing') try: aCP = ConsolidationPublish(host=host) logger.debug('publishing VMs usage history to %s' % host) except Exception as e:
def printDetail(msg, verboseLevel=1, verboseThreshold=1): # TODO: Review this to see if more levels are needed. if verboseThreshold == 0: LogUtil.info(msg) else: LogUtil.debug(msg)
def printWarning(msg): LogUtil.warning(' [WARNING] %s' % msg)
def printDebug(msg): LogUtil.debug(msg)
def printInfo(msg): LogUtil.info(msg)
def printStep(msg): LogUtil.info(' :: %s' % msg)
def printAction(msg): LogUtil.info(_format_action(msg))