Exemplo n.º 1
0
    def readConf(self):
        """
        Read the module configuration
        """
        PluginConfig.readConf(self)

        # API Package
        if self.has_option("user_package_api", "server"):
            self.upaa_server = self.get("user_package_api", "server")
        if self.has_option("user_package_api", "port"):
            self.upaa_port = self.get("user_package_api", "port")
        if self.has_option("user_package_api", "mountpoint"):
            self.upaa_mountpoint = self.get("user_package_api", "mountpoint")

        if self.has_option("user_package_api", "username"):
            if not isTwistedEnoughForLoginPass():
                logging.getLogger().warning(
                    "your version of twisted is not high enough to use login (user_package_api/username)"
                )
                self.upaa_username = ""
            else:
                self.upaa_username = self.get("user_package_api", "username")
        if self.has_option("user_package_api", "password"):
            if not isTwistedEnoughForLoginPass():
                logging.getLogger().warning(
                    "your version of twisted is not high enough to use password (user_package_api/password)"
                )
                self.upaa_password = ""
            else:
                self.upaa_password = self.get("user_package_api", "password")
        if self.has_option("user_package_api", "tmp_dir"):
            self.tmp_dir = self.get("user_package_api", "tmp_dir")
        if self.has_option("user_package_api", "enablessl"):
            self.upaa_enablessl = self.getboolean("user_package_api",
                                                  "enablessl")

        if self.upaa_enablessl:
            if self.has_option("user_package_api", "verifypeer"):
                self.upaa_verifypeer = self.getboolean("user_package_api",
                                                       "verifypeer")
            if self.upaa_verifypeer:  # we need twisted.internet.ssl.Certificate to activate certs
                if self.has_option("user_package_api", "cacert"):
                    self.upaa_cacert = self.get("user_package_api", "cacert")
                if self.has_option("user_package_api", "localcert"):
                    self.upaa_localcert = self.get("user_package_api",
                                                   "localcert")
                if not os.path.isfile(self.upaa_localcert):
                    raise Exception('can\'t read SSL key "%s"' %
                                    (self.upaa_localcert))
                if not os.path.isfile(self.upaa_cacert):
                    raise Exception('can\'t read SSL certificate "%s"' %
                                    (self.upaa_cacert))
                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'
                    )
Exemplo n.º 2
0
    def readConf(self):
        """
        Read the module configuration
        """
        PluginConfig.readConf(self)

        # API Package
        if self.has_option("user_package_api", "server"):
            self.upaa_server = self.get("user_package_api", "server")
        if self.has_option("user_package_api", "port"):
            self.upaa_port = self.get("user_package_api", "port")
        if self.has_option("user_package_api", "mountpoint"):
            self.upaa_mountpoint = self.get("user_package_api", "mountpoint")

        if self.has_option("user_package_api", "username"):
            if not isTwistedEnoughForLoginPass():
                logging.getLogger().warning("your version of twisted is not high enough to use login (user_package_api/username)")
                self.upaa_username = ""
            else:
                self.upaa_username = self.get("user_package_api", "username")
        if self.has_option("user_package_api", "password"):
            if not isTwistedEnoughForLoginPass():
                logging.getLogger().warning("your version of twisted is not high enough to use password (user_package_api/password)")
                self.upaa_password = ""
            else:
                self.upaa_password = self.get("user_package_api", "password")
        if self.has_option("user_package_api", "tmp_dir"):
            self.tmp_dir = self.get("user_package_api", "tmp_dir")
        if self.has_option("user_package_api", "enablessl"):
            self.upaa_enablessl = self.getboolean("user_package_api", "enablessl")

        if self.upaa_enablessl:
            if self.has_option("user_package_api", "verifypeer"):
                self.upaa_verifypeer = self.getboolean("user_package_api", "verifypeer")
            if self.upaa_verifypeer: # we need twisted.internet.ssl.Certificate to activate certs
                if self.has_option("user_package_api", "cacert"):
                    self.upaa_cacert = self.get("user_package_api", "cacert")
                if self.has_option("user_package_api", "localcert"):
                    self.upaa_localcert = self.get("user_package_api", "localcert")
                if not os.path.isfile(self.upaa_localcert):
                    raise Exception('can\'t read SSL key "%s"' % (self.upaa_localcert))
                if not os.path.isfile(self.upaa_cacert):
                    raise Exception('can\'t read SSL certificate "%s"' % (self.upaa_cacert))
                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')
        
        # Appstream settings
        if self.has_option("appstream", "url"):
            self.appstream_url = self.get("appstream", "url")
Exemplo n.º 3
0
    def setup(self, config_file):
        if self.cp == None:
            # Load configuration file
            if sys.platform != "win32":
                self.cp = Pulse2ConfigParser()
            else:
                self.cp = ConfigParser.ConfigParser()
            self.cp.read(config_file)

        if self.cp.has_option("main", "bind"):  # TODO remove in a future version
            logging.getLogger().warning("'bind' is obsolete, please replace it in your config file by 'host'")
            self.bind = self.cp.get("main", 'bind')
        elif self.cp.has_option('main', 'host'):
            self.bind = self.cp.get("main", 'host')
        if self.cp.has_option('main', 'port'):
            self.port = self.cp.getint("main", 'port')
        if self.cp.has_option('main', 'public_ip'):
            self.public_ip = self.cp.get("main", 'public_ip')
        else:
            self.public_ip = self.bind

        if sys.platform != "win32":
            if self.cp.has_section('daemon'):
                if self.cp.has_option('daemon', 'pidfile'):
                    self.pid_path = self.cp.get('daemon', 'pidfile')
                if self.cp.has_option("daemon", "user"):
                    self.daemon_user = pwd.getpwnam(self.cp.get("daemon", "user"))[2]
                if self.cp.has_option("daemon", "group"):
                    self.daemon_group = grp.getgrnam(self.cp.get("daemon", "group"))[2]
                if self.cp.has_option("daemon", "umask"):
                    self.umask = int(self.cp.get("daemon", "umask"), 8)

        if sys.platform == "win32":
            if self.cp.has_option("main", "use_iocp_reactor"):
                self.use_iocp_reactor = self.cp.getboolean("main", "use_iocp_reactor")

        if self.cp.has_option('ssl', 'username'):
            self.username = self.cp.get('ssl', 'username')
            if sys.platform != "win32":
                self.password = self.cp.getpassword('ssl', 'password')
            else:
                self.password = self.cp.get('ssl', 'password')
            if not isTwistedEnoughForLoginPass():
                if self.username:
                    logging.getLogger().warn("your version of twisted is not high enough to use login (ssl/username)")
                    self.username = ''
                if self.password != '':
                    logging.getLogger().warning("your version of twisted is not high enough to use password (ssl/password)")
                    self.password = ''

        if self.cp.has_option('ssl', 'enablessl'):
            self.enablessl = self.cp.getboolean('ssl', 'enablessl')
        if self.enablessl:
            self.proto = 'https'
            if self.cp.has_option('ssl', 'certfile'):
                self.cacert = self.cp.get('ssl', 'certfile')
            if self.cp.has_option('ssl', 'cacert'):
                self.cacert = self.cp.get('ssl', 'cacert')
            if self.cp.has_option('ssl', 'privkey'):
                self.localcert = self.cp.get('ssl', 'privkey')
            if self.cp.has_option('ssl', 'localcert'):
                self.localcert = self.cp.get('ssl', 'localcert')
            if self.cp.has_option('ssl', 'verifypeer'):
                self.verifypeer = self.cp.getboolean('ssl', 'verifypeer')
            if not os.path.isfile(self.localcert):
                raise Exception('can\'t read SSL key "%s"' % (self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception('can\'t read SSL certificate "%s"' % (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('I need at least Python Twisted 2.5 to handle peer checking')
                    return False

        if self.cp.has_section('mirror_api'):
            self.mirror_api['mount_point'] = '/rpc'
            if self.cp.has_option('mirror_api', 'mount_point'):
                self.mirror_api['mount_point'] = self.cp.get('mirror_api', 'mount_point')

        if self.cp.has_section('user_packageapi_api'):
            self.user_package_api['mount_point'] = '/upaa'
            if self.cp.has_option('user_packageapi_api', 'mount_point'):
                self.user_package_api['mount_point'] = self.cp.get('user_packageapi_api', 'mount_point')

        if self.cp.has_section('scheduler_api'):
            self.scheduler_api['mount_point'] = '/scheduler_api'
            self.scheduler_api['schedulers'] = 'scheduler_01'
            if self.cp.has_option('scheduler_api', 'mount_point'):
                self.scheduler_api['mount_point'] = self.cp.get('scheduler_api', 'mount_point')
            if self.cp.has_option('scheduler_api', 'schedulers'):
                self.scheduler_api['schedulers'] = self.cp.get('scheduler_api', 'schedulers')

        if self.cp.has_option('main', 'tmp_input_dir'):
            self.tmp_input_dir = self.cp.get('main', 'tmp_input_dir')

        for section in self.cp.sections():
            if re.compile('^mirror:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                mirror = {'mount_point': mount_point, 'src': src}
                if self.cp.has_option(section, 'mirror'):
                    mirror['mirror'] = self.cp.get(section, 'mirror')
                self.mirrors.append(mirror)
            if re.compile('^package_api_get:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                self.package_api_get.append({'mount_point': mount_point, 'src': src})
            if re.compile('^package_api_put:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                pap_tmp_input_dir = self.tmp_input_dir
                if self.cp.has_option(section, 'tmp_input_dir'):
                    self.package_detect_activate = True
                    self.package_detect_tmp_activate = True
                    pap_tmp_input_dir = self.cp.get(section, 'tmp_input_dir')

                self.package_api_put.append({'mount_point': mount_point, 'src': src, 'tmp_input_dir': pap_tmp_input_dir})

        # [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/package-server/keys/cacert.pem",
                'localcert' : mmcconfdir + "/pulse2/package-server/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

        # [imaging_api] section parsing
        if self.cp.has_section("imaging_api") and self.cp.has_option("imaging_api", 'uuid'):
            # mount point
            imaging_mp = '/imaging_api'
            # base folder
            base_folder = '/var/lib/pulse2/imaging'
            # will contain the bootloader material (revoboot + splashscreen), served by tftp
            bootloader_folder = 'bootloader'
            # CDROM bootloader
            cdrom_bootloader = 'cdrom_boot'
            # Boot splash screen
            bootsplash_file = 'bootsplash.xpm'
            # will contain the boot menus, served by tftp
            bootmenus_folder = 'bootmenus'
            # will contain diskless stuff (kernel, initramfs, additional tools), served by tftp
            diskless_folder = 'diskless'
            # diskless kernel
            diskless_kernel = 'kernel'
            # diskless initrd
            diskless_initrd = 'initrd'
            # diskless initrd for CD-ROM
            diskless_initrdcd = 'initrdcd'
            # diskless memtest tool
            diskless_memtest = 'memtest'
            # will contain computer-related materials
            computers_folder = 'computers'
            # will contain inventories
            inventories_folder = 'inventories'
            # will contain masters, served by tftp
            masters_folder = 'masters'
            # will contain postinstall binaries
            postinst_folder = 'postinst'
            # will contain archived computer imaging data
            archives_folder = 'archives'
            # will contain generated ISO images
            isos_folder = '/var/lib/pulse2/imaging/isos'
            # tool used to generate ISO file
            isogen_tool = '/usr/bin/genisoimage'
            # will contain our UUID/MAC Addr cache
            uuid_cache_file = os.path.join(base_folder, 'uuid-cache.txt')
            # our UUID/MAC Addr cache lifetime
            uuid_cache_lifetime = 300
            # RPC replay file
            rpc_replay_file = os.path.join(base_folder, 'rpc-replay.pck')
            # RPC replay loop timer in seconds
            rpc_loop_timer = 60
            # RPC to replay at each loop
            rpc_count = 10
            # Interval in seconds between two RPCs
            rpc_interval = 2
            # Package Server UUID
            uuid = ""

            if self.cp.has_option("imaging_api", 'mount_point'):
                imaging_mp = self.cp.get("imaging_api", 'mount_point')
            if self.cp.has_option('imaging_api', 'base_folder'):
                base_folder = self.cp.get('imaging_api', 'base_folder')
            if self.cp.has_option('imaging_api', 'bootloader_folder'):
                bootloader_folder = self.cp.get('imaging_api', 'bootloader_folder')
            if self.cp.has_option('imaging_api', 'cdrom_bootloader'):
                cdrom_bootloader = self.cp.get('imaging_api', 'cdrom_bootloader')
            if self.cp.has_option('imaging_api', 'bootsplash_file'):
                bootsplash_file = self.cp.get('imaging_api', 'bootlsplash_file')
            if self.cp.has_option('imaging_api', 'bootmenus_folder'):
                bootmenus_folder = self.cp.get('imaging_api', 'bootmenus_folder')
            if self.cp.has_option('imaging_api', 'diskless_folder'):
                diskless_folder = self.cp.get('imaging_api', 'diskless_folder')
            if self.cp.has_option("imaging_api", 'diskless_kernel'):
                diskless_kernel = self.cp.get("imaging_api", 'diskless_kernel')
            if self.cp.has_option("imaging_api", 'diskless_initrd'):
                diskless_initrd = self.cp.get("imaging_api", 'diskless_initrd')
            if self.cp.has_option('imaging_api', 'diskless_initrdcd'):
                diskless_initrdcd = self.cp.get("imaging_api", 'diskless_initrdcd')
            if self.cp.has_option("imaging_api", 'diskless_memtest'):
                diskless_memtest = self.cp.get("imaging_api", 'diskless_memtest')
            if self.cp.has_option('imaging_api', 'computers_folder'):
                computers_folder = self.cp.get('imaging_api', 'computers_folder')
            if self.cp.has_option('imaging_api', 'inventories_folder'):
                inventories_folder = self.cp.get('imaging_api', 'inventories_folder')
            if self.cp.has_option('imaging_api', 'masters_folder'):
                masters_folder = self.cp.get('imaging_api', 'masters_folder')
            if self.cp.has_option('imaging_api', 'postinst_folder'):
                postinst_folder = self.cp.get('imaging_api', 'postinst_folder')
            if self.cp.has_option('imaging_api', 'archives_folder'):
                archives_folder = self.cp.get('imaging_api', 'archives_folder')
            if self.cp.has_option('imaging_api', 'isos_folder'):
                isos_folder = self.cp.get('imaging_api', 'isos_folder')
            if self.cp.has_option('imaging_api', 'isogen_tool'):
                isogen_tool = self.cp.get('imaging_api', 'isogen_tool')
            if self.cp.has_option('imaging_api', 'uuid_cache_file'):
                uuid_cache_file = os.path.join(base_folder, self.cp.get('imaging_api', 'uuid_cache_file'))
            if self.cp.has_option('imaging_api', 'uuid_cache_lifetime'):
                uuid_cache_lifetime = self.cp.getint('imaging_api', 'uuid_cache_lifetime')
            if self.cp.has_option('imaging_api', 'rpc_replay_file'):
                rpc_replay_file = os.path.join(base_folder, self.cp.get('imaging_api', 'rpc_replay_file'))
            if self.cp.has_option('imaging_api', 'rpc_loop_timer'):
                rpc_loop_timer = self.cp.getint('imaging_api', 'rpc_loop_timer')
            if self.cp.has_option('imaging_api', 'rpc_count'):
                rpc_count = self.cp.getint('imaging_api', 'rpc_count')
            if self.cp.has_option('imaging_api', 'rpc_interval'):
                rpc_interval = self.cp.getint('imaging_api', 'rpc_interval')
            if self.cp.has_option("imaging_api", 'uuid'):
                uuid = self.cp.get("imaging_api", 'uuid')
            if not isUUID(uuid):
                raise TypeError("'%s' is not an valid UUID : in my config file, section [imaging_api], set a correct uuid." % uuid)

            self.imaging_api = {
                'mount_point'         : imaging_mp,
                'base_folder'         : base_folder,
                'bootloader_folder'   : bootloader_folder,
                'bootsplash_file'     : bootsplash_file,
                'bootmenus_folder'    : bootmenus_folder,
                'cdrom_bootloader'    : cdrom_bootloader,
                'diskless_folder'     : diskless_folder,
                'diskless_kernel'     : diskless_kernel,
                'diskless_initrd'     : diskless_initrd,
                'diskless_initrdcd'   : diskless_initrdcd,
                'diskless_memtest'    : diskless_memtest,
                'computers_folder'    : computers_folder,
                'inventories_folder'  : inventories_folder,
                'masters_folder'      : masters_folder,
                'postinst_folder'     : postinst_folder,
                'archives_folder'     : archives_folder,
                'isos_folder'         : isos_folder,
                'isogen_tool'         : isogen_tool,
                'src'                 : src,
                'uuid'                : uuid,
                'uuid_cache_file'     : uuid_cache_file,
                'uuid_cache_lifetime' : uuid_cache_lifetime,
                'rpc_replay_file'     : rpc_replay_file,
                'rpc_loop_timer'      : rpc_loop_timer,
                'rpc_count'           : rpc_count,
                'rpc_interval'        : rpc_interval}

        if self.cp.has_option("main", "package_detect_activate"):
            # WARN this must overide the previously defined activate if it is in the config file
            self.package_detect_activate = self.cp.getboolean("main", "package_detect_activate")
            if self.package_detect_activate and self.cp.has_option("main", "package_detect_loop"):
                self.package_detect_loop = self.cp.getint("main", "package_detect_loop")

            if self.cp.has_option("main", "package_detect_smart_method"):
                package_detect_smart_method = self.cp.get("main", "package_detect_smart_method")
                if package_detect_smart_method != 'none':
                    package_detect_smart_method = package_detect_smart_method.split(',')
                    self.package_detect_smart = True
                    if 'last_time_modification' in package_detect_smart_method:
                        self.package_detect_smart_method.append(self.SMART_DETECT_LAST)
                    if 'check_in_loop' in package_detect_smart_method:
                        self.package_detect_smart_method.append(self.SMART_DETECT_LOOP)
                    if 'check_size' in package_detect_smart_method:
                        self.package_detect_smart_method.append(self.SMART_DETECT_SIZE)
                    else:
                        logging.getLogger().info("dont know the package_detect_smart_method '%s'")
                    if self.cp.has_option("main", "package_detect_smart_time"):
                        self.package_detect_smart_time = self.cp.getint("main", "package_detect_smart_time")
                else:
                    self.package_detect_smart = False

        if self.cp.has_option("main", "package_mirror_target"):
            self.package_mirror_target = self.cp.get("main", "package_mirror_target").split(' ')
            if (type(self.package_mirror_target) == str and self.package_mirror_target != '') or \
                    (type(self.package_mirror_target) == list and len(self.package_mirror_target) == 1 and self.package_mirror_target[0] != '') or \
                    (type(self.package_mirror_target) == list and len(self.package_mirror_target) != 1):
                self.package_mirror_activate = True

                if self.cp.has_option("main", 'package_mirror_status_file'):
                    self.package_mirror_status_file = self.cp.get("main", 'package_mirror_status_file')
                if self.cp.has_option("main", 'package_mirror_loop'):
                    self.package_mirror_loop = self.cp.getint("main", 'package_mirror_loop')

                if self.cp.has_option("main", 'package_mirror_command'):
                    self.package_mirror_command = self.cp.get("main", 'package_mirror_command')
                if self.cp.has_option("main", 'package_mirror_command_options'):
                    self.package_mirror_command_options = self.cp.get("main", 'package_mirror_command_options').split(' ')
                if self.cp.has_option("main", "package_mirror_command_options_ssh_options"):
                    self.package_mirror_command_options_ssh_options = self.cp.get("main", 'package_mirror_command_options_ssh_options').split(' ')
                if self.cp.has_option("main", 'package_mirror_level0_command_options'):
                    self.package_mirror_level0_command_options = self.cp.get("main", 'package_mirror_level0_command_options').split(' ')

            if self.cp.has_option("main", "package_global_mirror_activate"):
                self.package_global_mirror_activate = self.cp.getboolean("main", "package_global_mirror_activate")
                if self.cp.has_option("main", "package_global_mirror_loop"):
                    self.package_global_mirror_loop = self.cp.getint("main", "package_global_mirror_loop")
                if self.cp.has_option("main", "package_global_mirror_command_options"):
                    self.package_global_mirror_command_options = self.cp.get("main", "package_global_mirror_command_options").split(' ')

        if self.cp.has_option("main", "real_package_deletion"):
            self.real_package_deletion = self.cp.getboolean("main", "real_package_deletion")
        if self.cp.has_option("main", "mm_assign_algo"):
            self.mm_assign_algo = self.cp.get("main", 'mm_assign_algo')
        if self.cp.has_option("main", "up_assign_algo"):
            self.up_assign_algo = self.cp.get("main", 'up_assign_algo')
Exemplo n.º 4
0
    def setup(self, config_file, name = None):
        # Load configuration file
        if not self.cp: # self.cp is set if presetup() was already called
            self.presetup(config_file)

        self.name = name

        # Parse "launchers" section
        self.setoption('launchers', 'inventory_command', 'inventory_command')
        self.setoption('launchers', 'launcher_path', 'launcher_path')
        self.setoption('launchers', 'max_command_age', 'max_command_age', 'int')
        self.setoption('launchers', 'max_ping_time', 'max_ping_time', 'int')
        self.setoption('launchers', 'max_probe_time', 'max_probe_time', 'int')
        self.setoption('launchers', 'ping_path', 'ping_path')
        self.setoption('launchers', 'source_path', 'source_path')
        self.setoption('launchers', 'reboot_command', 'reboot_command')
        self.setoption('launchers', 'halt_command', 'halt_command')
        self.setoption('launchers', 'target_path', 'target_path')
        self.setoption('launchers', 'temp_folder_prefix', 'temp_folder_prefix')

        # Parse "wrapper" section
        self.setoption('wrapper', 'max_log_size', 'wrapper_max_log_size', 'int')
        self.setoption('wrapper', 'max_exec_time', 'wrapper_max_exec_time', 'int')
        self.setoption('wrapper', 'path', 'wrapper_path')

        # Parse "wget" section
        self.setoption('wget', 'wget_path', 'wget_path')
        if self.cp.has_section("wget"):
            if self.cp.has_option("wget", "wget_options"):
                self.wget_options = self.cp.get("wget", "wget_options").split(' ')
        self.setoption('wget', 'check_certs', 'wget_check_certs', 'bool')
        self.setoption('wget', 'resume', 'wget_resume', 'bool')

        # Parse a part of "ssh" section
        self.setoption('ssh', 'ssh_path', 'ssh_path')
        self.setoption('ssh', 'scp_path', 'scp_path')
        self.setoption('ssh', 'ssh_agent_path', 'ssh_agent_path')

        # Parse "rsync" section
        self.setoption('rsync', 'rsync_path', 'rsync_path')
        self.setoption('rsync', 'resume', 'rsync_resume', 'bool')
        self.setoption('rsync', 'set_executable', 'rsync_set_executable')
        if not self.rsync_set_executable in ('yes', 'no', 'keep'):
            self.logger.warning("set_executable can have '%s' for value (yes|no|keep)"%(self.rsync_set_executable))
            self.rsync_set_executable = 'yes'
        self.setoption('rsync', 'set_access', 'rsync_set_access')
        if not self.rsync_set_access in ('private', 'restricted', 'public'):
            self.logger.warning("set_access can have '%s' for value (private|restricted|public)"%(self.rsync_set_access))
            self.rsync_set_access = 'private'

        # +----------------+------------------+---------------------+------------------+
        # | set_executable |                  |                     |                  |
        # +--------------\ |       yes        |         no          |        keep      |
        # | set_access    \|                  |                     |                  |
        # +----------------+------------------+---------------------+------------------+
        # | private        | u=rwx,g=,o=  (1) | u=rw,g=,o=          | u=rwX,g=,o=      |
        # +----------------+------------------+---------------------+------------------+
        # | restricted     | u=rwx,g=rx,o=    | u=rw,g=r,o=         | u=rwX,g=rX,o=    |
        # +----------------+------------------+---------------------+------------------+
        # | public         | u=rwx,g=rwx,o=rx | u=rw,g=rw,o=r       | u=rwX,g=rwX,o=rX |
        # +----------------+------------------+---------------------+------------------+
        # (1) : default value
        exe = 'X'
        if self.rsync_set_executable == 'yes':
            exe = 'x'
        elif self.rsync_set_executable == 'no':
            exe = ''

        other = ',o='
        group = ',g='
        if self.rsync_set_access == 'public':
            other += "r%s"%(exe)
            group += "rw%s"%(exe)
        elif self.rsync_set_access == 'restricted':
            group += "r%s"%(exe)
        self.rsync_set_chmod = 'u=rw%s%s%s'%(exe, group, other)

        log.debug("config metavalue 'rsync_set_chmod' = %s"%(self.rsync_set_chmod))

        # [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')

        # Parse "wol" section
        self.setoption('wol', 'wol_bcast', 'wol_bcast')
        self.setoption('wol', 'wol_path', 'wol_path')
        self.setoption('wol', 'wol_port', 'wol_port')

        # Parse "tcp_sproxy" section
        self.setoption('tcp_sproxy', 'tcp_sproxy_path', 'tcp_sproxy_path')
        self.setoption('tcp_sproxy', 'tcp_sproxy_host', 'tcp_sproxy_host')
        self.setoption('tcp_sproxy', 'tcp_sproxy_establish_delay', 'tcp_sproxy_establish_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_connect_delay', 'tcp_sproxy_connect_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_session_lenght', 'tcp_sproxy_session_lenght', 'int')
        if self.cp.has_section("tcp_sproxy"):
            if self.cp.has_option("tcp_sproxy", "tcp_sproxy_port_range"):
                range = map(lambda x: int(x), self.cp.get("tcp_sproxy", "tcp_sproxy_port_range").split('-'))
                if len(range) != 2:
                    log.info("'tcp_sproxy_port_range' not formated as expected, using default value, please check your config file ")
                else:
                    (self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end) = range
        log.info("launcher %s: section %s, option %s set to %d-%d" % (self.name, 'tcp_sproxy', 'tcp_sproxy_port_range', self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end))

        # Parse "smart_cleaner" section
        self.setoption('smart_cleaner', 'smart_cleaner_path', 'smart_cleaner_path')
        if self.smart_cleaner_path == '':
            LauncherConfig().is_smart_cleaner_available = False
        if self.cp.has_section("smart_cleaner"):
            if self.cp.has_option("smart_cleaner", "smart_cleaner_options"):
                self.smart_cleaner_options = self.cp.get("smart_cleaner", "smart_cleaner_options").split(' ')

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

                    awake_incertitude_factor = self.getvaluedefaulted(section, 'awake_incertitude_factor', .2, 'float')
                    if awake_incertitude_factor > .5:
                        log.warning("in %s, awake_incertitude_factor greater than .5, setting it to .5" % (section))
                        awake_incertitude_factor = .5
                    if awake_incertitude_factor < 0:
                        log.warning("in %s, awake_incertitude_factor lower than 0, setting it to 0" % (section))
                        awake_incertitude_factor = 0
                    awake_time = self.getvaluedefaulted(section, 'awake_time', 600, 'int')
                    if awake_time < 60:
                        log.warning("in %s, awake_time lower than 60, setting it to 60" % (section))
                        awake_time = 60

                    self.schedulers[section] = {
                        'host' : self.getvaluedefaulted(section, 'host', '127.0.0.1'),
                        'port' : self.getvaluedefaulted(section, 'port', "8000"),
                        'username' : username,
                        'password' : password,
                        'enablessl' : self.getvaluedefaulted(section, 'enablessl', True, 'bool'),
                        'awake_time' : awake_time,
                        'awake_incertitude_factor' : awake_incertitude_factor,
                        'defer_results' : self.getvaluedefaulted(section, 'defer_results', False, 'bool')
                    }
                    if self.first_scheduler == None:
                        self.first_scheduler = section
                except ConfigParser.NoOptionError, error:
                    log.warn("launcher %s: section %s do not seems to be correct (%s), please fix the configuration file" % (self.name, section, error))
Exemplo n.º 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' : '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})
Exemplo n.º 6
0
    def setup(self, config_file):
        self.config_file = config_file
        if self.cp == None:
            # Load configuration file
            if sys.platform != "win32":
                self.cp = Pulse2ConfigParser()
            else:
                self.cp = ConfigParser.ConfigParser()
            self.cp.read(config_file)
            self.cp.read(config_file + '.local')

        if self.cp.has_option("main",
                              "bind"):  # TODO remove in a future version
            logging.getLogger().warning(
                "'bind' is obsolete, please replace it in your config file by 'host'"
            )
            self.bind = self.cp.get("main", 'bind')
        elif self.cp.has_option('main', 'host'):
            self.bind = self.cp.get("main", 'host')
        if self.cp.has_option('main', 'port'):
            self.port = self.cp.getint("main", 'port')
        if self.cp.has_option('main', 'public_ip'):
            self.public_ip = self.cp.get("main", 'public_ip')
        else:
            self.public_ip = self.bind

        if sys.platform != "win32":
            if self.cp.has_section('daemon'):
                if self.cp.has_option('daemon', 'pidfile'):
                    self.pid_path = self.cp.get('daemon', 'pidfile')
                if self.cp.has_option("daemon", "user"):
                    self.daemon_user = pwd.getpwnam(
                        self.cp.get("daemon", "user"))[2]
                if self.cp.has_option("daemon", "group"):
                    self.daemon_group = grp.getgrnam(
                        self.cp.get("daemon", "group"))[2]
                if self.cp.has_option("daemon", "umask"):
                    self.umask = int(self.cp.get("daemon", "umask"), 8)

        if sys.platform == "win32":
            if self.cp.has_option("main", "use_iocp_reactor"):
                self.use_iocp_reactor = self.cp.getboolean(
                    "main", "use_iocp_reactor")

        if self.cp.has_option('ssl', 'username'):
            self.username = self.cp.get('ssl', 'username')
            if sys.platform != "win32":
                self.password = self.cp.getpassword('ssl', 'password')
            else:
                self.password = self.cp.get('ssl', 'password')
            if not isTwistedEnoughForLoginPass():
                if self.username:
                    logging.getLogger().warn(
                        "your version of twisted is not high enough to use login (ssl/username)"
                    )
                    self.username = ''
                if self.password != '':
                    logging.getLogger().warning(
                        "your version of twisted is not high enough to use password (ssl/password)"
                    )
                    self.password = ''

        if self.cp.has_option('ssl', 'enablessl'):
            self.enablessl = self.cp.getboolean('ssl', 'enablessl')
        if self.enablessl:
            self.proto = 'https'
            if self.cp.has_option('ssl', 'certfile'):
                self.cacert = self.cp.get('ssl', 'certfile')
            if self.cp.has_option('ssl', 'cacert'):
                self.cacert = self.cp.get('ssl', 'cacert')
            if self.cp.has_option('ssl', 'privkey'):
                self.localcert = self.cp.get('ssl', 'privkey')
            if self.cp.has_option('ssl', 'localcert'):
                self.localcert = self.cp.get('ssl', 'localcert')
            if self.cp.has_option('ssl', 'verifypeer'):
                self.verifypeer = self.cp.getboolean('ssl', 'verifypeer')
            if not os.path.isfile(self.localcert):
                raise Exception('can\'t read SSL key "%s"' % (self.localcert))
                return False
            if not os.path.isfile(self.cacert):
                raise Exception('can\'t read SSL certificate "%s"' %
                                (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(
                        'I need at least Python Twisted 2.5 to handle peer checking'
                    )
                    return False

        if self.cp.has_section('mirror_api'):
            self.mirror_api['mount_point'] = '/rpc'
            if self.cp.has_option('mirror_api', 'mount_point'):
                self.mirror_api['mount_point'] = self.cp.get(
                    'mirror_api', 'mount_point')

        if self.cp.has_section('user_packageapi_api'):
            self.user_package_api['mount_point'] = '/upaa'
            if self.cp.has_option('user_packageapi_api', 'mount_point'):
                self.user_package_api['mount_point'] = self.cp.get(
                    'user_packageapi_api', 'mount_point')

        if self.cp.has_section('scheduler_api'):
            self.scheduler_api['mount_point'] = '/scheduler_api'
            self.scheduler_api['schedulers'] = 'scheduler_01'
            if self.cp.has_option('scheduler_api', 'mount_point'):
                self.scheduler_api['mount_point'] = self.cp.get(
                    'scheduler_api', 'mount_point')
            if self.cp.has_option('scheduler_api', 'schedulers'):
                self.scheduler_api['schedulers'] = self.cp.get(
                    'scheduler_api', 'schedulers')

        if self.cp.has_option('main', 'tmp_input_dir'):
            self.tmp_input_dir = self.cp.get('main', 'tmp_input_dir')

        for section in self.cp.sections():
            if re.compile('^mirror:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                mirror = {'mount_point': mount_point, 'src': src}
                if self.cp.has_option(section, 'mirror'):
                    mirror['mirror'] = self.cp.get(section, 'mirror')
                self.mirrors.append(mirror)
            if re.compile('^package_api_get:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                self.package_api_get.append({
                    'mount_point': mount_point,
                    'src': src
                })
            if re.compile('^package_api_put:[0-9]+$').match(section):
                mount_point = self.cp.get(section, 'mount_point')
                src = self.cp.get(section, 'src')
                pap_tmp_input_dir = self.tmp_input_dir
                if self.cp.has_option(section, 'tmp_input_dir'):
                    self.package_detect_activate = True
                    self.package_detect_tmp_activate = True
                    pap_tmp_input_dir = self.cp.get(section, 'tmp_input_dir')

                self.package_api_put.append({
                    'mount_point': mount_point,
                    'src': src,
                    'tmp_input_dir': pap_tmp_input_dir
                })

        # [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/package-server/keys/cacert.pem",
                'localcert':
                mmcconfdir + "/pulse2/package-server/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

        # [imaging_api] section parsing
        if self.cp.has_section("imaging_api") and self.cp.has_option(
                "imaging_api", 'uuid'):
            # mount point
            imaging_mp = '/imaging_api'
            # base folder
            base_folder = '/var/lib/pulse2/imaging'
            # will contain the bootloader material (revoboot + splashscreen), served by tftp
            bootloader_folder = 'bootloader'
            # CDROM bootloader
            cdrom_bootloader = 'cdrom_boot'
            # Boot splash screen
            bootsplash_file = 'bootsplash.xpm'
            # will contain the boot menus, served by tftp
            bootmenus_folder = 'bootmenus'
            # will contain diskless stuff (kernel, initramfs, additional tools), served by tftp
            diskless_folder = 'diskless'
            # diskless kernel
            diskless_kernel = 'kernel'
            # diskless initrd
            diskless_initrd = 'initrd'
            # diskless initrd for CD-ROM
            diskless_initrdcd = 'initrdcd'
            # diskless memtest tool
            diskless_memtest = 'memtest'
            # diskless dban tool
            diskless_dban = 'dban'
            # will contain computer-related materials
            computers_folder = 'computers'
            # will contain inventories
            inventories_folder = 'inventories'
            # will contain masters, served by tftp
            masters_folder = 'masters'
            # will contain postinstall binaries
            postinst_folder = 'postinst'
            # will contain archived computer imaging data
            archives_folder = 'archives'
            # will contain generated ISO images
            isos_folder = '/var/lib/pulse2/imaging/isos'
            # tool used to generate ISO file
            isogen_tool = '/usr/bin/genisoimage'
            # will contain our UUID/MAC Addr cache
            uuid_cache_file = os.path.join(base_folder, 'uuid-cache.txt')
            # our UUID/MAC Addr cache lifetime
            uuid_cache_lifetime = 300
            # RPC replay file
            rpc_replay_file = os.path.join(base_folder, 'rpc-replay.pck')
            # RPC replay loop timer in seconds
            rpc_loop_timer = 60
            # RPC to replay at each loop
            rpc_count = 10
            # Interval in seconds between two RPCs
            rpc_interval = 2
            # Package Server UUID
            uuid = ""
            # listening on this port to communicate with PXE
            pxe_port = 1001
            # inventory host
            inventory_host = "127.0.0.1"
            # inventory port
            inventory_port = 9999
            # inventory SSL enable
            inventory_enablessl = False
            # on glpi, PXE register by minimal inventory
            glpi_mode = False
            # identification on PXE console

            if self.cp.has_option("imaging_api", 'mount_point'):
                imaging_mp = self.cp.get("imaging_api", 'mount_point')
            if self.cp.has_option('imaging_api', 'base_folder'):
                base_folder = self.cp.get('imaging_api', 'base_folder')
            if self.cp.has_option('imaging_api', 'bootloader_folder'):
                bootloader_folder = self.cp.get('imaging_api',
                                                'bootloader_folder')
            if self.cp.has_option('imaging_api', 'cdrom_bootloader'):
                cdrom_bootloader = self.cp.get('imaging_api',
                                               'cdrom_bootloader')
            if self.cp.has_option('imaging_api', 'bootsplash_file'):
                bootsplash_file = self.cp.get('imaging_api',
                                              'bootlsplash_file')
            if self.cp.has_option('imaging_api', 'bootmenus_folder'):
                bootmenus_folder = self.cp.get('imaging_api',
                                               'bootmenus_folder')
            if self.cp.has_option('imaging_api', 'diskless_folder'):
                diskless_folder = self.cp.get('imaging_api', 'diskless_folder')
            if self.cp.has_option("imaging_api", 'diskless_kernel'):
                diskless_kernel = self.cp.get("imaging_api", 'diskless_kernel')
            if self.cp.has_option("imaging_api", 'diskless_initrd'):
                diskless_initrd = self.cp.get("imaging_api", 'diskless_initrd')
            if self.cp.has_option('imaging_api', 'diskless_initrdcd'):
                diskless_initrdcd = self.cp.get("imaging_api",
                                                'diskless_initrdcd')
            if self.cp.has_option("imaging_api", 'diskless_memtest'):
                diskless_memtest = self.cp.get("imaging_api",
                                               'diskless_memtest')
            if self.cp.has_option("imaging_api", 'diskless_dban'):
                diskless_dban = self.cp.get("imaging_api", 'diskless_dban')
            if self.cp.has_option('imaging_api', 'computers_folder'):
                computers_folder = self.cp.get('imaging_api',
                                               'computers_folder')
            if self.cp.has_option('imaging_api', 'inventories_folder'):
                inventories_folder = self.cp.get('imaging_api',
                                                 'inventories_folder')
            if self.cp.has_option('imaging_api', 'masters_folder'):
                masters_folder = self.cp.get('imaging_api', 'masters_folder')
            if self.cp.has_option('imaging_api', 'postinst_folder'):
                postinst_folder = self.cp.get('imaging_api', 'postinst_folder')
            if self.cp.has_option('imaging_api', 'archives_folder'):
                archives_folder = self.cp.get('imaging_api', 'archives_folder')
            if self.cp.has_option('imaging_api', 'isos_folder'):
                isos_folder = self.cp.get('imaging_api', 'isos_folder')
            if self.cp.has_option('imaging_api', 'isogen_tool'):
                isogen_tool = self.cp.get('imaging_api', 'isogen_tool')
            if self.cp.has_option('imaging_api', 'uuid_cache_file'):
                uuid_cache_file = os.path.join(
                    base_folder, self.cp.get('imaging_api', 'uuid_cache_file'))
            if self.cp.has_option('imaging_api', 'uuid_cache_lifetime'):
                uuid_cache_lifetime = self.cp.getint('imaging_api',
                                                     'uuid_cache_lifetime')
            if self.cp.has_option('imaging_api', 'rpc_replay_file'):
                rpc_replay_file = os.path.join(
                    base_folder, self.cp.get('imaging_api', 'rpc_replay_file'))
            if self.cp.has_option('imaging_api', 'rpc_loop_timer'):
                rpc_loop_timer = self.cp.getint('imaging_api',
                                                'rpc_loop_timer')
            if self.cp.has_option('imaging_api', 'rpc_count'):
                rpc_count = self.cp.getint('imaging_api', 'rpc_count')
            if self.cp.has_option('imaging_api', 'rpc_interval'):
                rpc_interval = self.cp.getint('imaging_api', 'rpc_interval')
            if self.cp.has_option("imaging_api", 'uuid'):
                uuid = self.cp.get("imaging_api", 'uuid')
            if self.cp.has_option("imaging_api", 'glpi_mode'):
                glpi_mode = self.cp.get("imaging_api", 'glpi_mode')
            if self.cp.has_option("imaging_api", 'pxe_port'):
                pxe_port = self.cp.get("imaging_api", 'pxe_port')
            if self.cp.has_option("imaging_api", 'inventory_host'):
                inventory_host = self.cp.get("imaging_api", 'inventory_host')
            if self.cp.has_option("imaging_api", 'inventory_port'):
                inventory_port = self.cp.get("imaging_api", 'inventory_port')
            if self.cp.has_option("imaging_api", 'inventory_enablessl'):
                inventory_enablessl = self.cp.get("imaging_api",
                                                  'inventory_enablessl')
            if not isUUID(uuid):
                raise TypeError(
                    "'%s' is not an valid UUID : in my config file, section [imaging_api], set a correct uuid."
                    % uuid)

            self.imaging_api = {
                'mount_point': imaging_mp,
                'base_folder': base_folder,
                'bootloader_folder': bootloader_folder,
                'bootsplash_file': bootsplash_file,
                'bootmenus_folder': bootmenus_folder,
                'cdrom_bootloader': cdrom_bootloader,
                'diskless_folder': diskless_folder,
                'diskless_kernel': diskless_kernel,
                'diskless_initrd': diskless_initrd,
                'diskless_initrdcd': diskless_initrdcd,
                'diskless_memtest': diskless_memtest,
                'diskless_dban': diskless_dban,
                'computers_folder': computers_folder,
                'inventories_folder': inventories_folder,
                'masters_folder': masters_folder,
                'postinst_folder': postinst_folder,
                'archives_folder': archives_folder,
                'isos_folder': isos_folder,
                'isogen_tool': isogen_tool,
                'pxe_port': pxe_port,
                'inventory_host': inventory_host,
                'inventory_port': inventory_port,
                'inventory_enablessl': inventory_enablessl,
                'glpi_mode': glpi_mode,
                'uuid': uuid,
                'uuid_cache_file': uuid_cache_file,
                'uuid_cache_lifetime': uuid_cache_lifetime,
                'rpc_replay_file': rpc_replay_file,
                'rpc_loop_timer': rpc_loop_timer,
                'rpc_count': rpc_count,
                'rpc_interval': rpc_interval
            }

        if self.cp.has_option("main", "package_detect_activate"):
            # WARN this must overide the previously defined activate if it is in the config file
            self.package_detect_activate = self.cp.getboolean(
                "main", "package_detect_activate")
            if self.package_detect_activate and self.cp.has_option(
                    "main", "package_detect_loop"):
                self.package_detect_loop = self.cp.getint(
                    "main", "package_detect_loop")

            if self.cp.has_option("main", "package_detect_smart_method"):
                package_detect_smart_method = self.cp.get(
                    "main", "package_detect_smart_method")
                if package_detect_smart_method != 'none':
                    package_detect_smart_method = package_detect_smart_method.split(
                        ',')
                    self.package_detect_smart = True
                    if 'last_time_modification' in package_detect_smart_method:
                        self.package_detect_smart_method.append(
                            self.SMART_DETECT_LAST)
                    if 'check_in_loop' in package_detect_smart_method:
                        self.package_detect_smart_method.append(
                            self.SMART_DETECT_LOOP)
                    if 'check_size' in package_detect_smart_method:
                        self.package_detect_smart_method.append(
                            self.SMART_DETECT_SIZE)
                    else:
                        logging.getLogger().info(
                            "dont know the package_detect_smart_method '%s'")
                    if self.cp.has_option("main", "package_detect_smart_time"):
                        self.package_detect_smart_time = self.cp.getint(
                            "main", "package_detect_smart_time")
                else:
                    self.package_detect_smart = False

        if self.cp.has_option("main", "package_mirror_target"):
            self.package_mirror_target = self.cp.get(
                "main", "package_mirror_target").split(' ')
            if (type(self.package_mirror_target) == str and self.package_mirror_target != '') or \
                    (type(self.package_mirror_target) == list and len(self.package_mirror_target) == 1 and self.package_mirror_target[0] != '') or \
                    (type(self.package_mirror_target) == list and len(self.package_mirror_target) != 1):
                self.package_mirror_activate = True

                if self.cp.has_option("main", 'package_mirror_status_file'):
                    self.package_mirror_status_file = self.cp.get(
                        "main", 'package_mirror_status_file')
                if self.cp.has_option("main", 'package_mirror_loop'):
                    self.package_mirror_loop = self.cp.getint(
                        "main", 'package_mirror_loop')

                if self.cp.has_option("main", 'package_mirror_command'):
                    self.package_mirror_command = self.cp.get(
                        "main", 'package_mirror_command')
                if self.cp.has_option("main",
                                      'package_mirror_command_options'):
                    self.package_mirror_command_options = self.cp.get(
                        "main", 'package_mirror_command_options').split(' ')
                if self.cp.has_option(
                        "main", "package_mirror_command_options_ssh_options"):
                    self.package_mirror_command_options_ssh_options = self.cp.get(
                        "main",
                        'package_mirror_command_options_ssh_options').split(
                            ' ')
                if self.cp.has_option("main",
                                      'package_mirror_level0_command_options'):
                    self.package_mirror_level0_command_options = self.cp.get(
                        "main",
                        'package_mirror_level0_command_options').split(' ')

            if self.cp.has_option("main", "package_global_mirror_activate"):
                self.package_global_mirror_activate = self.cp.getboolean(
                    "main", "package_global_mirror_activate")
                if self.cp.has_option("main", "package_global_mirror_loop"):
                    self.package_global_mirror_loop = self.cp.getint(
                        "main", "package_global_mirror_loop")
                if self.cp.has_option("main",
                                      "package_global_mirror_command_options"):
                    self.package_global_mirror_command_options = self.cp.get(
                        "main",
                        "package_global_mirror_command_options").split(' ')

        if self.cp.has_option("main", "real_package_deletion"):
            self.real_package_deletion = self.cp.getboolean(
                "main", "real_package_deletion")
        if self.cp.has_option("main", "mm_assign_algo"):
            self.mm_assign_algo = self.cp.get("main", 'mm_assign_algo')
        if self.cp.has_option("main", "up_assign_algo"):
            self.up_assign_algo = self.cp.get("main", 'up_assign_algo')
Exemplo n.º 7
0
    def setup(self, conf_file):
        """
        Read the module configuration
        """
        self.disable = self.cp.getboolean("main", "disable")

        if self.cp.has_option("main", "check_db_enable"):
            self.check_db_enable = self.cp.getboolean("main",
                                                      "check_db_enable")
        if self.cp.has_option("main", "check_db_interval"):
            self.check_db_interval = self.cp.getint("main",
                                                    "check_db_interval")

        is_login_and_pass = isTwistedEnoughForLoginPass()

        # folders
        if self.cp.has_option("msc", "qactionspath"):
            self.qactionspath = self.cp.get("msc", "qactionspath")
        if self.cp.has_option("msc", "repopath"):
            self.repopath = self.cp.get("msc", "repopath")

        # IP address blacklists
        if self.cp.has_option("msc", "ignore_non_rfc2780"):
            self.ignore_non_rfc2780 = self.cp.getboolean(
                "msc", "ignore_non_rfc2780")
        if self.cp.has_option("msc", "ignore_non_rfc1918"):
            self.ignore_non_rfc1918 = self.cp.getboolean(
                "msc", "ignore_non_rfc1918")
        if self.cp.has_option("msc", "exclude_ipaddr"):
            self.exclude_ipaddr = self.cp.get("msc", "exclude_ipaddr")
        if self.cp.has_option("msc", "include_ipaddr"):
            self.include_ipaddr = self.cp.get("msc", "include_ipaddr")

        # Host name blacklists
        if self.cp.has_option("msc", "ignore_non_fqdn"):
            self.ignore_non_fqdn = self.cp.getboolean("msc", "ignore_non_fqdn")
        if self.cp.has_option("msc", "ignore_invalid_hostname"):
            self.ignore_invalid_hostname = self.cp.getboolean(
                "msc", "ignore_invalid_hostname")
        if self.cp.has_option("msc", "exclude_hostname"):
            self.exclude_hostname = self.cp.get("msc", "exclude_hostname")
        if self.cp.has_option("msc", "include_hostname"):
            self.include_hostname = self.cp.get("msc", "include_hostname")

        # MAC address blacklist
        if self.cp.has_option("msc", "wol_macaddr_blacklist"):
            self.wol_macaddr_blacklist = self.cp.get("msc",
                                                     "wol_macaddr_blacklist")

        # schedulers
        if self.cp.has_option("msc", "default_scheduler"):
            self.default_scheduler = self.cp.get("msc", "default_scheduler")

        # convergence_reschedule
        if self.cp.has_option("msc", "convergence_reschedule"):
            self.convergence_reschedule = self.cp.get(
                "msc", "convergence_reschedule")

        if self.cp.has_option("msc", "wu_command"):
            self.wu_command = self.cp.get("msc", "wu_command")

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

                self.schedulers[section] = {
                    'port': self.cp.get(section, "port"),
                    'host': self.cp.get(section, "host"),
                    'username': username,
                    'password': password,
                    'enablessl': self.cp.getboolean(section, "enablessl"),
                    'verifypeer': False
                }
                if self.schedulers[section]["enablessl"]:
                    if self.cp.has_option(section, "verifypeer"):
                        self.schedulers[section][
                            "verifypeer"] = self.cp.getboolean(
                                section, "verifypeer")
                    if self.cp.has_option(section, "cacert"):
                        self.schedulers[section]["cacert"] = self.cp.get(
                            section, "cacert")
                    if self.cp.has_option(section, "localcert"):
                        self.schedulers[section]["localcert"] = self.cp.get(
                            section, "localcert")
                    if "localcert" in self.schedulers[
                            section] and not os.path.isfile(
                                self.schedulers[section]["localcert"]):
                        raise Exception(
                            'can\'t read SSL key "%s"' %
                            (self.schedulers[section]["localcert"]))
                    if "cacert" in self.schedulers[
                            section] and not os.path.isfile(
                                self.schedulers[section]["cacert"]):
                        raise Exception('can\'t read SSL certificate "%s"' %
                                        (self.schedulers[section]["cacert"]))
                    if "verifypeer" in self.schedulers[
                            section] and self.schedulers[section]["verifypeer"]:
                        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'
                            )

        # some default web interface values
        if self.cp.has_option("web", "web_def_awake"):
            self.web_def_awake = self.cp.getint("web", "web_def_awake")
        if self.cp.has_option("web", "web_def_date_fmt"):
            self.web_def_date_fmt = self.cp.get("web", "web_def_date_fmt")
        if self.cp.has_option("web", "web_def_inventory"):
            self.web_def_inventory = self.cp.getint("web", "web_def_inventory")
        if self.cp.has_option("web", "web_def_reboot"):
            self.web_def_reboot = self.cp.getint("web", "web_def_reboot")
        if self.cp.has_option("web", "web_def_mode"):
            self.web_def_mode = self.cp.get("web", "web_def_mode")
        if self.cp.has_option("web", "web_force_mode"):
            self.web_force_mode = self.cp.getboolean("web", "web_force_mode")
        if self.cp.has_option("web", "web_def_maxbw"):
            self.web_def_maxbw = self.cp.get("web", "web_def_maxbw")
        if self.cp.has_option("web", "web_def_delay"):
            self.web_def_delay = self.cp.get("web", "web_def_delay")
        if self.cp.has_option("web", "web_def_attempts"):
            self.web_def_attempts = self.cp.get("web", "web_def_attempts")
        if self.cp.has_option("web", "web_show_reboot"):
            self.web_show_reboot = self.cp.getboolean("web", "web_show_reboot")
        if self.cp.has_option("web", "web_dlpath"):
            self.web_dlpath = []
            dlpaths = self.cp.get("web", "web_dlpath")
            for path in dlpaths.split(","):
                self.web_dlpath.append(path.strip())
            if not os.path.exists(self.download_directory_path):
                logging.getLogger().warn(
                    "Plugin MSC: directory %s does not exist, please create it"
                    % self.download_directory_path)

        if self.cp.has_option("web", "web_def_dlmaxbw"):
            self.web_def_dlmaxbw = self.cp.getint("web", "web_def_dlmaxbw")
        if self.cp.has_option("web", "web_def_deployment_intervals"):
            time_intervals = self.cp.get("web", "web_def_deployment_intervals")
            if time_intervals:
                self.web_def_deployment_intervals = time_intervals
            else:
                self.web_def_deployment_intervals = ""
                logging.getLogger().warn(
                    "Plugin MSC: Error parsing option web_def_deployment_intervals !"
                )
        if self.cp.has_option("web", "web_allow_local_proxy"):
            self.web_allow_local_proxy = self.cp.get("web",
                                                     "web_allow_local_proxy")
        if self.cp.has_option("web", "web_def_local_proxy_mode"):
            self.web_def_local_proxy_mode = self.cp.get(
                "web", "web_def_local_proxy_mode")
        if self.cp.has_option("web", "web_def_max_clients_per_proxy"):
            self.web_def_max_clients_per_proxy = self.cp.getint(
                "web", "web_def_max_clients_per_proxy")
        if self.cp.has_option("web", "web_def_proxy_number"):
            self.web_def_proxy_number = self.cp.getint("web",
                                                       "web_def_proxy_number")
        if self.cp.has_option("web", "web_def_proxy_selection_mode"):
            self.web_def_proxy_selection_mode = self.cp.get(
                "web", "web_def_proxy_selection_mode")
        if self.cp.has_option("web", "web_def_refresh_time"):
            self.web_def_refresh_time = self.cp.getint(
                "web", "web_def_refresh_time") * 1000
        if self.cp.has_option("web", "web_def_use_no_vnc"):
            self.web_def_use_no_vnc = self.cp.getint("web",
                                                     "web_def_use_no_vnc")
        if self.cp.has_option("web", "web_def_coh_life_time"):
            self.web_def_coh_life_time = self.cp.getint(
                "web", "web_def_coh_life_time")
        if self.cp.has_option("web", "web_def_attempts_per_day"):
            self.web_def_proxy_selection_mode = self.cp.get(
                "web", "web_def_attempts_per_day")

        # Allow to delete commands and bundles from audit
        if self.cp.has_option("web", "web_def_allow_delete"):
            self.web_def_allow_delete = self.cp.get("web",
                                                    "web_def_allow_delete")

        # VNC stuff
        if self.cp.has_option("web", "vnc_show_icon"):
            self.web_vnc_show_icon = self.cp.getboolean("web", "vnc_show_icon")
        if self.cp.has_option("web", "vnc_view_only"):
            self.web_vnc_view_only = self.cp.getboolean("web", "vnc_view_only")
        if self.cp.has_option("web", "vnc_network_connectivity"):
            self.web_vnc_network_connectivity = self.cp.get(
                "web", "vnc_network_connectivity")
        if self.cp.has_option("web", "vnc_allow_user_control"):
            self.web_vnc_allow_user_control = self.cp.getboolean(
                "web", "vnc_allow_user_control")
        if self.cp.has_option("web", "vnc_port"):
            self.web_vnc_port = self.cp.get("web", "vnc_port")

        if self.cp.has_option("web", "probe_order"):
            self.web_probe_order = self.cp.get("web", "probe_order")
        if self.cp.has_option("web", "probe_order_on_demand"):
            self.web_probe_order_on_demand = self.cp.get(
                "web", "probe_order_on_demand")
        if self.cp.has_option("web", "show_root_commands"):
            self.show_root_commands = self.cp.get("web", "show_root_commands")

        # API Package
        if self.cp.has_option("package_api", "mserver"):
            self.ma_server = self.cp.get("package_api", "mserver")
        if self.cp.has_option("package_api", "mport"):
            self.ma_port = self.cp.get("package_api", "mport")
        if self.cp.has_option("package_api", "mmountpoint"):
            self.ma_mountpoint = self.cp.get("package_api", "mmountpoint")
        if self.cp.has_option("package_api", "username"):
            if not is_login_and_pass:
                logging.getLogger().warning(
                    "your version of twisted is not high enough to use login (package_api/username)"
                )
                self.ma_username = ""
            else:
                self.ma_username = self.cp.get("package_api", "username")
        if self.cp.has_option("package_api", "password"):
            if not is_login_and_pass:
                logging.getLogger().warning(
                    "your version of twisted is not high enough to use password (package_api/password)"
                )
                self.ma_password = ""
            else:
                self.ma_password = self.cp.get("package_api", "password")
        if self.cp.has_option("package_api", "enablessl"):
            self.ma_enablessl = self.cp.getboolean("package_api", "enablessl")
        if self.ma_enablessl:
            if self.cp.has_option("package_api", "verifypeer"):
                self.ma_verifypeer = self.cp.getboolean(
                    "package_api", "verifypeer")
            if self.ma_verifypeer:  # we need twisted.internet.ssl.Certificate to activate certs
                if self.cp.has_option("package_api", "cacert"):
                    self.ma_cacert = self.cp.get("package_api", "cacert")
                if self.cp.has_option("package_api", "localcert"):
                    self.ma_localcert = self.cp.get("package_api", "localcert")
                if not os.path.isfile(self.ma_localcert):
                    raise Exception('can\'t read SSL key "%s"' %
                                    (self.ma_localcert))
                if not os.path.isfile(self.ma_cacert):
                    raise Exception('can\'t read SSL certificate "%s"' %
                                    (self.ma_cacert))
                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'
                    )

        # Scheduler API
        if self.cp.has_section("scheduler_api"):
            self.sa_enable = True
            if self.cp.has_option("scheduler_api", "host"):
                self.sa_server = self.cp.get("scheduler_api", "host")
            if self.cp.has_option("scheduler_api", "port"):
                self.sa_port = self.cp.get("scheduler_api", "port")
            if self.cp.has_option("scheduler_api", "mountpoint"):
                self.sa_mountpoint = self.cp.get("scheduler_api", "mountpoint")
            if self.cp.has_option("scheduler_api", "username"):
                if not is_login_and_pass:
                    logging.getLogger().warning(
                        "your version of twisted is not high enough to use login (scheduler_api/username)"
                    )
                    self.sa_username = ""
                else:
                    self.sa_username = self.cp.get("scheduler_api", "username")
            if self.cp.has_option("scheduler_api", "password"):
                if not is_login_and_pass:
                    logging.getLogger().warning(
                        "your version of twisted is not high enough to use password (scheduler_api/password)"
                    )
                    self.sa_password = ""
                else:
                    self.sa_password = self.cp.get("scheduler_api", "password")
            if self.cp.has_option("scheduler_api", "enablessl"):
                self.sa_enablessl = self.cp.getboolean("scheduler_api",
                                                       "enablessl")
            if self.sa_enablessl:
                if self.cp.has_option("scheduler_api", "verifypeer"):
                    self.sa_verifypeer = self.cp.getboolean(
                        "scheduler_api", "verifypeer")
                if self.sa_verifypeer:  # we need twisted.internet.ssl.Certificate to activate certs
                    if self.cp.has_option("scheduler_api", "cacert"):
                        self.sa_cacert = self.cp.get("scheduler_api", "cacert")
                    if self.cp.has_option("scheduler_api", "localcert"):
                        self.sa_localcert = self.cp.get(
                            "scheduler_api", "localcert")
                    if not os.path.isfile(self.sa_localcert):
                        raise Exception('can\'t read SSL key "%s"' %
                                        (self.sa_localcert))
                    if not os.path.isfile(self.sa_cacert):
                        raise Exception('can\'t read SSL certificate "%s"' %
                                        (self.sa_cacert))
                    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'
                        )

            self.scheduler_url2id = {}

            for id in self.schedulers:
                (url, credentials) = makeURL(self.schedulers[id])
                self.scheduler_url2id[url] = id
Exemplo n.º 8
0
    def setup(self, conf_file):
        """
        Read the module configuration
        """
        self.disable = self.cp.getboolean("main", "disable")

        is_login_and_pass = isTwistedEnoughForLoginPass()

        # folders
        if self.cp.has_option("msc", "qactionspath"):
            self.qactionspath = self.cp.get("msc", "qactionspath")
        if self.cp.has_option("msc", "repopath"):
            self.repopath = self.cp.get("msc", "repopath")

        # IP address blacklists
        if self.cp.has_option("msc", "ignore_non_rfc2780"):
            self.ignore_non_rfc2780 = self.cp.getboolean("msc", "ignore_non_rfc2780")
        if self.cp.has_option("msc", "ignore_non_rfc1918"):
            self.ignore_non_rfc1918 = self.cp.getboolean("msc", "ignore_non_rfc1918")
        if self.cp.has_option("msc", "exclude_ipaddr"):
            self.exclude_ipaddr = self.cp.get("msc", "exclude_ipaddr")
        if self.cp.has_option("msc", "include_ipaddr"):
            self.include_ipaddr = self.cp.get("msc", "include_ipaddr")

        # Host name blacklists
        if self.cp.has_option("msc", "ignore_non_fqdn"):
            self.ignore_non_fqdn = self.cp.getboolean("msc", "ignore_non_fqdn")
        if self.cp.has_option("msc", "ignore_invalid_hostname"):
            self.ignore_invalid_hostname = self.cp.getboolean("msc", "ignore_invalid_hostname")
        if self.cp.has_option("msc", "exclude_hostname"):
            self.exclude_hostname = self.cp.get("msc", "exclude_hostname")
        if self.cp.has_option("msc", "include_hostname"):
            self.include_hostname = self.cp.get("msc", "include_hostname")

        # MAC address blacklist
        if self.cp.has_option("msc", "wol_macaddr_blacklist"):
            self.wol_macaddr_blacklist = self.cp.get("msc", "wol_macaddr_blacklist")

        # schedulers
        if self.cp.has_option("msc", "default_scheduler"):
            self.default_scheduler = self.cp.get("msc", "default_scheduler")

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

                self.schedulers[section] = {
                        'port': self.cp.get(section, "port"),
                        'host': self.cp.get(section, "host"),
                        'username': username,
                        'password': password,
                        'enablessl': self.cp.getboolean(section, "enablessl"),
                        'verifypeer': False
                    }
                if self.schedulers[section]["enablessl"]:
                    if self.cp.has_option(section, "verifypeer"):
                        self.schedulers[section]["verifypeer"] = self.cp.getboolean(section, "verifypeer")
                    if self.cp.has_option(section, "cacert"):
                        self.schedulers[section]["cacert"] = self.cp.get(section, "cacert")
                    if self.cp.has_option(section, "localcert"):
                        self.schedulers[section]["localcert"] = self.cp.get(section, "localcert")
                    if "localcert" in self.schedulers[section] and not os.path.isfile(self.schedulers[section]["localcert"]):
                        raise Exception('can\'t read SSL key "%s"' % (self.schedulers[section]["localcert"]))
                    if "cacert" in self.schedulers[section] and not os.path.isfile(self.schedulers[section]["cacert"]):
                        raise Exception('can\'t read SSL certificate "%s"' % (self.schedulers[section]["cacert"]))
                    if "verifypeer" in self.schedulers[section] and self.schedulers[section]["verifypeer"]:
                        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')

        # some default web interface values
        if self.cp.has_option("web", "web_def_awake"):
            self.web_def_awake = self.cp.getint("web", "web_def_awake")
        if self.cp.has_option("web", "web_def_date_fmt"):
            self.web_def_date_fmt = self.cp.get("web", "web_def_date_fmt")
        if self.cp.has_option("web", "web_def_inventory"):
            self.web_def_inventory = self.cp.getint("web", "web_def_inventory")
        if self.cp.has_option("web", "web_def_mode"):
            self.web_def_mode = self.cp.get("web", "web_def_mode")
        if self.cp.has_option("web", "web_force_mode"):
            self.web_force_mode = self.cp.getboolean("web", "web_force_mode")
        if self.cp.has_option("web", "web_def_maxbw"):
            self.web_def_maxbw = self.cp.get("web", "web_def_maxbw")
        if self.cp.has_option("web", "web_def_delay"):
            self.web_def_delay = self.cp.get("web", "web_def_delay")
        if self.cp.has_option("web", "web_def_attempts"):
            self.web_def_attempts = self.cp.get("web", "web_def_attempts")
        if self.cp.has_option("web", "web_def_issue_halt_to"):
            self.web_def_issue_halt_to = []
            #p_wdiht = ['done', 'failed', 'over_time', 'out_of_interval']
            p_wdiht = ['done']
            for wdiht in self.cp.get("web", "web_def_issue_halt_to").split(','):
                if wdiht in p_wdiht:
                    self.web_def_issue_halt_to.append(wdiht)
                else:
                    logging.getLogger().warn("Plugin MSC: web_def_issue_halt_to cannot be '%s' (possible choices : %s)"%(wdiht, str(p_wdiht)))
        if self.cp.has_option("web", "web_show_reboot"):
            self.web_show_reboot = self.cp.getboolean("web", "web_show_reboot")
        if self.cp.has_option("web", "web_dlpath"):
            self.web_dlpath = []
            dlpaths = self.cp.get("web", "web_dlpath")
            for path in dlpaths.split(","):
                self.web_dlpath.append(path.strip())
            if not os.path.exists(self.download_directory_path):
                logging.getLogger().warn("Plugin MSC: directory %s does not exist, please create it" % self.download_directory_path)

        if self.cp.has_option("web", "web_def_dlmaxbw"):
            self.web_def_dlmaxbw = self.cp.getint("web", "web_def_dlmaxbw")
        if self.cp.has_option("web", "web_def_deployment_intervals"):
            time_intervals = pulse2.time_intervals.normalizeinterval(self.cp.get("web", "web_def_deployment_intervals"))
            if time_intervals:
                self.web_def_deployment_intervals = time_intervals
            else:
                self.web_def_deployment_intervals = ""
                logging.getLogger().warn("Plugin MSC: Error parsing option web_def_deployment_intervals !")
        if self.cp.has_option("web", "web_allow_local_proxy"):
            self.web_allow_local_proxy = self.cp.get("web", "web_allow_local_proxy")
        if self.cp.has_option("web", "web_def_local_proxy_mode"):
            self.web_def_local_proxy_mode = self.cp.get("web", "web_def_local_proxy_mode")
        if self.cp.has_option("web", "web_def_max_clients_per_proxy"):
            self.web_def_max_clients_per_proxy = self.cp.getint("web", "web_def_max_clients_per_proxy")
        if self.cp.has_option("web", "web_def_proxy_number"):
            self.web_def_proxy_number = self.cp.getint("web", "web_def_proxy_number")
        if self.cp.has_option("web", "web_def_proxy_selection_mode"):
            self.web_def_proxy_selection_mode = self.cp.get("web", "web_def_proxy_selection_mode")

        # VNC stuff
        if self.cp.has_option("web", "vnc_show_icon"):
            self.web_vnc_show_icon = self.cp.getboolean("web", "vnc_show_icon")
        if self.cp.has_option("web", "vnc_view_only"):
            self.web_vnc_view_only = self.cp.getboolean("web", "vnc_view_only")
        if self.cp.has_option("web", "vnc_network_connectivity"):
            self.web_vnc_network_connectivity = self.cp.get("web", "vnc_network_connectivity")
        if self.cp.has_option("web", "vnc_allow_user_control"):
            self.web_vnc_allow_user_control = self.cp.getboolean("web", "vnc_allow_user_control")
        if self.cp.has_option("web", "vnc_port"):
            self.web_vnc_port = self.cp.get("web", "vnc_port")

        if self.cp.has_option("web", "probe_order"):
            self.web_probe_order = self.cp.get("web", "probe_order")

        # API Package
        if self.cp.has_option("package_api", "mserver"):
            self.ma_server = self.cp.get("package_api", "mserver")
        if self.cp.has_option("package_api", "mport"):
            self.ma_port = self.cp.get("package_api", "mport")
        if self.cp.has_option("package_api", "mmountpoint"):
            self.ma_mountpoint = self.cp.get("package_api", "mmountpoint")
        if self.cp.has_option("package_api", "username"):
            if not is_login_and_pass:
                logging.getLogger().warning("your version of twisted is not high enough to use login (package_api/username)")
                self.ma_username = ""
            else:
                self.ma_username = self.cp.get("package_api", "username")
        if self.cp.has_option("package_api", "password"):
            if not is_login_and_pass:
                logging.getLogger().warning("your version of twisted is not high enough to use password (package_api/password)")
                self.ma_password = ""
            else:
                self.ma_password = self.cp.get("package_api", "password")
        if self.cp.has_option("package_api", "enablessl"):
            self.ma_enablessl = self.cp.getboolean("package_api", "enablessl")
        if self.ma_enablessl:
            if self.cp.has_option("package_api", "verifypeer"):
                self.ma_verifypeer = self.cp.getboolean("package_api", "verifypeer")
            if self.ma_verifypeer: # we need twisted.internet.ssl.Certificate to activate certs
                if self.cp.has_option("package_api", "cacert"):
                    self.ma_cacert = self.cp.get("package_api", "cacert")
                if self.cp.has_option("package_api", "localcert"):
                    self.ma_localcert = self.cp.get("package_api", "localcert")
                if not os.path.isfile(self.ma_localcert):
                    raise Exception('can\'t read SSL key "%s"' % (self.ma_localcert))
                if not os.path.isfile(self.ma_cacert):
                    raise Exception('can\'t read SSL certificate "%s"' % (self.ma_cacert))
                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')

        # Scheduler API
        if self.cp.has_section("scheduler_api"):
            self.sa_enable = True
            if self.cp.has_option("scheduler_api", "host"):
                self.sa_server = self.cp.get("scheduler_api", "host")
            if self.cp.has_option("scheduler_api", "port"):
                self.sa_port = self.cp.get("scheduler_api", "port")
            if self.cp.has_option("scheduler_api", "mountpoint"):
                self.sa_mountpoint = self.cp.get("scheduler_api", "mountpoint")
            if self.cp.has_option("scheduler_api", "username"):
                if not is_login_and_pass:
                    logging.getLogger().warning("your version of twisted is not high enough to use login (scheduler_api/username)")
                    self.sa_username = ""
                else:
                    self.sa_username = self.cp.get("scheduler_api", "username")
            if self.cp.has_option("scheduler_api", "password"):
                if not is_login_and_pass:
                    logging.getLogger().warning("your version of twisted is not high enough to use password (scheduler_api/password)")
                    self.sa_password = ""
                else:
                    self.sa_password = self.cp.get("scheduler_api", "password")
            if self.cp.has_option("scheduler_api", "enablessl"):
                self.sa_enablessl = self.cp.getboolean("scheduler_api", "enablessl")
            if self.sa_enablessl:
                if self.cp.has_option("scheduler_api", "verifypeer"):
                    self.sa_verifypeer = self.cp.getboolean("scheduler_api", "verifypeer")
                if self.sa_verifypeer: # we need twisted.internet.ssl.Certificate to activate certs
                    if self.cp.has_option("scheduler_api", "cacert"):
                        self.sa_cacert = self.cp.get("scheduler_api", "cacert")
                    if self.cp.has_option("scheduler_api", "localcert"):
                        self.sa_localcert = self.cp.get("scheduler_api", "localcert")
                    if not os.path.isfile(self.sa_localcert):
                        raise Exception('can\'t read SSL key "%s"' % (self.sa_localcert))
                    if not os.path.isfile(self.sa_cacert):
                        raise Exception('can\'t read SSL certificate "%s"' % (self.sa_cacert))
                    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')

            self.scheduler_url2id = {}

            for id in self.schedulers:
                (url, credentials) = makeURL(self.schedulers[id])
                self.scheduler_url2id[url] = id
Exemplo n.º 9
0
class LauncherConfig(pulse2.utils.Singleton):
    """
    Singleton Class to hold configuration directives

    """
    name = None
    cp = None

    # launchers section
    halt_command = "/bin/shutdown.exe -f -s 1 || shutdown -h now"
    inventory_command = '''export P2SRV=`echo $SSH_CONNECTION | cut -f1 -d\ `; export P2PORT=9999; export http_proxy=""; export ftp_proxy=""; ( [ -x /cygdrive/c/Program\ Files/FusionInventory-Agent/uninstFI.exe ] && /cygdrive/c/Program\ Files/FusionInventory-Agent/perl/bin/perl "C:\Program Files\FusionInventory-Agent\perl\\bin\\fusioninventory-agent" /server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /cygdrive/c/Program\ Files\ \(x86\)/FusionInventory-Agent/uninstFI.exe ] && /cygdrive/c/Program\ Files\ \(x86\)/FusionInventory-Agent/perl/bin/perl "C:\Program Files (x86)\FusionInventory-Agent\perl\\bin\\fusioninventory-agent" /server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /cygdrive/c/Program\ Files/FusionInventory-Agent/fusioninventory-agent.bat ] && /cygdrive/c/Program\ Files/FusionInventory-Agent/fusioninventory-agent.bat /server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /cygdrive/c/Program\ Files\ \(x86\)/FusionInventory-Agent/fusioninventory-agent.bat ] && /cygdrive/c/Program\ Files\ \(x86\)/FusionInventory-Agent/fusioninventory-agent.bat /server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /cygdrive/c/Program\ Files/OCS\ Inventory\ Agent/OCSInventory.exe ] && /cygdrive/c/Program\ Files/OCS\ Inventory\ Agent/OCSInventory.exe /np /server:$P2SRV /pnum:$P2PORT 2> /dev/null ) || ( [ -x /cygdrive/c/Program\ Files\ \(x86\)/OCS\ Inventory\ Agent/OCSInventory.exe ] && /cygdrive/c/Program\ Files\ \(x86\)/OCS\ Inventory\ Agent/OCSInventory.exe /np /server:$P2SRV /pnum:$P2PORT 2> /dev/null ) || ( [ -x /usr/bin/ocsinventory-agent ] && /usr/bin/ocsinventory-agent --server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /usr/sbin/ocsinventory-agent ] && /usr/sbin/ocsinventory-agent --server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /usr/local/sbin/ocs_mac_agent.php ] && /usr/local/sbin/ocs_mac_agent.php 2> /dev/null ) || ( [ -x /usr/local/bin/fusioninventory-agent ] && /usr/local/bin/fusioninventory-agent --server=http://$P2SRV:$P2PORT 2> /dev/null ) || ( [ -x /usr/bin/fusioninventory-agent ] && /usr/bin/fusioninventory-agent --server=http://$P2SRV:$P2PORT 2> /dev/null )  || ( [ -x /opt/fusioninventory-agent/fusioninventory-agent ] && /opt/fusioninventory-agent/fusioninventory-agent --server=http://$P2SRV:$P2PORT 2> /dev/null )'''
    launcher_path = "/usr/sbin/pulse2-launcher"
    max_command_age = 86400
    max_ping_time = 4
    max_probe_time = 20
    ping_path = "/usr/sbin/pulse2-ping"
    reboot_command = "/bin/shutdown.exe -f -r 1 || shutdown -r now"
    source_path = "/var/lib/pulse2/packages"
    target_path = "/tmp"
    temp_folder_prefix = "MDVPLS"

    # [daemon] section
    daemon_group = 0
    pid_path = "/var/run/pulse2"
    umask = 0077
    daemon_user = 0

    # wrapper stuff
    wrapper_max_exec_time = 21600
    wrapper_max_log_size = 512000
    wrapper_path = "/usr/sbin/pulse2-output-wrapper"

    # ssh stuff
    scp_path_default = scp_path = "/usr/bin/scp"
    ssh_agent_path_default = ssh_agent_path = "/usr/bin/ssh-agent"
    ssh_agent_sock = None
    ssh_agent_pid = None
    ssh_defaultkey = 'default'
    ssh_forward_key = 'let'
    ssh_keys = {
        'default': '/root/.ssh/id_rsa'
    }
    ssh_options = [ \
        'LogLevel=ERROR',
        'UserKnownHostsFile=/dev/null',
        'StrictHostKeyChecking=no',
        'Batchmode=yes',
        'PasswordAuthentication=no',
        'ServerAliveInterval=10',
        'CheckHostIP=no',
        'ConnectTimeout=10'
    ]
    ssh_path_default = ssh_path = "/usr/bin/ssh"

    # wget stuff
    wget_path_default = wget_path = '/usr/bin/wget'
    wget_options = ''
    wget_check_certs = False
    wget_resume = True

    # rsync stuff
    rsync_path_default = rsync_path = '/usr/bin/rsync'
    rsync_resume = True
    rsync_set_executable = 'yes'
    rsync_set_access = 'private'

    # WOL stuff
    wol_bcast = '255.255.255.255'
    wol_path = '/usr/sbin/pulse2-wol'
    wol_port = '40000'

    # SSH Proxy stuff
    tcp_sproxy_path = '/usr/sbin/pulse2-tcp-sproxy'
    tcp_sproxy_host = None
    tcp_sproxy_check = False
    tcp_sproxy_port_range_start = 8100
    tcp_sproxy_port_range_end = 8200
    tcp_sproxy_establish_delay = 60
    tcp_sproxy_connect_delay = 120
    tcp_sproxy_session_lenght = 3600

    # Create or not a web_proxy (to use with noVNC)
    create_web_proxy = True

    # Smart Cleaner Stuff
    is_smart_cleaner_available = True
    smart_cleaner_path = "/usr/bin/pulse2-smart-cleaner.sh"
    smart_cleaner_options = []

    # scheduler stuff
    first_scheduler = None
    schedulers = {
    }

    # [launcher_xxx] section
    launchers = {
    }

    ## initialize additionnal vars ##

    # base idea: rsync is NOT available
    is_rsync_available = False
    is_rsync_limited = True

    def setoption(self, section, key, attrib, type = 'str'):
        if type == 'str':
            if self.cp.has_option(section, key):
                setattr(self, attrib, self.cp.get(section, key))
                log.debug("launcher %s: section %s, option %s set to '%s'" % (self.name, section, key, getattr(self, attrib)))
            else:
                log.debug("launcher %s: section %s, option %s not set, using default value '%s'" % (self.name, section, key, getattr(self, attrib)))
        elif type == 'bool':
            if self.cp.has_option(section, key):
                setattr(self, attrib, self.cp.getboolean(section, key))
                log.debug("launcher %s: section %s, option %s set to %s" % (self.name, section, key, getattr(self, attrib)))
            else:
                log.debug("launcher %s: section %s, option %s not set, using default value %s" % (self.name, section, key, getattr(self, attrib)))
        elif type == 'int':
            if self.cp.has_option(section, key):
                setattr(self, attrib, self.cp.getint(section, key))
                log.debug("launcher %s: section %s, option %s set to %s" % (self.name, section, key, getattr(self, attrib)))
            else:
                log.debug("launcher %s: section %s, option %s not set, using default value %s" % (self.name, section, key, getattr(self, attrib)))
        elif type == 'pass':
            if self.cp.has_option(section, key):
                setattr(self, attrib, self.cp.getpassword(section, key))
                log.debug("launcher %s: section %s, option %s set using given value" % (self.name, section, key))
            else:
                log.debug("launcher %s: section %s, option %s not set, using default value" % (self.name, section, key))

    def presetup(self, config_file):
        """
            used to pre-parse conf file to gather enough data to setuid() soon
        """
        self.cp = pulse2.utils.Pulse2ConfigParser()
        self.cp.read(config_file)
        self.cp.read(config_file + '.local')

        if self.cp.has_option("daemon", "user"):
            self.daemon_user = pwd.getpwnam(self.cp.get("daemon", "user"))[2]
        if self.cp.has_option("daemon", "group"):
            self.daemon_group = grp.getgrnam(self.cp.get("daemon", "group"))[2]
        if self.cp.has_option("daemon", "umask"):
            self.umask = string.atoi(self.cp.get("daemon", "umask"), 8)
        if self.cp.has_option("handler_hand01", "args"):
            self.logdir = os.path.dirname(re.compile("['|\"]").split(self.cp.get("handler_hand01", "args"))[1])

    def setup(self, config_file, name = None):
        # Load configuration file
        if not self.cp: # self.cp is set if presetup() was already called
            self.presetup(config_file)

        self.name = name

        # Parse "launchers" section
        self.setoption('launchers', 'inventory_command', 'inventory_command')
        self.setoption('launchers', 'launcher_path', 'launcher_path')
        self.setoption('launchers', 'max_command_age', 'max_command_age', 'int')
        self.setoption('launchers', 'max_ping_time', 'max_ping_time', 'int')
        self.setoption('launchers', 'max_probe_time', 'max_probe_time', 'int')
        self.setoption('launchers', 'ping_path', 'ping_path')
        self.setoption('launchers', 'source_path', 'source_path')
        self.setoption('launchers', 'reboot_command', 'reboot_command')
        self.setoption('launchers', 'halt_command', 'halt_command')
        self.setoption('launchers', 'target_path', 'target_path')
        self.setoption('launchers', 'temp_folder_prefix', 'temp_folder_prefix')

        # Parse "wrapper" section
        self.setoption('wrapper', 'max_log_size', 'wrapper_max_log_size', 'int')
        self.setoption('wrapper', 'max_exec_time', 'wrapper_max_exec_time', 'int')
        self.setoption('wrapper', 'path', 'wrapper_path')

        # Parse "wget" section
        self.setoption('wget', 'wget_path', 'wget_path')
        if self.cp.has_section("wget"):
            if self.cp.has_option("wget", "wget_options"):
                self.wget_options = self.cp.get("wget", "wget_options").split(' ')
        self.setoption('wget', 'check_certs', 'wget_check_certs', 'bool')
        self.setoption('wget', 'resume', 'wget_resume', 'bool')

        # Parse a part of "ssh" section
        self.setoption('ssh', 'ssh_path', 'ssh_path')
        self.setoption('ssh', 'scp_path', 'scp_path')
        self.setoption('ssh', 'ssh_agent_path', 'ssh_agent_path')

        # Parse "rsync" section
        self.setoption('rsync', 'rsync_path', 'rsync_path')
        self.setoption('rsync', 'resume', 'rsync_resume', 'bool')
        self.setoption('rsync', 'set_executable', 'rsync_set_executable')
        if not self.rsync_set_executable in ('yes', 'no', 'keep'):
            self.logger.warning("set_executable can have '%s' for value (yes|no|keep)"%(self.rsync_set_executable))
            self.rsync_set_executable = 'yes'
        self.setoption('rsync', 'set_access', 'rsync_set_access')
        if not self.rsync_set_access in ('private', 'restricted', 'public'):
            self.logger.warning("set_access can have '%s' for value (private|restricted|public)"%(self.rsync_set_access))
            self.rsync_set_access = 'private'

        # +----------------+------------------+---------------------+------------------+
        # | set_executable |                  |                     |                  |
        # +--------------\ |       yes        |         no          |        keep      |
        # | set_access    \|                  |                     |                  |
        # +----------------+------------------+---------------------+------------------+
        # | private        | u=rwx,g=,o=  (1) | u=rw,g=,o=          | u=rwX,g=,o=      |
        # +----------------+------------------+---------------------+------------------+
        # | restricted     | u=rwx,g=rx,o=    | u=rw,g=r,o=         | u=rwX,g=rX,o=    |
        # +----------------+------------------+---------------------+------------------+
        # | public         | u=rwx,g=rwx,o=rx | u=rw,g=rw,o=r       | u=rwX,g=rwX,o=rX |
        # +----------------+------------------+---------------------+------------------+
        # (1) : default value
        exe = 'X'
        if self.rsync_set_executable == 'yes':
            exe = 'x'
        elif self.rsync_set_executable == 'no':
            exe = ''

        other = ',o='
        group = ',g='
        if self.rsync_set_access == 'public':
            other += "r%s"%(exe)
            group += "rw%s"%(exe)
        elif self.rsync_set_access == 'restricted':
            group += "r%s"%(exe)
        self.rsync_set_chmod = 'u=rw%s%s%s'%(exe, group, other)

        log.debug("config metavalue 'rsync_set_chmod' = %s"%(self.rsync_set_chmod))

        # [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')

        # Parse "wol" section
        self.setoption('wol', 'wol_bcast', 'wol_bcast')
        self.setoption('wol', 'wol_path', 'wol_path')
        self.setoption('wol', 'wol_port', 'wol_port')

        # Parse "tcp_sproxy" section
        self.setoption('tcp_sproxy', 'tcp_sproxy_path', 'tcp_sproxy_path')
        self.setoption('tcp_sproxy', 'tcp_sproxy_host', 'tcp_sproxy_host')
        self.setoption('tcp_sproxy', 'tcp_sproxy_check', 'tcp_sproxy_check', 'bool')
        self.setoption('tcp_sproxy', 'tcp_sproxy_establish_delay', 'tcp_sproxy_establish_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_connect_delay', 'tcp_sproxy_connect_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_session_lenght', 'tcp_sproxy_session_lenght', 'int')
        self.setoption('tcp_sproxy', 'create_web_proxy', 'create_web_proxy', 'bool')
        if self.cp.has_section("tcp_sproxy"):
            if self.cp.has_option("tcp_sproxy", "tcp_sproxy_port_range"):
                range = map(lambda x: int(x), self.cp.get("tcp_sproxy", "tcp_sproxy_port_range").split('-'))
                if len(range) != 2:
                    log.info("'tcp_sproxy_port_range' not formated as expected, using default value, please check your config file ")
                else:
                    (self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end) = range
        log.info("launcher %s: section %s, option %s set to %d-%d" % (self.name, 'tcp_sproxy', 'tcp_sproxy_port_range', self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end))

        # Parse "smart_cleaner" section
        self.setoption('smart_cleaner', 'smart_cleaner_path', 'smart_cleaner_path')
        if self.smart_cleaner_path == '':
            LauncherConfig().is_smart_cleaner_available = False
        if self.cp.has_section("smart_cleaner"):
            if self.cp.has_option("smart_cleaner", "smart_cleaner_options"):
                self.smart_cleaner_options = self.cp.get("smart_cleaner", "smart_cleaner_options").split(' ')

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

                    awake_incertitude_factor = self.getvaluedefaulted(section, 'awake_incertitude_factor', .2, 'float')
                    if awake_incertitude_factor > .5:
                        log.warning("in %s, awake_incertitude_factor greater than .5, setting it to .5" % (section))
                        awake_incertitude_factor = .5
                    if awake_incertitude_factor < 0:
                        log.warning("in %s, awake_incertitude_factor lower than 0, setting it to 0" % (section))
                        awake_incertitude_factor = 0
                    awake_time = self.getvaluedefaulted(section, 'awake_time', 600, 'int')
                    if awake_time < 60:
                        log.warning("in %s, awake_time lower than 60, setting it to 60" % (section))
                        awake_time = 60

                    self.schedulers[section] = {
                        'host' : self.getvaluedefaulted(section, 'host', '127.0.0.1'),
                        'port' : self.getvaluedefaulted(section, 'port', "8000"),
                        'username' : username,
                        'password' : password,
                        'enablessl' : self.getvaluedefaulted(section, 'enablessl', True, 'bool'),
                        'awake_time' : awake_time,
                        'awake_incertitude_factor' : awake_incertitude_factor,
                        'defer_results' : self.getvaluedefaulted(section, 'defer_results', False, 'bool')
                    }
                    if self.first_scheduler == None:
                        self.first_scheduler = section
                except ConfigParser.NoOptionError, error:
                    log.warn("launcher %s: section %s do not seems to be correct (%s), please fix the configuration file" % (self.name, section, error))

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

                    self.launchers[section] = {
                            'bind': self.getvaluedefaulted(section, 'bind', '127.0.0.1'),
                            'port': self.cp.get(section, 'port'),
                            'username': username,
                            'password': password,
                            'enablessl': self.getvaluedefaulted(section, 'enablessl', True, 'bool'),
                            'slots': self.getvaluedefaulted(section, 'slots', 300, 'int'),
                            'scheduler': self.getvaluedefaulted(section, 'scheduler', self.first_scheduler),
                            'logconffile' : self.getvaluedefaulted(section, 'logconffile', None),
                        }
                    if self.launchers[section]['enablessl']:
                        if self.cp.has_option(section, 'verifypeer'):
                            self.launchers[section]['verifypeer'] = self.cp.getboolean(section, 'verifypeer')
                        else:
                            self.launchers[section]['verifypeer'] = False
                        if self.cp.has_option(section, 'cacert'):
                            self.launchers[section]['cacert'] = self.cp.get(section, 'cacert')
                        else:
                            self.launchers[section]['cacert'] = self.cp.get(section, 'certfile')
                        if self.cp.has_option(section, 'localcert'):
                            self.launchers[section]['localcert'] = self.cp.get(section, 'localcert')
                        else:
                            self.launchers[section]['localcert'] = self.cp.get(section, 'privkey')
                        if not os.path.exists(self.launchers[section]['cacert']):
                            raise Exception("Configuration error: path %s does not exists" % self.launchers[section]['cacert'])
                            return False
                        if not os.path.exists(self.launchers[section]['localcert']):
                            raise Exception("Configuration error: path %s does not exists" % self.launchers[section]['localcert'])
                            return False
                        if self.launchers[section]['verifypeer']: # we need twisted.internet.ssl.Certificate to activate certs
                            import twisted.internet.ssl
                            if not hasattr(twisted.internet.ssl, "Certificate"):
                                raise Exception('Configuration error in section "%s": I need at least Python Twisted 2.5 to handle peer checking' % (section))
                                return False

                        maxslots = (os.sysconf('SC_OPEN_MAX') - 50) / 2 # "should work in most case" formulae
                        if self.launchers[section]['slots'] > maxslots:
                            log.warn("launcher %s: section %s, slots capped to %s instead of %s regarding the max FD (%s)" % (self.name, section, maxslots, self.launchers[section]['slots'], os.sysconf('SC_OPEN_MAX')))
                            self.launchers[section]['slots'] = maxslots

                except ConfigParser.NoOptionError, e:
                    log.warn("launcher %s: section %s do not seems to be correct (%s), please fix the configuration file" % (self.name, section, e))
Exemplo n.º 10
0
    def setup(self, config_file, name = None):
        # Load configuration file
        if not self.cp: # self.cp is set if presetup() was already called
            self.presetup(config_file)

        self.name = name

        # Parse "launchers" section
        self.setoption('launchers', 'inventory_command', 'inventory_command')
        self.setoption('launchers', 'launcher_path', 'launcher_path')
        self.setoption('launchers', 'max_command_age', 'max_command_age', 'int')
        self.setoption('launchers', 'max_ping_time', 'max_ping_time', 'int')
        self.setoption('launchers', 'max_probe_time', 'max_probe_time', 'int')
        self.setoption('launchers', 'ping_path', 'ping_path')
        self.setoption('launchers', 'source_path', 'source_path')
        self.setoption('launchers', 'reboot_command', 'reboot_command')
        self.setoption('launchers', 'halt_command', 'halt_command')
        self.setoption('launchers', 'target_path', 'target_path')
        self.setoption('launchers', 'temp_folder_prefix', 'temp_folder_prefix')

        # Parse "wrapper" section
        self.setoption('wrapper', 'max_log_size', 'wrapper_max_log_size', 'int')
        self.setoption('wrapper', 'max_exec_time', 'wrapper_max_exec_time', 'int')
        self.setoption('wrapper', 'path', 'wrapper_path')

        # Parse "wget" section
        self.setoption('wget', 'wget_path', 'wget_path')
        if self.cp.has_section("wget"):
            if self.cp.has_option("wget", "wget_options"):
                self.wget_options = self.cp.get("wget", "wget_options").split(' ')
        self.setoption('wget', 'check_certs', 'wget_check_certs', 'bool')
        self.setoption('wget', 'resume', 'wget_resume', 'bool')

        # Parse a part of "ssh" section
        self.setoption('ssh', 'ssh_path', 'ssh_path')
        self.setoption('ssh', 'scp_path', 'scp_path')
        self.setoption('ssh', 'ssh_agent_path', 'ssh_agent_path')

        # Parse "rsync" section
        self.setoption('rsync', 'rsync_path', 'rsync_path')
        self.setoption('rsync', 'resume', 'rsync_resume', 'bool')
        self.setoption('rsync', 'set_executable', 'rsync_set_executable')
        if not self.rsync_set_executable in ('yes', 'no', 'keep'):
            self.logger.warning("set_executable can have '%s' for value (yes|no|keep)"%(self.rsync_set_executable))
            self.rsync_set_executable = 'yes'
        self.setoption('rsync', 'set_access', 'rsync_set_access')
        if not self.rsync_set_access in ('private', 'restricted', 'public'):
            self.logger.warning("set_access can have '%s' for value (private|restricted|public)"%(self.rsync_set_access))
            self.rsync_set_access = 'private'

        # +----------------+------------------+---------------------+------------------+
        # | set_executable |                  |                     |                  |
        # +--------------\ |       yes        |         no          |        keep      |
        # | set_access    \|                  |                     |                  |
        # +----------------+------------------+---------------------+------------------+
        # | private        | u=rwx,g=,o=  (1) | u=rw,g=,o=          | u=rwX,g=,o=      |
        # +----------------+------------------+---------------------+------------------+
        # | restricted     | u=rwx,g=rx,o=    | u=rw,g=r,o=         | u=rwX,g=rX,o=    |
        # +----------------+------------------+---------------------+------------------+
        # | public         | u=rwx,g=rwx,o=rx | u=rw,g=rw,o=r       | u=rwX,g=rwX,o=rX |
        # +----------------+------------------+---------------------+------------------+
        # (1) : default value
        exe = 'X'
        if self.rsync_set_executable == 'yes':
            exe = 'x'
        elif self.rsync_set_executable == 'no':
            exe = ''

        other = ',o='
        group = ',g='
        if self.rsync_set_access == 'public':
            other += "r%s"%(exe)
            group += "rw%s"%(exe)
        elif self.rsync_set_access == 'restricted':
            group += "r%s"%(exe)
        self.rsync_set_chmod = 'u=rw%s%s%s'%(exe, group, other)

        log.debug("config metavalue 'rsync_set_chmod' = %s"%(self.rsync_set_chmod))

        # [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')

        # Parse "wol" section
        self.setoption('wol', 'wol_bcast', 'wol_bcast')
        self.setoption('wol', 'wol_path', 'wol_path')
        self.setoption('wol', 'wol_port', 'wol_port')

        # Parse "tcp_sproxy" section
        self.setoption('tcp_sproxy', 'tcp_sproxy_path', 'tcp_sproxy_path')
        self.setoption('tcp_sproxy', 'tcp_sproxy_host', 'tcp_sproxy_host')
        self.setoption('tcp_sproxy', 'tcp_sproxy_check', 'tcp_sproxy_check', 'bool')
        self.setoption('tcp_sproxy', 'tcp_sproxy_establish_delay', 'tcp_sproxy_establish_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_connect_delay', 'tcp_sproxy_connect_delay', 'int')
        self.setoption('tcp_sproxy', 'tcp_sproxy_session_lenght', 'tcp_sproxy_session_lenght', 'int')
        self.setoption('tcp_sproxy', 'create_web_proxy', 'create_web_proxy', 'bool')
        if self.cp.has_section("tcp_sproxy"):
            if self.cp.has_option("tcp_sproxy", "tcp_sproxy_port_range"):
                range = map(lambda x: int(x), self.cp.get("tcp_sproxy", "tcp_sproxy_port_range").split('-'))
                if len(range) != 2:
                    log.info("'tcp_sproxy_port_range' not formated as expected, using default value, please check your config file ")
                else:
                    (self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end) = range
        log.info("launcher %s: section %s, option %s set to %d-%d" % (self.name, 'tcp_sproxy', 'tcp_sproxy_port_range', self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end))

        # Parse "smart_cleaner" section
        self.setoption('smart_cleaner', 'smart_cleaner_path', 'smart_cleaner_path')
        if self.smart_cleaner_path == '':
            LauncherConfig().is_smart_cleaner_available = False
        if self.cp.has_section("smart_cleaner"):
            if self.cp.has_option("smart_cleaner", "smart_cleaner_options"):
                self.smart_cleaner_options = self.cp.get("smart_cleaner", "smart_cleaner_options").split(' ')

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

                    awake_incertitude_factor = self.getvaluedefaulted(section, 'awake_incertitude_factor', .2, 'float')
                    if awake_incertitude_factor > .5:
                        log.warning("in %s, awake_incertitude_factor greater than .5, setting it to .5" % (section))
                        awake_incertitude_factor = .5
                    if awake_incertitude_factor < 0:
                        log.warning("in %s, awake_incertitude_factor lower than 0, setting it to 0" % (section))
                        awake_incertitude_factor = 0
                    awake_time = self.getvaluedefaulted(section, 'awake_time', 600, 'int')
                    if awake_time < 60:
                        log.warning("in %s, awake_time lower than 60, setting it to 60" % (section))
                        awake_time = 60

                    self.schedulers[section] = {
                        'host' : self.getvaluedefaulted(section, 'host', '127.0.0.1'),
                        'port' : self.getvaluedefaulted(section, 'port', "8000"),
                        'username' : username,
                        'password' : password,
                        'enablessl' : self.getvaluedefaulted(section, 'enablessl', True, 'bool'),
                        'awake_time' : awake_time,
                        'awake_incertitude_factor' : awake_incertitude_factor,
                        'defer_results' : self.getvaluedefaulted(section, 'defer_results', False, 'bool')
                    }
                    if self.first_scheduler == None:
                        self.first_scheduler = section
                except ConfigParser.NoOptionError, error:
                    log.warn("launcher %s: section %s do not seems to be correct (%s), please fix the configuration file" % (self.name, section, error))
Exemplo n.º 11
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(' ')
        self.setoption("scheduler", "scheduler_path", "scheduler_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')

        # [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})
Exemplo n.º 12
0
    def setup(self, config_file, name=None):
        # Load configuration file
        if not self.cp:  # self.cp is set if presetup() was already called
            self.presetup(config_file)

        self.name = name

        # Parse "launchers" section
        self.setoption("launchers", "inventory_command", "inventory_command")
        self.setoption("launchers", "launcher_path", "launcher_path")
        self.setoption("launchers", "max_command_age", "max_command_age", "int")
        self.setoption("launchers", "max_ping_time", "max_ping_time", "int")
        self.setoption("launchers", "max_probe_time", "max_probe_time", "int")
        self.setoption("launchers", "ping_path", "ping_path")
        self.setoption("launchers", "source_path", "source_path")
        self.setoption("launchers", "reboot_command", "reboot_command")
        self.setoption("launchers", "halt_command", "halt_command")
        self.setoption("launchers", "target_path", "target_path")
        self.setoption("launchers", "temp_folder_prefix", "temp_folder_prefix")

        # Parse "wrapper" section
        self.setoption("wrapper", "max_log_size", "wrapper_max_log_size", "int")
        self.setoption("wrapper", "max_exec_time", "wrapper_max_exec_time", "int")
        self.setoption("wrapper", "path", "wrapper_path")

        # Parse "wget" section
        self.setoption("wget", "wget_path", "wget_path")
        if self.cp.has_section("wget"):
            if self.cp.has_option("wget", "wget_options"):
                self.wget_options = self.cp.get("wget", "wget_options").split(" ")
        self.setoption("wget", "check_certs", "wget_check_certs", "bool")
        self.setoption("wget", "resume", "wget_resume", "bool")

        # Parse a part of "ssh" section
        self.setoption("ssh", "ssh_path", "ssh_path")
        self.setoption("ssh", "scp_path", "scp_path")
        self.setoption("ssh", "ssh_agent_path", "ssh_agent_path")

        # Parse "rsync" section
        self.setoption("rsync", "rsync_path", "rsync_path")
        self.setoption("rsync", "resume", "rsync_resume", "bool")
        self.setoption("rsync", "set_executable", "rsync_set_executable")
        if not self.rsync_set_executable in ("yes", "no", "keep"):
            self.logger.warning("set_executable can have '%s' for value (yes|no|keep)" % (self.rsync_set_executable))
            self.rsync_set_executable = "yes"
        self.setoption("rsync", "set_access", "rsync_set_access")
        if not self.rsync_set_access in ("private", "restricted", "public"):
            self.logger.warning(
                "set_access can have '%s' for value (private|restricted|public)" % (self.rsync_set_access)
            )
            self.rsync_set_access = "private"

        # +----------------+------------------+---------------------+------------------+
        # | set_executable |                  |                     |                  |
        # +--------------\ |       yes        |         no          |        keep      |
        # | set_access    \|                  |                     |                  |
        # +----------------+------------------+---------------------+------------------+
        # | private        | u=rwx,g=,o=  (1) | u=rw,g=,o=          | u=rwX,g=,o=      |
        # +----------------+------------------+---------------------+------------------+
        # | restricted     | u=rwx,g=rx,o=    | u=rw,g=r,o=         | u=rwX,g=rX,o=    |
        # +----------------+------------------+---------------------+------------------+
        # | public         | u=rwx,g=rwx,o=rx | u=rw,g=rw,o=r       | u=rwX,g=rwX,o=rX |
        # +----------------+------------------+---------------------+------------------+
        # (1) : default value
        exe = "X"
        if self.rsync_set_executable == "yes":
            exe = "x"
        elif self.rsync_set_executable == "no":
            exe = ""

        other = ",o="
        group = ",g="
        if self.rsync_set_access == "public":
            other += "r%s" % (exe)
            group += "rw%s" % (exe)
        elif self.rsync_set_access == "restricted":
            group += "r%s" % (exe)
        self.rsync_set_chmod = "u=rw%s%s%s" % (exe, group, other)

        log.debug("config metavalue 'rsync_set_chmod' = %s" % (self.rsync_set_chmod))

        # [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")

        # Parse "wol" section
        self.setoption("wol", "wol_bcast", "wol_bcast")
        self.setoption("wol", "wol_path", "wol_path")
        self.setoption("wol", "wol_port", "wol_port")

        # Parse "tcp_sproxy" section
        self.setoption("tcp_sproxy", "tcp_sproxy_path", "tcp_sproxy_path")
        self.setoption("tcp_sproxy", "tcp_sproxy_host", "tcp_sproxy_host")
        self.setoption("tcp_sproxy", "tcp_sproxy_establish_delay", "tcp_sproxy_establish_delay", "int")
        self.setoption("tcp_sproxy", "tcp_sproxy_connect_delay", "tcp_sproxy_connect_delay", "int")
        self.setoption("tcp_sproxy", "tcp_sproxy_session_lenght", "tcp_sproxy_session_lenght", "int")
        if self.cp.has_section("tcp_sproxy"):
            if self.cp.has_option("tcp_sproxy", "tcp_sproxy_port_range"):
                range = map(lambda x: int(x), self.cp.get("tcp_sproxy", "tcp_sproxy_port_range").split("-"))
                if len(range) != 2:
                    log.info(
                        "'tcp_sproxy_port_range' not formated as expected, using default value, please check your config file "
                    )
                else:
                    (self.tcp_sproxy_port_range_start, self.tcp_sproxy_port_range_end) = range
        log.info(
            "launcher %s: section %s, option %s set to %d-%d"
            % (
                self.name,
                "tcp_sproxy",
                "tcp_sproxy_port_range",
                self.tcp_sproxy_port_range_start,
                self.tcp_sproxy_port_range_end,
            )
        )

        # Parse "smart_cleaner" section
        self.setoption("smart_cleaner", "smart_cleaner_path", "smart_cleaner_path")
        if self.smart_cleaner_path == "":
            LauncherConfig().is_smart_cleaner_available = False
        if self.cp.has_section("smart_cleaner"):
            if self.cp.has_option("smart_cleaner", "smart_cleaner_options"):
                self.smart_cleaner_options = self.cp.get("smart_cleaner", "smart_cleaner_options").split(" ")

        # Parse "scheduler_XXXX" sections
        for section in self.cp.sections():
            if re.compile("^scheduler_[0-9]+$").match(section):
                try:
                    username = self.getvaluedefaulted(section, "username", "username")
                    password = self.getvaluedefaulted(section, "password", "password", "pass")
                    if not isTwistedEnoughForLoginPass():
                        if username != "":
                            if username != "username":
                                log.warning(
                                    "your version of twisted is not high enough to use login (%s/username)" % (section)
                                )
                            username = ""
                        if password != "":
                            if password != "password":
                                log.warning(
                                    "your version of twisted is not high enough to use password (%s/password)"
                                    % (section)
                                )
                            password = ""

                    awake_incertitude_factor = self.getvaluedefaulted(section, "awake_incertitude_factor", 0.2, "float")
                    if awake_incertitude_factor > 0.5:
                        log.warning("in %s, awake_incertitude_factor greater than .5, setting it to .5" % (section))
                        awake_incertitude_factor = 0.5
                    if awake_incertitude_factor < 0:
                        log.warning("in %s, awake_incertitude_factor lower than 0, setting it to 0" % (section))
                        awake_incertitude_factor = 0
                    awake_time = self.getvaluedefaulted(section, "awake_time", 600, "int")
                    if awake_time < 60:
                        log.warning("in %s, awake_time lower than 60, setting it to 60" % (section))
                        awake_time = 60

                    self.schedulers[section] = {
                        "host": self.getvaluedefaulted(section, "host", "127.0.0.1"),
                        "port": self.getvaluedefaulted(section, "port", "8000"),
                        "username": username,
                        "password": password,
                        "enablessl": self.getvaluedefaulted(section, "enablessl", True, "bool"),
                        "awake_time": awake_time,
                        "awake_incertitude_factor": awake_incertitude_factor,
                        "defer_results": self.getvaluedefaulted(section, "defer_results", False, "bool"),
                    }
                    if self.first_scheduler == None:
                        self.first_scheduler = section
                except ConfigParser.NoOptionError, error:
                    log.warn(
                        "launcher %s: section %s do not seems to be correct (%s), please fix the configuration file"
                        % (self.name, section, error)
                    )
Exemplo n.º 13
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})
Exemplo n.º 14
0
Arquivo: config.py Projeto: allgi/mmc
    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})