Example #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, {}))
Example #2
0
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
Example #3
0
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
Example #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"])
Example #5
0
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)
Example #6
0
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)
Example #7
0
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
Example #8
0
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