我需要使用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