Use of Fabric as library (for fab-user mailing list)
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
| # With many thanks to pmuller for its streamlogger class : # https://gist.githubusercontent.com/pmuller/2376336/raw/cc455144c66b058d8de56c5d6c0a87dbd7c301d5/streamlogger.py | |
| class FabricException(Exception): | |
| pass | |
| def fabric_task(host, command, **kwargs): | |
| """ | |
| Args: | |
| host (string): eg : server-id | |
| command (import path) : python import path to the task, eg sercie.process.status | |
| """ | |
| fabric.api.env.host_string = "root@{0}:22".format(host) | |
| fabric.api.env.host = host | |
| fabric.api.env.abort_on_prompts = True | |
| fabric.api.env.colorize_errors = False | |
| fabric.api.env.abort_exception = FabricException | |
| fabric.api.env.warn_only = True | |
| from app.lib.streamsilencer import StreamSilencer | |
| with StreamSilencer('stdout'): | |
| try: | |
| with fabric.api.quiet(): | |
| return fabric.api.execute(command, | |
| hosts=[fabric.api.env.host_string], | |
| **kwargs)[fabric.api.env.host_string] | |
| finally: | |
| fabric.network.disconnect_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment