コード例 #1
0
 def test_load_from_empty_module(self):
     """
     Loading empty state results in empty dictionaries.
     """
     self.settings = Settings.load_from_module(join(self.dir_name, "empty.py"))
     for key in Settings.KEYS:
         eq_({}, getattr(self.settings, key, {}))
コード例 #2
0
ファイル: autotasks.py プロジェクト: locationlabs/confab
def generate_tasks(settings_path=None):
    """
    Autogenerate `env` tasks for all defined environments.
    """
    def create_task(settings, environment):
        def select_environment(*roles):
            if hasattr(env, "environmentdef"
                       ) and env.environmentdef.name != environment:
                abort("Environment already defined as '{}'".format(
                    env.environmentdef.name))

            # Do not select hosts here.
            #
            # If `fab` is run with multiple hosts, this task will be run multiple
            # times, overwriting the value of "env.environmentdef". By not selecting hosts
            # here, we ensure that the same environmentdef will be loaded each
            # time. See also confab.iter:iter_conffiles
            env.environmentdef = settings.for_env(environment).with_roles(
                *roles)

        return select_environment

    settings = Settings.load_from_module(settings_path)

    for environment in settings.environmentdefs.iterkeys():
        _add_task(
            environment, create_task(settings, environment),
            "Set environment to '{environment}'".format(
                environment=environment))
    return settings
コード例 #3
0
ファイル: autotasks.py プロジェクト: locationlabs/confab
def generate_tasks(settings_path=None):
    """
    Autogenerate `env` tasks for all defined environments.
    """
    def create_task(settings, environment):
        def select_environment(*roles):
            if hasattr(env, "environmentdef") and env.environmentdef.name != environment:
                abort("Environment already defined as '{}'".format(env.environmentdef.name))

            # Do not select hosts here.
            #
            # If `fab` is run with multiple hosts, this task will be run multiple
            # times, overwriting the value of "env.environmentdef". By not selecting hosts
            # here, we ensure that the same environmentdef will be loaded each
            # time. See also confab.iter:iter_conffiles
            env.environmentdef = settings.for_env(environment).with_roles(*roles)
        return select_environment

    settings = Settings.load_from_module(settings_path)

    for environment in settings.environmentdefs.iterkeys():
        _add_task(environment,
                  create_task(settings, environment),
                  "Set environment to '{environment}'".format(environment=environment))
    return settings
コード例 #4
0
 def test_load_from_example_module(self):
     """
     Loading non-empty module results in expected dictionaries.
     """
     self.settings = Settings.load_from_module(join(self.dir_name, "example.py"))
     eq_(["host1", "host2"], self.settings.environmentdefs["environment1"])
     eq_(["host1"], self.settings.roledefs["role1"])
     eq_(["component1"], self.settings.componentdefs["role1"])
コード例 #5
0
ファイル: diagnostics.py プロジェクト: toddhodes/confab
def main():
    """
    Diagnostics command line entry point.
    """
    try:
        # Parse and validate arguments
        parser, options, arguments = parse_options()

        settings = Settings.load_from_module(options.directory)

    except Exception as e:
        parser.error(e)

    descriptions = make_conffile_descriptions(settings,
                                              options.environment,
                                              options.hosts.split(",") if options.hosts else [],
                                              options.roles.split(",") if options.roles else [])
    print_conffiles(descriptions)
コード例 #6
0
ファイル: diagnostics.py プロジェクト: locationlabs/confab
def main():
    """
    Diagnostics command line entry point.
    """
    try:
        # Parse and validate arguments
        parser, options, arguments = parse_options()

        configure_output(verbosity=options.verbosity, quiet=options.quiet)

        settings = Settings.load_from_module(options.directory)

    except Exception as e:
        parser.error(e)

    table = make_table(settings,
                       options.environment,
                       options.hosts.split(",") if options.hosts else [],
                       options.roles.split(",") if options.roles else [])
    print(table)
コード例 #7
0
ファイル: main.py プロジェクト: toddhodes/confab
def load_environmentdef(environment,
                        settings_path=None,
                        hosts=None,
                        roles=None):
    """
    Load settings, construct an environment definition, and save in Fabric env
    as "confab" for use by subsequent confab tasks.

    :param environment: environment name
    :param settings_path: path to settings module
    :param hosts: comma delimited host list
    :param roles: comma delimited role list
    """

    settings_ = Settings.load_from_module(settings_path)

    # Normalize and resolve hosts to roles mapping
    selected_hosts = hosts.split(",") if hosts else []
    selected_roles = roles.split(",") if roles else []

    env.environmentdef = settings_.for_env(environment)
    env.environmentdef = env.environmentdef.with_hosts(*selected_hosts)
    env.environmentdef = env.environmentdef.with_roles(*selected_roles)
    return env.environmentdef
コード例 #8
0
ファイル: main.py プロジェクト: locationlabs/confab
def load_environmentdef(environment,
                        settings_path=None,
                        hosts=None,
                        roles=None):
    """
    Load settings, construct an environment definition, and save in Fabric env
    as ``confab`` for use by subsequent confab tasks.

    :param environment: environment name
    :param settings_path: path to settings module
    :param hosts: comma delimited host list
    :param roles: comma delimited role list
    """

    settings_ = Settings.load_from_module(settings_path)

    # Normalize and resolve hosts to roles mapping
    selected_hosts = hosts.split(",") if hosts else []
    selected_roles = roles.split(",") if roles else []

    env.environmentdef = settings_.for_env(environment)
    env.environmentdef = env.environmentdef.with_hosts(*selected_hosts)
    env.environmentdef = env.environmentdef.with_roles(*selected_roles)
    return env.environmentdef