util.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:mendel 作者: sproutsocial 项目源码 文件源码
def create_host_task(key, host_config):
    """ Generate host tasks dynamically from config """

    # do validation *before* dynamic task function generation
    # allowing for hostname to avoid a breaking change
    if 'hostname' in host_config and 'hostnames' in host_config:
        raise ValueError(red('cannot specify both \'hostname\' and \'hostnames\''))
    if 'hostname' not in host_config and 'hostnames' not in host_config:
        raise ValueError(red('must supply \'hostnames\' section'))

    hosts_key = 'hostname' if 'hostname' in host_config else 'hostnames'

    def f():
        hosts = None
        if 'hostname' in host_config:
            warn('\'hostname\' is being deprecated in favor of \'hostnames\' so you can provide a csv-list\n')
            hostname = host_config['hostname']
            hosts = [hostname]

        if 'hostnames' in host_config:
            hosts = [h.strip() for h in host_config['hostnames'].split(',')]

        env.hosts = hosts
        env.port = host_config.get('port', 22)

        # convenience for local deployment to Vagrantfile VM
        if hosts[0] in {'localhost', '127.0.0.1'}:
            hostname = '127.0.0.1'  # sometimes fabric just fails with 'localhost'
            env.user = 'vagrant'
            env.password = 'vagrant'
            env.port = host_config.get('port', 2222)

    f.__name__ = key
    f.__doc__ = "[hosts] \tsets deploy hosts to %s" % green(host_config[hosts_key])
    return WrappedCallableTask(f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号