how to call a remote fabric method in django


I need to call a fabric method on a remote machine through django. I mean when user send a given request get the hostname of a remote machine. Something like this:

def get_hostname(request): hostname = os.system('fab remote_server hostname') return hostname


For greater control and flexibility you should use fabric as a library. see: <a href="http://docs.fabfile.org/en/1.3.3/usage/library.html" rel="nofollow">http://docs.fabfile.org/en/1.3.3/usage/library.html</a>

import fabric.api as fab from fabric.network import disconnect_all from contextlib import contextmanager @context_manager def ssh(settings): with settings: try: yield finally: disconnect_all() def hostname(request, host='somehost', user='someuser', pw='secret'): with ssh(fab.settings(host_string=host, user=user, password=pw)): return fab.run('hostname')


If you server has the needed parts for fabric you should be able to just import you fabfile on call the function directly.

(This is just some code I dreamt up YMMW)

import fabfile as f #Your fabfile must be somewhere it can be imported def get_hostname(request): hostname = f.remote_server(hostname) return hostname

You can also import and use fabric directly from django


Check fabric.tasks.execute() after version 1.3.


  • Trying to use fabric to check out a git repository to a subdirectory
  • run fabric file renamed other than fabfile.py and password-less ssh
  • Fabric does not use SSH key [duplicate]
  • Model with BatchNormalization: stagnant test loss
  • Xpath extract current node content including all child node
  • How to handle a Boolean when expecting a String in GSON? [closed]
  • How to understand ndarray.reshape function?
  • Failed to resolve: com.google.gms.google-services:15.0.1:
  • How to get the date of next specified day of week
  • Python cosine function precision [duplicate]
  • revitapi ironpython ToRoom returns “indexer # object”
  • Zurb Foundation _global.scss meta styles for js?
  • How to convert workspace coordinates to screen coordinates?
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Hardware Accelerated Image Scaling in windows using C++
  • one Local Olampyad Questions on Informatic in 2011
  • iOS: Detect app start via notification press
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • How to attach a node.js readable stream to a Sendgrid email?
  • Nant, Vault & Windows Integrated Authentication
  • Bug in WPF DataGrid
  • Does CUDA 5 support STL or THRUST inside the device code?
  • When should I choose bucket sort over other sorting algorithms?
  • Hazelcast - OperationTimeoutException
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • Why winpcap requires both .lib and .dll to run?
  • QuartzCore.framework for Mono Develop
  • RestKit - RKRequestDelegate does not exist
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Revoking OAuth Access Token Results in 404 Not Found
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • Django query for large number of relationships
  • reshape alternating columns in less time and using less memory
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?