def setup_file(filename=None, level=None): """ Add a logging file to the logging configuration If no filename is given, we will check the config file for a valid logfile configuration. If not found, no logging to file is configured. """ from candelabra.config import config if not filename: if config.has_section(DEFAULT_CFG_SECTION_LOGGING_FILE): filename = config.get_key(CFG_LOG_FILE) else: filename = None if filename: if not level: if config.has_section(DEFAULT_CFG_SECTION_LOGGING_FILE): level = config.get_key(CFG_LOG_FILE_LEVEL) max_log_size = long(config.get_key(CFG_LOG_FILE_MAX_LEN)) log_format_file = LOG_FILE_FORMAT_DEBUG if level == 'DEBUG' else LOG_FILE_FORMAT # add the file try: hdlr = logging.handlers.RotatingFileHandler(str(filename), maxBytes=max_log_size, backupCount=1) except IOError, e: logging.critical('cannot create log file: %s', str(e)) sys.exit(1) fmt = logging.Formatter(log_format_file, None) hdlr.setFormatter(fmt) hdlr.setLevel(level) logging.root.addHandler(hdlr)
def __init__(self, **kwargs): """ Initialize a VirtualBox machine """ super(VirtualboxMachineNode, self).__init__(**kwargs) TopologyAttribute.setall(self, kwargs, self.__known_attributes) # get any VirtualBox default parameters from the config file if config.has_section(DEFAULT_CFG_SECTION_VIRTUALBOX): self._cfg = config.items(section=DEFAULT_CFG_SECTION_VIRTUALBOX) if len(self._cfg) > 0: logger.debug('VirtualBox default config:') for k, v in self._cfg: logger.debug('... %s = %s', k, v) setattr(self, 'default_' + k, v) else: self._cfg = None self._vbox = _virtualbox.VirtualBox() self._vbox_uuid = self.cfg_uuid if getattr(self, 'cfg_uuid', None) else None self._vbox_machine = None self._vbox_guest = None self._vbox_guest_os_type = None self._vbox_wait_events = {} self._created_shared_folders = [] # check and fix topology parameters if not self.cfg_gui in ['headless', 'gui']: raise MalformedTopologyException('invalid GUI type %s', self.cfg_gui) if not self.cfg_updown_timeout: self.cfg_updown_timeout = config.get_key(CFG_MACHINE_UPDOWN_TIMEOUT) if not self.cfg_userland_timeout: self.cfg_userland_timeout = config.get_key(CFG_USERLAND_TIMEOUT) if not self.cfg_commands_timeout: self.cfg_commands_timeout = config.get_key(CFG_MACHINE_COMMANDS_TIMEOUT) # create a communicator for this machine self.communicator = build_communicator_instance(_class='virtualbox', machine=self)