Example #1
0
def list_sites(self, directory, site=''):
    """
    List site into sites-available or site-enabled directory.
    directory is required and must be set in conf.d/*/services.conf.
    In this case, * must be your env.
    site could be empty or glob characters.
    """
    config = {}
    # Filesystem operations callback (fsh) is required.
    if not hasattr(self, 'fsh'):
        self.load_callbacks('fsh')

    config = __config.get_config('services.conf',
                [self.systemtype]).get_section('nginx')[1]

    valid_directory = ['available', 'enabled']
    if directory not in valid_directory:
        __LOG.log_die("%s: not a valid path." % (directory))

    config_path_site = config["path_sites_%s" % (directory)]
    site_exist = self.fsh.file_exists("%s" % (config_path_site.rstrip('/') +
                    '/' + site))

    if not site or __common.has_magic(site) is True:
        out = self.fsh.list_files("%s" % (
            config_path_site.rstrip('/') + '/' + site))
        return out
    else:
        if site_exist is False:
            __LOG.log_die("File %s: not found in %s" % (site, config_path_site))
        else:
            out = self.fsh.list_files("%s" % (
                config_path_site.rstrip('/') + '/' + site))
            return out, site, site_exist
Example #2
0
def retrieve_config_infos(self, service_name, action):
    """
    Retrieve configuration informations for service_name/action
    See also configuration documentation for more details.
    """
    config_dict = dict()
    config = __config.get_config(__SERVICES_CONFIGFILE, [self.trk.systemtype])

    # trying service specific configuration, or falling back to GENERIC
    # no specific nor generic section found, nothing can be done
    (section_name, section_content) = config.get_section(service_name,
                                                         default = "GENERIC")
    if section_content == None:
        __LOG.log_c("service not defined and GENERIC section not found")
        return None

    # sudo usage to do action on service name
    config_dict['use_sudo'] = config.getopt(section_name,
                                            ['use_sudo'], default = False,
                                            vartype="boolean")

    # pre action command to run (specific -> generic -> None)
    config_dict['pre'] = config.getopt(section_name,
                                       ['pre_%s' % (action), 'pre'])

    # action command to run (required)
    config_dict['cmd'] = config.getopt(section_name,
                                       ['cmd_%s' % (action), 'cmd'])

    # post action command to run (specific -> generic -> None)
    config_dict['post'] = config.getopt(section_name,
                                        ['post_%s' % (action), 'post'])

    # fallback action command to run (specific -> generic -> None)
    config_dict['fallback'] = config.getopt(section_name,
                                            ['fallback_%s' % (action),
                                             'fallback'])

    return config_dict
Example #3
0
def list_sites(self, directory, site=''):
    """
    List site into sites-available or site-enabled directory.
    ``directory`` is required and must be set in conf.d/*/services.conf.
    In this case, ``*`` must be your env.
    ``site`` could be empty or wildcard for now, glob characters are not
    allowed right now.

    ToDo: accept glob character to ``site``.
    """
    config = {}
    # Filesystem operations callback (fsh) is required.
    if not hasattr(self, 'fsh'):
        self.load_callbacks('fsh')

    config = __config.get_config('services.conf',
                [self.systemtype]).get_section('apache2')[1]

    valid_directory = ['available', 'enabled']
    if directory not in valid_directory:
        __LOG.log_die("%s: not a valid path." % (directory))

    config_path_site = config["path_sites_%s" % (directory)]
    site_exist = self.fsh.file_exists("%s" % (config_path_site.rstrip('/') +
                    '/' + site))

    if not site or site == '*':
        out = self.fsh.list_files("%s" % (
            config_path_site.rstrip('/') + '/' + site))
        return out
    else:
        if site_exist is False:
            __LOG.log_die("File %s: not found in %s" % (site, config_path_site))
        else:
            out = self.fsh.list_files("%s" % (
                config_path_site.rstrip('/') + '/' + site))
            return out, site, site_exist
Example #4
0
def retrieve_config_infos(self):
    """ retrieve config info """
    caller = __scc.findcaller(2)[0]
    config = __config.get_config(__USERS_CONFIGFILE, [self.systemtype])
    return config.get_section(caller)