ファブリックを使用して、ファイルシステムに1台のマシンを使用し、データベースサーバーに他のマシンを使用するWebサイトでいくつかの操作を行う必要があります。私は2つのホストを処理する必要があります。どうやってやるの?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():
私は今のところ持っているコードは、このようなものでしょうか?
よろしく、
"fab get_install"を実行しているfile_server()とdatabase_server()にこれを行う方法がありますか?私はあなたが言ったようにしていますが、私はすぐにそれを行う必要があります。可能です? –
ただ1つのコマンドを入力するだけですか?私はそうは思わない。全体のポイントは、環境から独立したアクションを持つことで、環境を交換することができるようにすることです。しかし、私はファブリックをよく知っていないので、おそらくそこにあります。 – Tom