Пример #1
0
    def readConf(self):
        """
        Read web section of the imaging plugin configuration file
        """
        PluginConfig.readConf(self)
        if not self.disabled:
            ImagingDatabaseConfig.setup(self, self.conffile)
            if self.has_section("web"):
                for option in self.options("web"):
                    # option variable is lowercase
                    setattr(self, option, self.get("web", option))

        setattr(self, "network", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.has_option("network", "preferred_network"):
            self.preferred_network = pnp.parse(self.get("network", "preferred_network"))
        else :
            self.preferred_network = pnp.get_default()

        try:
            self.purge_interval = self.get('main', 'purge_interval')
        except (NoOptionError, NoSectionError):
            self.purge_interval = '23 0 * * 0'
Пример #2
0
    def readConf(self):
        """
        Read web section of the imaging plugin configuration file
        """
        PluginConfig.readConf(self)
        if not self.disabled:
            ImagingDatabaseConfig.setup(self, self.conffile)
            if self.has_section("web"):
                for option in self.options("web"):
                    # option variable is lowercase
                    setattr(self, option, self.get("web", option))

        setattr(self, "network", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.has_option("network", "preferred_network"):
            self.preferred_network = pnp.parse(
                self.get("network", "preferred_network"))
        else:
            self.preferred_network = pnp.get_default()
Пример #3
0
    def setup(self, config_file):
        # Load configuration file
        if not self.cp: # self.cp is set if presetup() was already called
            self.presetup(config_file)

        # [scheduler] section parsing
        self.name = self.cp.get("scheduler", "id")

        self.setoption("scheduler", "awake_time", "awake_time", 'int')
        self.setoption("scheduler", "initial_wait", "initial_wait", 'int')
        self.setoption("scheduler", "emitting_period", "emitting_period", 'float')
        self.setoption("scheduler", "proxy_buffer_period", "proxy_buffer_period", 'float')
        self.setoption("scheduler", "proxy_buffer_start_delay", "proxy_buffer_start_delay", 'int')

        # cache settings
        self.setoption("scheduler", "cache_size", "cache_size", 'int')
        self.setoption("scheduler", "cache_timeout", "cache_timeout", 'int')

        self.setoption("scheduler", "max_command_time", "max_command_time", 'int')
        self.setoption("scheduler", "max_upload_time", "max_upload_time", 'int')
        self.setoption("scheduler", "max_wol_time", "max_wol_time", 'int')
        self.setoption("scheduler", "dbencoding", "dbencoding")
        self.setoption("scheduler", "enablessl", "enablessl", 'bool')
        self.setoption("scheduler", "max_threads", "max_threads", 'int')

        self.setoption("scheduler", "imaging", "imaging", 'bool')
        self.setoption("scheduler", "max_to_overtimed", "max_to_overtimed", 'int')

        if self.cp.has_option("scheduler", "non_fatal_steps"):
            self.non_fatal_steps = self.cp.get("scheduler", "non_fatal_steps").split(' ')
            log.debug("scheduler %s: section %s, option %s set to '%s'" % (self.name, "scheduler", "non_fatal_steps", self.non_fatal_steps))
        else:
            log.debug("scheduler %s: section %s, option %s not set, using default value '%s'" % (self.name, "scheduler", "non_fatal_steps", self.non_fatal_steps))


        if self.enablessl:
            if self.cp.has_option("scheduler", "privkey"):
                self.localcert = self.cp.get("scheduler", "privkey")
            if self.cp.has_option("scheduler", "localcert"):
                self.localcert = self.cp.get("scheduler", "localcert")
            if self.cp.has_option("scheduler", "certfile"):
                self.cacert = self.cp.get("scheduler", "certfile")
            if self.cp.has_option("scheduler", "cacert"):
                self.cacert = self.cp.get("scheduler", "cacert")
            if self.cp.has_option("scheduler", "verifypeer"):
                self.verifypeer = self.cp.getboolean("scheduler", "verifypeer")
            if not os.path.isfile(self.localcert):
                raise Exception('scheduler "%s": can\'t read SSL key "%s"' % (self.name, self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception('scheduler "%s": can\'t read SSL certificate "%s"' % (self.name, self.cacert))
                return False
            if self.verifypeer: # we need twisted.internet.ssl.Certificate to activate certs
                import twisted.internet.ssl
                if not hasattr(twisted.internet.ssl, "Certificate"):
                    raise Exception('scheduler "%s": I need at least Python Twisted 2.5 to handle peer checking' % (self.name))
                    return False

        if self.cp.has_option("scheduler", "listen"): # TODO remove in a future version
            log.warning("'listen' is obsolete, please replace it in your config file by 'host'")
            self.setoption("scheduler", "listen", "host")
        else:
            self.setoption("scheduler", "host", "host")
        self.setoption("scheduler", "port", "port")
        self.port = int(self.port)
        self.setoption("scheduler", "username", "username")
        self.setoption("scheduler", "password", "password", 'pass')
        if not isTwistedEnoughForLoginPass():
            if self.username != '':
                if self.username != 'username':
                    log.warning("your version of twisted is not high enough to use login (scheduler/username)")
                self.username = ''
            if self.password != '':
                if self.password != 'password':
                    log.warning("your version of twisted is not high enough to use password (scheduler/password)")
                self.password = ''

        self.setoption("scheduler", "mode", "mode")
        self.setoption("scheduler", "resolv_order", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.cp.has_option("scheduler", "preferred_network"):
            self.preferred_network = pnp.parse(self.cp.get("scheduler", "preferred_network"))
        else :
            self.preferred_network = pnp.get_default()


        self.setoption("scheduler", "netbios_path", "netbios_path")
        self.setoption("scheduler", "scheduler_path", "scheduler_path")
        self.setoption("scheduler", "scheduler_proxy_path", "scheduler_proxy_path")

        if self.cp.has_option("scheduler", "scheduler_proxy_socket_path"):
            self.scheduler_proxy_socket_path = self.cp.get("scheduler", "scheduler_proxy_socket_path")
        if self.cp.has_option("scheduler", "scheduler_proxy_buffer_tmp"):
            self.scheduler_proxy_buffer_tmp = self.cp.get("scheduler", "scheduler_proxy_buffer_tmp")


        if self.cp.has_option("scheduler", "client_check"):
            self.client_check = {}
            for token in self.cp.get("scheduler", "client_check").split(','):
                (key, val) = token.split('=')
                self.client_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'client_check', self.client_check))
        if self.cp.has_option("scheduler", "server_check"):
            self.server_check = {}
            for token in self.cp.get("scheduler", "server_check").split(','):
                (key, val) = token.split('=')
                self.server_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'server_check', self.server_check))
        if self.cp.has_option("scheduler", "announce_check"):
            self.announce_check = {}
            for token in self.cp.get("scheduler", "announce_check").split(','):
                (key, val) = token.split('=')
                self.announce_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'server_check', self.server_check))

        # [daemon] section parsing (parsing ofr user, group, and umask is done above in presetup)
        if self.cp.has_section("daemon"):
            if self.cp.has_option('daemon', 'pid_path'):
                log.warning("'pid_path' is deprecated, please replace it in your config file by 'pidfile'")
                self.setoption('daemon', 'pid_path', 'pid_path')
            else:
                self.setoption('daemon', 'pidfile', 'pid_path')

        # [mmc_agent] section parsing
        self.mmc_agent = {}
        if self.cp.has_section("mmc_agent"):
            self.mmc_agent = {
                'host' : "127.0.0.1",
                'port' : 7080,
                'username' : 'mmc',
                'password' : 's3cr3t',
                'enablessl' : True,
                'verifypeer' : False,
                'cacert' : mmcconfdir + "/pulse2/scheduler/keys/cacert.pem",
                'localcert' : mmcconfdir + "/pulse2/scheduler/keys/privkey.pem"}
            if self.cp.has_option('mmc_agent', 'host'):
                self.mmc_agent['host'] = self.cp.get('mmc_agent', 'host')
            if self.cp.has_option('mmc_agent', 'port'):
                self.mmc_agent['port'] = self.cp.getint('mmc_agent', 'port')
            if self.cp.has_option('mmc_agent', 'enablessl'):
                self.mmc_agent['enablessl'] = self.cp.getboolean('mmc_agent', 'enablessl')
            if self.cp.has_option('mmc_agent', 'verifypeer'):
                self.mmc_agent['verifypeer'] = self.cp.getboolean('mmc_agent', 'verifypeer')
            if self.cp.has_option('mmc_agent', 'cacert'):
                self.mmc_agent['cacert'] = self.cp.get('mmc_agent', 'cacert')
            if self.cp.has_option('mmc_agent', 'localcert'):
                self.mmc_agent['localcert'] = self.cp.get('mmc_agent', 'localcert')
            if self.mmc_agent['enablessl']:
                if not os.path.isfile(self.mmc_agent['localcert']):
                    raise Exception('can\'t read SSL key "%s"' % (self.mmc_agent['localcert']))
                    return False
                if not os.path.isfile(self.mmc_agent['cacert']):
                    raise Exception('can\'t read SSL certificate "%s"' % (self.mmc_agent['cacert']))
                    return False
                if self.mmc_agent['verifypeer']:  # we need twisted.internet.ssl.Certificate to activate certs
                    import twisted.internet.ssl
                    if not hasattr(twisted.internet.ssl, "Certificate"):
                        raise Exception('I need at least Python Twisted 2.5 to handle peer checking')
                        return False

        # [launcher_xxx] section parsing
        for section in self.cp.sections():
            if re.compile("^launcher_[0-9]+$").match(section):
                username = self.cp.get(section, "username")
                password = self.cp.getpassword(section, "password")
                if not isTwistedEnoughForLoginPass():
                    if username != '':
                        log.warning("your version of twisted is not high enough to use login (%s/username)"%(section))
                        username = ''
                    if password != '':
                        log.warning("your version of twisted is not high enough to use password (%s/password)"%(section))
                        password = ''

                if self.cp.has_option(section, "slots"):
                    slots = self.cp.getint(section, "slots")
                else:
                    slots = 20

                self.launchers[section] = {
                        'enablessl': self.cp.getboolean(section, "enablessl"),
                        'host': self.cp.get(section, "host"),
                        'username': username,
                        'password': password,
                        'port': self.cp.get(section, "port"),
                        'slots': slots,
                    }
                if self.launchers[section]["enablessl"]:
                    uri = "https://"
                else:
                    uri = 'http://'
                if self.launchers[section]['username'] != '':
                    uri += '%s:%s@' % (self.launchers[section]['username'], self.launchers[section]['password'])
                uri += '%s:%d' % (self.launchers[section]['host'], int(self.launchers[section]['port']))
                self.launchers_uri.update({section: uri})

                pnp = PreferredNetworkParser(None, None)
                if self.cp.has_option(section, "preferred_network"):
                    _networks = pnp.parse(self.cp.get(section, "preferred_network"))
                else :
                    _networks = pnp.get_default()
                self.launchers_networks.update({section: _networks})
Пример #4
0
    def setup(self, config_file):
        # Load configuration file
        if not self.cp: # self.cp is set if presetup() was already called
            self.presetup(config_file)

        # [scheduler] section parsing
        self.name = self.cp.get("scheduler", "id")

        self.setoption("scheduler", "awake_time", "awake_time", 'int')
        self.setoption("scheduler", "initial_wait", "initial_wait", 'int')
        self.setoption("scheduler", "preempt_amount", "preempt_amount", 'int')
        self.setoption("scheduler", "preempt_period", "preempt_period", 'int')
        self.setoption("scheduler", "checkstatus_period", "checkstatus_period", 'int')
        self.setoption("scheduler", "loghealth_period", "loghealth_period", 'int')
        self.setoption("scheduler", "incertitude_factor", "incertitude_factor", 'float')

        # cache settings
        self.setoption("scheduler", "cache_size", "cache_size", 'int')
        self.setoption("scheduler", "cache_timeout", "cache_timeout", 'int')

        self.setoption("scheduler", "analyse_hour", "analyse_hour")
        if len(self.analyse_hour) == 0: # no option given
            log.info("analyse loop disabled as requested")
            self.active_analyse_hour = False
        else:
            try:
                splitted = self.analyse_hour.split(':')
                assert len(splitted) == 3 # only accept "HH:MM:SS"
                self.analyse_hour = (int(splitted[0]) * 60 + int(splitted[1])) * 60 + int(splitted[2])
                log.info("analyse loop enabled, will run every day at %s" % ":".join(splitted))
                self.active_analyse_hour = True
            except:
                log.warning("can't parse analyse_hour (read %s, expecting 'HH:MM:SS'), neutralysing analyse loop" % (self.analyse_hour))
                self.active_analyse_hour = False

        self.setoption("scheduler", "clean_states_time", "clean_states_time", 'int')
        self.setoption("scheduler", "active_clean_states", "active_clean_states")
        self.active_clean_states_run = False
        self.active_clean_states_stop = False
        for s in self.active_clean_states.split(','):
            if s == 'run': self.active_clean_states_run = True
            if s == 'stop': self.active_clean_states_stop = True

        self.setoption("scheduler", "max_slots", "max_slots", 'int')
        self.setoption("scheduler", "max_command_time", "max_command_time", 'int')
        self.setoption("scheduler", "max_upload_time", "max_upload_time", 'int')
        self.setoption("scheduler", "max_wol_time", "max_wol_time", 'int')
        self.setoption("scheduler", "dbencoding", "dbencoding")
        self.setoption("scheduler", "enablessl", "enablessl", 'bool')
        self.setoption("scheduler", "lock_processed_commands", "lock_processed_commands", 'bool')
        self.setoption("scheduler", "multithreading", "multithreading", 'bool')
        self.setoption("scheduler", "max_threads", "max_threads", 'int')

        if self.cp.has_option("scheduler", "non_fatal_steps"):
            self.non_fatal_steps = self.cp.get("scheduler", "non_fatal_steps").split(' ')
            log.debug("scheduler %s: section %s, option %s set to '%s'" % (self.name, "scheduler", "non_fatal_steps", self.non_fatal_steps))
        else:
            log.debug("scheduler %s: section %s, option %s not set, using default value '%s'" % (self.name, "scheduler", "non_fatal_steps", self.non_fatal_steps))

        if self.cp.has_option("scheduler", "mg_assign_algo"):
            self.mg_assign_algo = self.cp.get("scheduler", 'mg_assign_algo')

        if self.enablessl:
            if self.cp.has_option("scheduler", "privkey"):
                self.localcert = self.cp.get("scheduler", "privkey")
            if self.cp.has_option("scheduler", "localcert"):
                self.localcert = self.cp.get("scheduler", "localcert")
            if self.cp.has_option("scheduler", "certfile"):
                self.cacert = self.cp.get("scheduler", "certfile")
            if self.cp.has_option("scheduler", "cacert"):
                self.cacert = self.cp.get("scheduler", "cacert")
            if self.cp.has_option("scheduler", "verifypeer"):
                self.verifypeer = self.cp.getboolean("scheduler", "verifypeer")
            if not os.path.isfile(self.localcert):
                raise Exception('scheduler "%s": can\'t read SSL key "%s"' % (self.name, self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception('scheduler "%s": can\'t read SSL certificate "%s"' % (self.name, self.cacert))
                return False
            if self.verifypeer: # we need twisted.internet.ssl.Certificate to activate certs
                import twisted.internet.ssl
                if not hasattr(twisted.internet.ssl, "Certificate"):
                    raise Exception('scheduler "%s": I need at least Python Twisted 2.5 to handle peer checking' % (self.name))
                    return False

        if self.cp.has_option("scheduler", "listen"): # TODO remove in a future version
            log.warning("'listen' is obsolete, please replace it in your config file by 'host'")
            self.setoption("scheduler", "listen", "host")
        else:
            self.setoption("scheduler", "host", "host")
        self.setoption("scheduler", "port", "port")
        self.port = int(self.port)
        self.setoption("scheduler", "username", "username")
        self.setoption("scheduler", "password", "password", 'pass')
        if not isTwistedEnoughForLoginPass():
            if self.username != '':
                if self.username != 'username':
                    log.warning("your version of twisted is not high enough to use login (scheduler/username)")
                self.username = ''
            if self.password != '':
                if self.password != 'password':
                    log.warning("your version of twisted is not high enough to use password (scheduler/password)")
                self.password = ''

        self.setoption("scheduler", "mode", "mode")
        self.setoption("scheduler", "resolv_order", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.cp.has_option("scheduler", "preferred_network"):
            self.preferred_network = pnp.parse(self.cp.get("scheduler", "preferred_network"))
        else :
            self.preferred_network = pnp.get_default()


        self.setoption("scheduler", "netbios_path", "netbios_path")
        self.setoption("scheduler", "scheduler_path", "scheduler_path")
        self.setoption("scheduler", "scheduler_proxy_path", "scheduler_proxy_path")


        if self.cp.has_option("scheduler", "client_check"):
            self.client_check = {}
            for token in self.cp.get("scheduler", "client_check").split(','):
                (key, val) = token.split('=')
                self.client_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'client_check', self.client_check))
        if self.cp.has_option("scheduler", "server_check"):
            self.server_check = {}
            for token in self.cp.get("scheduler", "server_check").split(','):
                (key, val) = token.split('=')
                self.server_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'server_check', self.server_check))
        if self.cp.has_option("scheduler", "announce_check"):
            self.announce_check = {}
            for token in self.cp.get("scheduler", "announce_check").split(','):
                (key, val) = token.split('=')
                self.announce_check[key] = val
            log.info("scheduler %s: section %s, option %s set using given value" % (self.name, 'server_check', self.server_check))

        # [daemon] section parsing (parsing ofr user, group, and umask is done above in presetup)
        if self.cp.has_section("daemon"):
            if self.cp.has_option('daemon', 'pid_path'):
                log.warning("'pid_path' is deprecated, please replace it in your config file by 'pidfile'")
                self.setoption('daemon', 'pid_path', 'pid_path')
            else:
                self.setoption('daemon', 'pidfile', 'pid_path')

        # [mmc_agent] section parsing
        self.mmc_agent = {}
        if self.cp.has_section("mmc_agent"):
            self.mmc_agent = {
                'host' : "127.0.0.1",
                'port' : 7080,
                'username' : 'mmc',
                'password' : 's3cr3t',
                'enablessl' : True,
                'verifypeer' : False,
                'cacert' : mmcconfdir + "/pulse2/scheduler/keys/cacert.pem",
                'localcert' : mmcconfdir + "/pulse2/scheduler/keys/privkey.pem"}
            if self.cp.has_option('mmc_agent', 'host'):
                self.mmc_agent['host'] = self.cp.get('mmc_agent', 'host')
            if self.cp.has_option('mmc_agent', 'port'):
                self.mmc_agent['port'] = self.cp.getint('mmc_agent', 'port')
            if self.cp.has_option('mmc_agent', 'enablessl'):
                self.mmc_agent['enablessl'] = self.cp.getboolean('mmc_agent', 'enablessl')
            if self.cp.has_option('mmc_agent', 'verifypeer'):
                self.mmc_agent['verifypeer'] = self.cp.getboolean('mmc_agent', 'verifypeer')
            if self.cp.has_option('mmc_agent', 'cacert'):
                self.mmc_agent['cacert'] = self.cp.get('mmc_agent', 'cacert')
            if self.cp.has_option('mmc_agent', 'localcert'):
                self.mmc_agent['localcert'] = self.cp.get('mmc_agent', 'localcert')
            if self.mmc_agent['enablessl']:
                if not os.path.isfile(self.mmc_agent['localcert']):
                    raise Exception('can\'t read SSL key "%s"' % (self.mmc_agent['localcert']))
                    return False
                if not os.path.isfile(self.mmc_agent['cacert']):
                    raise Exception('can\'t read SSL certificate "%s"' % (self.mmc_agent['cacert']))
                    return False
                if self.mmc_agent['verifypeer']:  # we need twisted.internet.ssl.Certificate to activate certs
                    import twisted.internet.ssl
                    if not hasattr(twisted.internet.ssl, "Certificate"):
                        raise Exception('I need at least Python Twisted 2.5 to handle peer checking')
                        return False

        # [launcher_xxx] section parsing
        for section in self.cp.sections():
            if re.compile("^launcher_[0-9]+$").match(section):
                username = self.cp.get(section, "username")
                password = self.cp.getpassword(section, "password")
                if not isTwistedEnoughForLoginPass():
                    if username != '':
                        log.warning("your version of twisted is not high enough to use login (%s/username)"%(section))
                        username = ''
                    if password != '':
                        log.warning("your version of twisted is not high enough to use password (%s/password)"%(section))
                        password = ''

                self.launchers[section] = {
                        'enablessl': self.cp.getboolean(section, "enablessl"),
                        'host': self.cp.get(section, "host"),
                        'username': username,
                        'password': password,
                        'port': self.cp.get(section, "port")
                    }
                if self.launchers[section]["enablessl"]:
                    uri = "https://"
                else:
                    uri = 'http://'
                if self.launchers[section]['username'] != '':
                    uri += '%s:%s@' % (self.launchers[section]['username'], self.launchers[section]['password'])
                uri += '%s:%d' % (self.launchers[section]['host'], int(self.launchers[section]['port']))
                self.launchers_uri.update({section: uri})
Пример #5
0
    def setup(self, config_file):
        # Load configuration file
        if not self.cp:  # self.cp is set if presetup() was already called
            self.presetup(config_file)

        # [scheduler] section parsing
        self.name = self.cp.get("scheduler", "id")

        self.setoption("scheduler", "awake_time", "awake_time", 'int')
        self.setoption("scheduler", "initial_wait", "initial_wait", 'int')
        self.setoption("scheduler", "emitting_period", "emitting_period",
                       'float')
        self.setoption("scheduler", "proxy_buffer_period",
                       "proxy_buffer_period", 'float')
        self.setoption("scheduler", "proxy_buffer_start_delay",
                       "proxy_buffer_start_delay", 'int')

        # cache settings
        self.setoption("scheduler", "cache_size", "cache_size", 'int')
        self.setoption("scheduler", "cache_timeout", "cache_timeout", 'int')

        self.setoption("scheduler", "max_command_time", "max_command_time",
                       'int')
        self.setoption("scheduler", "max_upload_time", "max_upload_time",
                       'int')
        self.setoption("scheduler", "max_wol_time", "max_wol_time", 'int')
        self.setoption("scheduler", "dbencoding", "dbencoding")
        self.setoption("scheduler", "enablessl", "enablessl", 'bool')
        self.setoption("scheduler", "max_threads", "max_threads", 'int')

        self.setoption("scheduler", "imaging", "imaging", 'bool')
        self.setoption("scheduler", "max_to_overtimed", "max_to_overtimed",
                       'int')

        if self.cp.has_option("scheduler", "non_fatal_steps"):
            self.non_fatal_steps = self.cp.get("scheduler",
                                               "non_fatal_steps").split(' ')
            log.debug("scheduler %s: section %s, option %s set to '%s'" %
                      (self.name, "scheduler", "non_fatal_steps",
                       self.non_fatal_steps))
        else:
            log.debug(
                "scheduler %s: section %s, option %s not set, using default value '%s'"
                % (self.name, "scheduler", "non_fatal_steps",
                   self.non_fatal_steps))

        if self.enablessl:
            if self.cp.has_option("scheduler", "privkey"):
                self.localcert = self.cp.get("scheduler", "privkey")
            if self.cp.has_option("scheduler", "localcert"):
                self.localcert = self.cp.get("scheduler", "localcert")
            if self.cp.has_option("scheduler", "certfile"):
                self.cacert = self.cp.get("scheduler", "certfile")
            if self.cp.has_option("scheduler", "cacert"):
                self.cacert = self.cp.get("scheduler", "cacert")
            if self.cp.has_option("scheduler", "verifypeer"):
                self.verifypeer = self.cp.getboolean("scheduler", "verifypeer")
            if not os.path.isfile(self.localcert):
                raise Exception('scheduler "%s": can\'t read SSL key "%s"' %
                                (self.name, self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception(
                    'scheduler "%s": can\'t read SSL certificate "%s"' %
                    (self.name, self.cacert))
                return False
            if self.verifypeer:  # we need twisted.internet.ssl.Certificate to activate certs
                import twisted.internet.ssl
                if not hasattr(twisted.internet.ssl, "Certificate"):
                    raise Exception(
                        'scheduler "%s": I need at least Python Twisted 2.5 to handle peer checking'
                        % (self.name))
                    return False

        if self.cp.has_option("scheduler",
                              "listen"):  # TODO remove in a future version
            log.warning(
                "'listen' is obsolete, please replace it in your config file by 'host'"
            )
            self.setoption("scheduler", "listen", "host")
        else:
            self.setoption("scheduler", "host", "host")
        self.setoption("scheduler", "port", "port")
        self.port = int(self.port)
        self.setoption("scheduler", "username", "username")
        self.setoption("scheduler", "password", "password", 'pass')
        if not isTwistedEnoughForLoginPass():
            if self.username != '':
                if self.username != 'username':
                    log.warning(
                        "your version of twisted is not high enough to use login (scheduler/username)"
                    )
                self.username = ''
            if self.password != '':
                if self.password != 'password':
                    log.warning(
                        "your version of twisted is not high enough to use password (scheduler/password)"
                    )
                self.password = ''

        self.setoption("scheduler", "mode", "mode")
        self.setoption("scheduler", "resolv_order", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.cp.has_option("scheduler", "preferred_network"):
            self.preferred_network = pnp.parse(
                self.cp.get("scheduler", "preferred_network"))
        else:
            self.preferred_network = pnp.get_default()

        self.setoption("scheduler", "netbios_path", "netbios_path")
        self.setoption("scheduler", "scheduler_path", "scheduler_path")
        self.setoption("scheduler", "scheduler_proxy_path",
                       "scheduler_proxy_path")

        if self.cp.has_option("scheduler", "scheduler_proxy_socket_path"):
            self.scheduler_proxy_socket_path = self.cp.get(
                "scheduler", "scheduler_proxy_socket_path")
        if self.cp.has_option("scheduler", "scheduler_proxy_buffer_tmp"):
            self.scheduler_proxy_buffer_tmp = self.cp.get(
                "scheduler", "scheduler_proxy_buffer_tmp")

        if self.cp.has_option("scheduler", "client_check"):
            self.client_check = {}
            for token in self.cp.get("scheduler", "client_check").split(','):
                (key, val) = token.split('=')
                self.client_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'client_check', self.client_check))
        if self.cp.has_option("scheduler", "server_check"):
            self.server_check = {}
            for token in self.cp.get("scheduler", "server_check").split(','):
                (key, val) = token.split('=')
                self.server_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'server_check', self.server_check))
        if self.cp.has_option("scheduler", "announce_check"):
            self.announce_check = {}
            for token in self.cp.get("scheduler", "announce_check").split(','):
                (key, val) = token.split('=')
                self.announce_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'server_check', self.server_check))

        # [daemon] section parsing (parsing ofr user, group, and umask is done above in presetup)
        if self.cp.has_section("daemon"):
            if self.cp.has_option('daemon', 'pid_path'):
                log.warning(
                    "'pid_path' is deprecated, please replace it in your config file by 'pidfile'"
                )
                self.setoption('daemon', 'pid_path', 'pid_path')
            else:
                self.setoption('daemon', 'pidfile', 'pid_path')

        # [mmc_agent] section parsing
        self.mmc_agent = {}
        if self.cp.has_section("mmc_agent"):
            self.mmc_agent = {
                'host': "127.0.0.1",
                'port': 7080,
                'username': '******',
                'password': '******',
                'enablessl': True,
                'verifypeer': False,
                'cacert': mmcconfdir + "/pulse2/scheduler/keys/cacert.pem",
                'localcert': mmcconfdir + "/pulse2/scheduler/keys/privkey.pem"
            }
            if self.cp.has_option('mmc_agent', 'host'):
                self.mmc_agent['host'] = self.cp.get('mmc_agent', 'host')
            if self.cp.has_option('mmc_agent', 'port'):
                self.mmc_agent['port'] = self.cp.getint('mmc_agent', 'port')
            if self.cp.has_option('mmc_agent', 'enablessl'):
                self.mmc_agent['enablessl'] = self.cp.getboolean(
                    'mmc_agent', 'enablessl')
            if self.cp.has_option('mmc_agent', 'verifypeer'):
                self.mmc_agent['verifypeer'] = self.cp.getboolean(
                    'mmc_agent', 'verifypeer')
            if self.cp.has_option('mmc_agent', 'cacert'):
                self.mmc_agent['cacert'] = self.cp.get('mmc_agent', 'cacert')
            if self.cp.has_option('mmc_agent', 'localcert'):
                self.mmc_agent['localcert'] = self.cp.get(
                    'mmc_agent', 'localcert')
            if self.mmc_agent['enablessl']:
                if not os.path.isfile(self.mmc_agent['localcert']):
                    raise Exception('can\'t read SSL key "%s"' %
                                    (self.mmc_agent['localcert']))
                    return False
                if not os.path.isfile(self.mmc_agent['cacert']):
                    raise Exception('can\'t read SSL certificate "%s"' %
                                    (self.mmc_agent['cacert']))
                    return False
                if self.mmc_agent[
                        'verifypeer']:  # we need twisted.internet.ssl.Certificate to activate certs
                    import twisted.internet.ssl
                    if not hasattr(twisted.internet.ssl, "Certificate"):
                        raise Exception(
                            'I need at least Python Twisted 2.5 to handle peer checking'
                        )
                        return False

        # [launcher_xxx] section parsing
        for section in self.cp.sections():
            if re.compile("^launcher_[0-9]+$").match(section):
                username = self.cp.get(section, "username")
                password = self.cp.getpassword(section, "password")
                if not isTwistedEnoughForLoginPass():
                    if username != '':
                        log.warning(
                            "your version of twisted is not high enough to use login (%s/username)"
                            % (section))
                        username = ''
                    if password != '':
                        log.warning(
                            "your version of twisted is not high enough to use password (%s/password)"
                            % (section))
                        password = ''

                if self.cp.has_option(section, "slots"):
                    slots = self.cp.getint(section, "slots")
                else:
                    slots = 20

                self.launchers[section] = {
                    'enablessl': self.cp.getboolean(section, "enablessl"),
                    'host': self.cp.get(section, "host"),
                    'username': username,
                    'password': password,
                    'port': self.cp.get(section, "port"),
                    'slots': slots,
                }
                if self.launchers[section]["enablessl"]:
                    uri = "https://"
                else:
                    uri = 'http://'
                if self.launchers[section]['username'] != '':
                    uri += '%s:%s@' % (self.launchers[section]['username'],
                                       self.launchers[section]['password'])
                uri += '%s:%d' % (self.launchers[section]['host'],
                                  int(self.launchers[section]['port']))
                self.launchers_uri.update({section: uri})

                pnp = PreferredNetworkParser(None, None)
                if self.cp.has_option(section, "preferred_network"):
                    _networks = pnp.parse(
                        self.cp.get(section, "preferred_network"))
                else:
                    _networks = pnp.get_default()
                self.launchers_networks.update({section: _networks})
Пример #6
0
    def setup(self, config_file):
        # Load configuration file
        if not self.cp:  # self.cp is set if presetup() was already called
            self.presetup(config_file)

        # [scheduler] section parsing
        self.name = self.cp.get("scheduler", "id")

        self.setoption("scheduler", "awake_time", "awake_time", 'int')
        self.setoption("scheduler", "initial_wait", "initial_wait", 'int')
        self.setoption("scheduler", "preempt_amount", "preempt_amount", 'int')
        self.setoption("scheduler", "preempt_period", "preempt_period", 'int')
        self.setoption("scheduler", "checkstatus_period", "checkstatus_period",
                       'int')
        self.setoption("scheduler", "loghealth_period", "loghealth_period",
                       'int')
        self.setoption("scheduler", "incertitude_factor", "incertitude_factor",
                       'float')

        # cache settings
        self.setoption("scheduler", "cache_size", "cache_size", 'int')
        self.setoption("scheduler", "cache_timeout", "cache_timeout", 'int')

        self.setoption("scheduler", "analyse_hour", "analyse_hour")
        if len(self.analyse_hour) == 0:  # no option given
            log.info("analyse loop disabled as requested")
            self.active_analyse_hour = False
        else:
            try:
                splitted = self.analyse_hour.split(':')
                assert len(splitted) == 3  # only accept "HH:MM:SS"
                self.analyse_hour = (int(splitted[0]) * 60 +
                                     int(splitted[1])) * 60 + int(splitted[2])
                log.info("analyse loop enabled, will run every day at %s" %
                         ":".join(splitted))
                self.active_analyse_hour = True
            except:
                log.warning(
                    "can't parse analyse_hour (read %s, expecting 'HH:MM:SS'), neutralysing analyse loop"
                    % (self.analyse_hour))
                self.active_analyse_hour = False

        self.setoption("scheduler", "clean_states_time", "clean_states_time",
                       'int')
        self.setoption("scheduler", "active_clean_states",
                       "active_clean_states")
        self.active_clean_states_run = False
        self.active_clean_states_stop = False
        for s in self.active_clean_states.split(','):
            if s == 'run': self.active_clean_states_run = True
            if s == 'stop': self.active_clean_states_stop = True

        self.setoption("scheduler", "max_slots", "max_slots", 'int')
        self.setoption("scheduler", "max_command_time", "max_command_time",
                       'int')
        self.setoption("scheduler", "max_upload_time", "max_upload_time",
                       'int')
        self.setoption("scheduler", "max_wol_time", "max_wol_time", 'int')
        self.setoption("scheduler", "dbencoding", "dbencoding")
        self.setoption("scheduler", "enablessl", "enablessl", 'bool')
        self.setoption("scheduler", "lock_processed_commands",
                       "lock_processed_commands", 'bool')
        self.setoption("scheduler", "multithreading", "multithreading", 'bool')
        self.setoption("scheduler", "max_threads", "max_threads", 'int')

        if self.cp.has_option("scheduler", "non_fatal_steps"):
            self.non_fatal_steps = self.cp.get("scheduler",
                                               "non_fatal_steps").split(' ')
            log.debug("scheduler %s: section %s, option %s set to '%s'" %
                      (self.name, "scheduler", "non_fatal_steps",
                       self.non_fatal_steps))
        else:
            log.debug(
                "scheduler %s: section %s, option %s not set, using default value '%s'"
                % (self.name, "scheduler", "non_fatal_steps",
                   self.non_fatal_steps))

        if self.cp.has_option("scheduler", "mg_assign_algo"):
            self.mg_assign_algo = self.cp.get("scheduler", 'mg_assign_algo')

        if self.enablessl:
            if self.cp.has_option("scheduler", "privkey"):
                self.localcert = self.cp.get("scheduler", "privkey")
            if self.cp.has_option("scheduler", "localcert"):
                self.localcert = self.cp.get("scheduler", "localcert")
            if self.cp.has_option("scheduler", "certfile"):
                self.cacert = self.cp.get("scheduler", "certfile")
            if self.cp.has_option("scheduler", "cacert"):
                self.cacert = self.cp.get("scheduler", "cacert")
            if self.cp.has_option("scheduler", "verifypeer"):
                self.verifypeer = self.cp.getboolean("scheduler", "verifypeer")
            if not os.path.isfile(self.localcert):
                raise Exception('scheduler "%s": can\'t read SSL key "%s"' %
                                (self.name, self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception(
                    'scheduler "%s": can\'t read SSL certificate "%s"' %
                    (self.name, self.cacert))
                return False
            if self.verifypeer:  # we need twisted.internet.ssl.Certificate to activate certs
                import twisted.internet.ssl
                if not hasattr(twisted.internet.ssl, "Certificate"):
                    raise Exception(
                        'scheduler "%s": I need at least Python Twisted 2.5 to handle peer checking'
                        % (self.name))
                    return False

        if self.cp.has_option("scheduler",
                              "listen"):  # TODO remove in a future version
            log.warning(
                "'listen' is obsolete, please replace it in your config file by 'host'"
            )
            self.setoption("scheduler", "listen", "host")
        else:
            self.setoption("scheduler", "host", "host")
        self.setoption("scheduler", "port", "port")
        self.port = int(self.port)
        self.setoption("scheduler", "username", "username")
        self.setoption("scheduler", "password", "password", 'pass')
        if not isTwistedEnoughForLoginPass():
            if self.username != '':
                if self.username != 'username':
                    log.warning(
                        "your version of twisted is not high enough to use login (scheduler/username)"
                    )
                self.username = ''
            if self.password != '':
                if self.password != 'password':
                    log.warning(
                        "your version of twisted is not high enough to use password (scheduler/password)"
                    )
                self.password = ''

        self.setoption("scheduler", "mode", "mode")
        self.setoption("scheduler", "resolv_order", "resolv_order")
        if not type(self.resolv_order) == type([]):
            self.resolv_order = self.resolv_order.split(' ')

        pnp = PreferredNetworkParser(None, None)
        if self.cp.has_option("scheduler", "preferred_network"):
            self.preferred_network = pnp.parse(
                self.cp.get("scheduler", "preferred_network"))
        else:
            self.preferred_network = pnp.get_default()

        self.setoption("scheduler", "netbios_path", "netbios_path")
        self.setoption("scheduler", "scheduler_path", "scheduler_path")
        self.setoption("scheduler", "scheduler_proxy_path",
                       "scheduler_proxy_path")

        if self.cp.has_option("scheduler", "client_check"):
            self.client_check = {}
            for token in self.cp.get("scheduler", "client_check").split(','):
                (key, val) = token.split('=')
                self.client_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'client_check', self.client_check))
        if self.cp.has_option("scheduler", "server_check"):
            self.server_check = {}
            for token in self.cp.get("scheduler", "server_check").split(','):
                (key, val) = token.split('=')
                self.server_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'server_check', self.server_check))
        if self.cp.has_option("scheduler", "announce_check"):
            self.announce_check = {}
            for token in self.cp.get("scheduler", "announce_check").split(','):
                (key, val) = token.split('=')
                self.announce_check[key] = val
            log.info(
                "scheduler %s: section %s, option %s set using given value" %
                (self.name, 'server_check', self.server_check))

        # [daemon] section parsing (parsing ofr user, group, and umask is done above in presetup)
        if self.cp.has_section("daemon"):
            if self.cp.has_option('daemon', 'pid_path'):
                log.warning(
                    "'pid_path' is deprecated, please replace it in your config file by 'pidfile'"
                )
                self.setoption('daemon', 'pid_path', 'pid_path')
            else:
                self.setoption('daemon', 'pidfile', 'pid_path')

        # [mmc_agent] section parsing
        self.mmc_agent = {}
        if self.cp.has_section("mmc_agent"):
            self.mmc_agent = {
                'host': "127.0.0.1",
                'port': 7080,
                'username': '******',
                'password': '******',
                'enablessl': True,
                'verifypeer': False,
                'cacert': mmcconfdir + "/pulse2/scheduler/keys/cacert.pem",
                'localcert': mmcconfdir + "/pulse2/scheduler/keys/privkey.pem"
            }
            if self.cp.has_option('mmc_agent', 'host'):
                self.mmc_agent['host'] = self.cp.get('mmc_agent', 'host')
            if self.cp.has_option('mmc_agent', 'port'):
                self.mmc_agent['port'] = self.cp.getint('mmc_agent', 'port')
            if self.cp.has_option('mmc_agent', 'enablessl'):
                self.mmc_agent['enablessl'] = self.cp.getboolean(
                    'mmc_agent', 'enablessl')
            if self.cp.has_option('mmc_agent', 'verifypeer'):
                self.mmc_agent['verifypeer'] = self.cp.getboolean(
                    'mmc_agent', 'verifypeer')
            if self.cp.has_option('mmc_agent', 'cacert'):
                self.mmc_agent['cacert'] = self.cp.get('mmc_agent', 'cacert')
            if self.cp.has_option('mmc_agent', 'localcert'):
                self.mmc_agent['localcert'] = self.cp.get(
                    'mmc_agent', 'localcert')
            if self.mmc_agent['enablessl']:
                if not os.path.isfile(self.mmc_agent['localcert']):
                    raise Exception('can\'t read SSL key "%s"' %
                                    (self.mmc_agent['localcert']))
                    return False
                if not os.path.isfile(self.mmc_agent['cacert']):
                    raise Exception('can\'t read SSL certificate "%s"' %
                                    (self.mmc_agent['cacert']))
                    return False
                if self.mmc_agent[
                        'verifypeer']:  # we need twisted.internet.ssl.Certificate to activate certs
                    import twisted.internet.ssl
                    if not hasattr(twisted.internet.ssl, "Certificate"):
                        raise Exception(
                            'I need at least Python Twisted 2.5 to handle peer checking'
                        )
                        return False

        # [launcher_xxx] section parsing
        for section in self.cp.sections():
            if re.compile("^launcher_[0-9]+$").match(section):
                username = self.cp.get(section, "username")
                password = self.cp.getpassword(section, "password")
                if not isTwistedEnoughForLoginPass():
                    if username != '':
                        log.warning(
                            "your version of twisted is not high enough to use login (%s/username)"
                            % (section))
                        username = ''
                    if password != '':
                        log.warning(
                            "your version of twisted is not high enough to use password (%s/password)"
                            % (section))
                        password = ''

                self.launchers[section] = {
                    'enablessl': self.cp.getboolean(section, "enablessl"),
                    'host': self.cp.get(section, "host"),
                    'username': username,
                    'password': password,
                    'port': self.cp.get(section, "port")
                }
                if self.launchers[section]["enablessl"]:
                    uri = "https://"
                else:
                    uri = 'http://'
                if self.launchers[section]['username'] != '':
                    uri += '%s:%s@' % (self.launchers[section]['username'],
                                       self.launchers[section]['password'])
                uri += '%s:%d' % (self.launchers[section]['host'],
                                  int(self.launchers[section]['port']))
                self.launchers_uri.update({section: uri})