我需要使用Fabric在网站中执行一些操作,这些操作使用一台计算机作为文件系统,其他计算机使用数据库服务器。我需要处理两台主机。我怎样才能做到这一点?如何在Fabric(Python)中定义多个服务器环境?
我有一些代码,但我不能让环境定义工作。
这个想法是连接到远程文件系统服务器并获取文件,然后连接到远程数据库服务器并获取数据库模式。
,我对现在的代码是这样的:
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
'''
Here I define where is my "aid"s file structure
'''
local_root = '/home/andre/test' # This is the root folder for the audits
code_location = '/remote_code' # This is the root folder dor the customer code inside each audit
#
# ENVIRONMENTS CONFIGURATIONS
#
'''
Here I configure where is the remote file server
'''
def file_server():
env.user = 'andre'
env.hosts = ['localhost']
'''
Here I configure where is the database server
'''
def database_server():
env.user = 'andre'
env.hosts = ['192.168.5.1']
#
# START SCRIPT
#
def get_install(remote_location, aid):
### I will get the files
'''
Here I need to load the file_server() definitions
'''
working_folder = local_root + '/%s' % aid # I will define the working folder
local('mkdir ' + working_folder) # I will create the working folder for this audit
local('mkdir ' + working_folder + code_location) # I will create the folder to receive the code
get(remote_location, working_folder + code_location) # I will download the code to my machine
### I will get the database
'''
Here I need to load the database_server() definitions
'''
local('dir') # Just to test
我怎样才能里面get_install()定义环境file_server()和database_server()?
最好的问候,
有一种方法可以为file_server()和database_server()运行“fab get_install”?我像你说的那样做,但我需要立即做。有可能的? – 2012-01-06 15:49:15
你的意思是只需输入一个命令?我不这么认为。整个观点是要有独立于环境的行动,然后能够将环境交换出去。但我不太了解Fabric,所以也许有。 – Tom 2012-01-06 17:23:58