Created
April 9, 2012 17:52
-
-
Save bmannix/2345006 to your computer and use it in GitHub Desktop.
pyfab provides a simpler fabric interface for python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fabfile as fab | |
class Pyfab: | |
def __init__(self, role, user): | |
self.role = role | |
self.user = user | |
def fab_exec(self, command, *args, **kwargs): | |
''' | |
this runs fabric commands defined in the fabfile. By default it | |
will execute commands based on the roles passed from the fabric config | |
stored in a dictionary called 'roledefs'. | |
By default it will execute commands as the user passed during init. | |
You may override the user or define a single host e.g.: | |
fab_exec("<fab file cmd>", args, kwargs, host='xenon.rdc.lctl.gov', user='brma') | |
''' | |
user = self.user | |
host = None | |
fabkwargs = {} | |
hosts = fab.env["roledefs"][self.role] | |
for key in kwargs: | |
if key == 'user': | |
user = kwargs[key] | |
elif key == 'host': | |
host = [ kwargs[key] ] | |
else: | |
fabkwargs[key] = kwargs[key] | |
fab.env.user = user | |
if host: hosts = host | |
for host_str in hosts: | |
fab.env.host_string = host_str | |
getattr(fab, command)(*args, **fabkwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
leaving this here for historical reasons, but fabric included support for this right around the same time I wrote it