user2114835
user2114835

Reputation:

fabric.api vs fabric.operations

I am new to Python and Fabric, using Fabric==1.10.1 and Python 2.7.6. I don't understand the difference between fabric.api and fabric.operations calls, both seem to be doing the same thing. Which one should I use in fabfile? One thing that I noticed is when I do fabric.api.reboot() then it does display message,

[127.0.0.1] out: Broadcast message from [email protected]
[127.0.0.1] out:
[127.0.0.1] out:    (/dev/pts/0) at 17:39 ...
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out: The system is going down for reboot NOW!
[127.0.0.1] out:

But when I use fabric.operations.reboot() it does not display any message.

Update: Actually seems fabric.operations.reboot() and fabric.api.reboot() produce the message.

Upvotes: 3

Views: 1228

Answers (1)

Morgan
Morgan

Reputation: 4131

You can use either, but fabric.api is specifically the better option. This is because it's where the other fabric modules are imported for simplicity's sake. See here:

$ cat fabric/api.py                                                                                                                                                                                                                                          (env: selenium)
"""
Non-init module for doing convenient * imports from.

Necessary because if we did this in __init__, one would be unable to import
anything else inside the package -- like, say, the version number used in
setup.py -- without triggering loads of most of the code. Which doesn't work so
well when you're using setup.py to install e.g. ssh!
"""
from fabric.context_managers import (cd, hide, settings, show, path, prefix,
    lcd, quiet, warn_only, remote_tunnel, shell_env)
from fabric.decorators import (hosts, roles, runs_once, with_settings, task,
        serial, parallel)
from fabric.operations import (require, prompt, put, get, run, sudo, local,
    reboot, open_shell)
from fabric.state import env, output
from fabric.utils import abort, warn, puts, fastprint
from fabric.tasks import execute

fabric.api is importing fabric.operations.reboot for you already.

Upvotes: 3

Related Questions