Beispiel #1
0
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)
Beispiel #2
0
    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)
Beispiel #3
0
def _get_provider_class_from_dict(**kwargs):
    """ Get a a provider class from a dictionary
    """
    for name in ['class', 'cfg_class', '_class']:
        if name in kwargs:
            return kwargs[name]

    for alternative in ['_container', '_parent']:
        if alternative in kwargs:
            alternative_attr = kwargs[alternative]
            if alternative_attr:
                for name in ['class', 'cfg_class', '_class']:
                    if hasattr(alternative_attr, name):
                        return getattr(alternative_attr, name)

    return config.get_key(CFG_DEFAULT_PROVIDER)
Beispiel #4
0
    def __init__(self, **kwargs):
        """ Initialize a machines definition
        """
        super(MachineNode, self).__init__(**kwargs)

        # set the default class for nodes if it has not been set
        if not self.cfg_class:
            self.cfg_class = config.get_key(CFG_DEFAULT_PROVIDER)
            logger.debug('using default node class: %s', self.cfg_class)

        TopologyAttribute.setall(self, kwargs, self.__known_attributes)

        self.guest = None
        self.communicator = None

        # validate the attributes
        if not self.cfg_name and not self.is_global:
            raise MalformedTopologyException('machines must have a name')
Beispiel #5
0
 def get_storage_root():
     """ Get the storage root for boxes
     """
     d = config.get_key(CFG_BOXES_PATH)
     return os.path.expandvars(d) if d else d