Example #1
0
def setup():
  """
  Sets up the specified roles in sequence based on env.role_config
  Fabric 1.x is too limited to allow for parallel role configuration -- this
  should change with the release of Fabric 2.x. Check out this Github issue
  for more info...

  https://github.com/fabric/fabric/issues/361

  # ensure hostname exists in hosts due to AWS inconsistency
  # host_string = '127.0.1.1 ' + sudo('hostname').split('\r\n').pop()
  # contrib.files.append('/etc/hosts', host_string, use_sudo=True)
  """
  env.user = env.admin_user
  for role in env.roles:
    with mode_sudo():
      defaults = ['install_pgps',
                  'install_sources',
                  'install_ppas',
                  'install_pkgs',
                  'setup_deploy_user']
      for subtask in defaults:
        execute(fabric_task(env.subtasks[subtask]), env.role_config[role])
      for subtask in env.role_config[role]['subtasks']['setup']:
        execute(fabric_task(env.subtasks[subtask]), env.role_config[role])
Example #2
0
 def decorator(func):
     t = fabric_task(*args, **kwargs)
     wrapper = t(func)
     if namespace is not None:
         if not hasattr(wrapper, '_hivemind'):
             wrapper._hivemind = {}
         wrapper._hivemind['namespace'] = namespace
     return wrapper
Example #3
0
def deploy(app):
  """ ... """
  env.user = env.deploy_user
  if 'strategy' in env.app_config[app]:
    strategy_name = env.app_config[app]['strategy']
  else:
    strategy_name = env.strategy
  strategy = env.strategies[strategy_name]
  execute(fabric_task(strategy['function']), app)
Example #4
0
def task(func):
    '''Composition of decorator functions for inherent self-documentation on
    task execution.

    On execution, each task prints out its name and its first docstring line.
    '''
    prefix = '\n# '
    tail = '\n'
    return fabric_task(
        print_full_name(color=magenta, prefix=prefix,
                        tail=tail)(print_doc1(func)))
Example #5
0
 def wrapped(*args, **kwargs):
   for role in env.roledefs:
     config = env.role_defaults.copy()
     update(config, env.role_config[role] if role in env.role_config else {})
     env.role_config[role] = config
   for app in env.app_config:
     config = env.app_defaults.copy()
     if 'strategy' in env.app_config[app]:
       strategy = env.strategies[env.app_config[app]['strategy']]
       update(config, strategy['defaults'])
     update(config, env.app_config[app])
   execute(fabric_task(callable), *args, **kwargs)
Example #6
0
def task(callable):
  """
  Wraps a Fabric `task` decorator with some extra `env` var processing to
  ensure custom configuration is collapsed over defaults.

  env.role_config[role] <-- role_defaults <-- env.role_config[role]
  env.app_config[app] <-- app_defaults  <-- strategy_defaults <-- env.app_config[app]
  """
  def wrapped(*args, **kwargs):
    for role in env.roledefs:
      config = env.role_defaults.copy()
      update(config, env.role_config[role] if role in env.role_config else {})
      env.role_config[role] = config
    for app in env.app_config:
      config = env.app_defaults.copy()
      if 'strategy' in env.app_config[app]:
        strategy = env.strategies[env.app_config[app]['strategy']]
        update(config, strategy['defaults'])
      update(config, env.app_config[app])
    execute(fabric_task(callable), *args, **kwargs)
  wrapped.__name__ = callable.__name__
  wrapped.__doc__ = callable.__doc__
  return fabric_task(wrapped)
Example #7
0
def task(function):
    """
    Convenience decorator that wraps the default Fabric task decorator with the
    :py:func:`register` decorator.
    """
    return fabric_task(register(function))
Example #8
0
        )
    )
    print(
        Panel(
            pformat(user_config[name]),
            title="[red1]User overrides[/red1]",
            expand=False,
        )
    )


# Metaprogram the machine wrappers
for machine_name in set(config.keys()) - set(["default"]):

    globals()[machine_name] = fabric_task(alias=machine_name)(
        partial(machine, machine_name)
    )
    # globals()[machine_name] = task(alias=machine_name)(
    #     partial(machine, machine_name)
    # )


def load_plugin_env_vars(plugin_name):
    """
    the decorator to load the `env` variable specific for the pluing
    To use this decorator, you need to add it to the `#!python @task` function
    in your plugin.
    example :
    ```python
    @task
    @load_plugin_env_vars("<plugin_name>")