Disconnecting from host with Python Fabric when using the API

The main.py for fabric has this:

from fabric.state import commands, connections

for key in connections.keys():
    if state.output.status:
        print "Disconnecting from %s..." %, denormalize(key), connections[key].close()

fabric.state.connections is a dict with the value being: paramiko.SSHClient

So off I go to close those.


If you don't want to have to iterate through all open connections, fabric.network.disconnect_all() is what you're looking for. The docstring reads

""" Disconnect from all currently connected servers. Used at the end of fab's main loop, and also intended for use by library users. """

Tags:

Python

Fabric