fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] [PATCH] Fix #7: Implement "something like roles."


From: Christian Vest Hansen
Subject: Re: [Fab-user] [PATCH] Fix #7: Implement "something like roles."
Date: Thu, 6 Nov 2008 22:27:48 +0100

On Thu, Nov 6, 2008 at 10:16 PM, Jeff Forcier <address@hidden> wrote:
> Sorry to be a wet blanket of sorts! I just tend to have an eye for
> things-easy-to-make-mistakes-with (probably because I do tend to be
> prone to such things...) and wanted to make my complaint known up
> front ;)

I'm the one that should be sorry for not thinking the implementation
through properly :) Also, this kind of code-eyeballing is (supposedly)
one of the primary arguments of why open source works.

I have edited the path:


Redo the role implementation based on Jeff's comments.

---
 doc/samples/roles/fabfile.py |    6 +++---
 fabric.py                    |   26 ++++++++++++++++----------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/doc/samples/roles/fabfile.py b/doc/samples/roles/fabfile.py
index fd54c53..48db346 100644
--- a/doc/samples/roles/fabfile.py
+++ b/doc/samples/roles/fabfile.py
@@ -11,15 +11,15 @@ def production():
 def build():
     local('echo Building project')

address@hidden('rdbms')
address@hidden('rdbms')
 def prepare_db():
     run("echo Preparing database for deployment")

address@hidden('httpd')
address@hidden('httpd')
 def prepare_web():
     run("echo Preparing web servers for deployment")

 @depends(prepare_db, prepare_web)
address@hidden('httpd')
address@hidden('httpd')
 def deploy():
     run("echo Doing final deployment things to $(fab_host)")
diff --git a/fabric.py b/fabric.py
index c1ae55a..22d60f7 100644
--- a/fabric.py
+++ b/fabric.py
@@ -195,6 +195,14 @@ def hosts(*hosts):
     return decorator

 @decorator
+def roles(*roles):
+    "Tags function object with desired fab_hosts to run on."
+    def decorator(fn):
+        fn.roles = roles
+        return fn
+    return decorator
+
address@hidden
 def mode(mode):
     "Tags function object with desired fab_mode to run in."
     def decorator(fn):
@@ -1251,15 +1259,13 @@ def _args_hash(args):

 def _execute_at_target(command, args):
     mode = ENV['fab_local_mode'] = getattr(command, 'mode', ENV['fab_mode'])
-    hosts = ENV['fab_local_hosts'] = getattr(
-        command, 'hosts', ENV.get('fab_hosts'))
-    if hosts and len(hosts) == 1 and isinstance(hosts[0], basestring):
-        # we allow the hosts to be a string-alias for another variable
-        # that will contain the real array of hosts to connect to.
-        host_alias = _lazy_format(hosts[0])
-        hosts = ENV.get(host_alias)
-        print "Resoling host alias", host_alias, "to", (', '.join(hosts))
-        ENV['fab_local_hosts'] = hosts
+    hosts = ENV['fab_local_hosts'] = set(getattr(
+        command, 'hosts', ENV.get('fab_hosts') or []))
+    roles = getattr(command, 'roles', [])
+    for role in roles:
+        role = _lazy_format(role)
+        role_hosts = ENV.get(role)
+        map(hosts.add, role_hosts)
     # Determine whether we need to connect for this command, do so if so
     if _needs_connect(command):
         _check_fab_hosts()
@@ -1267,7 +1273,7 @@ def _execute_at_target(command, args):
     if mode in ('rolling', 'fanout'):
         print("Warning: The 'rolling' and 'fanout' fab_modes are " +
               "deprecated.\n   Use 'broad' and 'deep' instead.")
-        ENV['fab_local_mode'] = 'broad'
+        mode = ENV['fab_local_mode'] = 'broad'
     # Run command once, with each operation running once per host.
     if mode == 'broad':
         command(**(args or {}))
-- 
1.6.0.1

Attachment: 0002-Redo-the-role-implementation-based-on-Jeff-s-comment.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]