gpt4 book ai didi

Python 结构嵌套角色

转载 作者:太空宇宙 更新时间:2023-11-04 05:49:22 24 4
gpt4 key购买 nike

我想了解如何在 fabric 中使用嵌套的 roledefsIt写着,

Role definitions are not necessary configuration of hosts only, but could hold other role specific settings of your choice. This is achieved by defining the roles as dicts and host strings under a hosts key

我的配置是这样的

from fabric.api import env
env.roledefs = {
'prod': {
'hosts': ['prod1', 'prod2', 'prod3'],
'db': ['db1']
},
}

我的问题是如何为特定任务访问 db

@roles('db') or @roles('prod')  #<- not sure what to add here
def migrate():
# migration stuff
pass

最佳答案

我的建议:

roles = {'prod': {'hosts': ['node1', 'node2'], 'db': ['node3']}
'test': {'hosts': ['test1'], 'db': ['test2']}}

def migrate(role='test'):
env.roledefs = roles[role]
execute(_run_prepare)
execute(_run_migrate)

@roles('hosts', 'db')
def _run_prepare():
pass # runs on hosts in role "hosts" and hosts in role "db"

@roles('db')
def _run_migrate():
pass # runs on hosts in role "db"

关于Python 结构嵌套角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30964502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com