Exemplo n.º 1
0
    def guess_version(self):
        """
        :returns: (float) version of the config file or 0.9 if unrecognized
        """
        from kamaki.cli import logger
        # Ignore logs from "checker" logger
        logger.deactivate(__name__)
        checker = Config(self.path, with_defaults=False)
        logger.activate(__name__)

        sections = checker.sections()
        #  log.debug('Config file heuristic 1: old global section ?')
        if 'global' in sections:
            if checker.get('global', 'url') or checker.get('global', 'token'):
                log.debug('config file has an old global section')
                return 0.8
        #  log.debug('Config file heuristic 2: Any cloud sections ?')
        if CLOUD_PREFIX in sections:
            for r in self.keys(CLOUD_PREFIX):
                log.debug('found cloud "%s"' % r)
            ipv = self.get('global', 'ip_cli')
            if ipv in ('cyclades', ):
                    return 0.11
            netv = self.get('global', 'network_cli')
            if netv in ('cyclades', ):
                return 0.10
            return 0.12
        log.debug('All heuristics failed, cannot decide')
        return 0.12
Exemplo n.º 2
0
    def guess_version(self):
        """
        :returns: (float) version of the config file or 0.9 if unrecognized
        """
        from kamaki.cli import logger
        # Ignore logs from "checker" logger
        logger.deactivate(__name__)
        checker = Config(self.path, with_defaults=False)
        logger.activate(__name__)

        sections = checker.sections()
        #  log.debug('Config file heuristic 1: old global section ?')
        if 'global' in sections:
            if checker.get('global', 'url') or checker.get('global', 'token'):
                log.debug('config file has an old global section')
                return 0.8
        #  log.debug('Config file heuristic 2: Any cloud sections ?')
        if CLOUD_PREFIX in sections:
            for r in self.keys(CLOUD_PREFIX):
                log.debug('found cloud "%s"' % r)
            ipv = self.get('global', 'ip_cli')
            if ipv in ('cyclades', ):
                return 0.11
            netv = self.get('global', 'network_cli')
            if netv in ('cyclades', ):
                return 0.10
            return 0.12
        log.debug('All heuristics failed, cannot decide')
        return 0.12
Exemplo n.º 3
0
Arquivo: test.py Projeto: grnet/kamaki
 def test_activate(self, GL):
     from kamaki.cli.logger import activate
     activate('another logger')
     GL.assert_called_once_with('another logger')
     self.assertEqual(
         self.PseudoLogger._setLevel_calls[-1], (self.PseudoLogger.level, ))
Exemplo n.º 4
0
 def test_activate(self, GL):
     from kamaki.cli.logger import activate
     activate('another logger')
     GL.assert_called_once_with('another logger')
     self.assertEqual(self.PseudoLogger._setLevel_calls[-1],
                      (self.PseudoLogger.level, ))