Chef-like functionality for Fabric

Related tags

DevOps Tools cuisine
Overview
           /      /
 ___         ___    ___  ___
|    |   )| |___ | |   )|___)
|__  |__/ |  __/ | |  / |__

-- Chef-like functionality for Fabric

About

Fabric is an incredible tool to automate administration of remote machines. As Fabric's functions are rather low-level, you'll probably quickly see a need for more high-level functions such as add/remove users and groups, install/upgrade packages, etc.

Cuisine is a small set of functions that sit on top of Fabric, to abstract common administration operations such as file/dir operations, user/group creation, package install/upgrade, making it easier to write portable administration and deployment scripts.

Cuisine's features are:

  • Small, easy to read, a single file API: <object>_<operation>() e.g. dir_exists(location) tells if there is a remote directory at the given location.
  • Covers file/dir operations, user/group operations, package operations
  • Text processing and template functions
  • All functions are lazy: they will actually only do things when the change is required.

Installation

Cuisine is on PyPI so you can either use easy_install -U cuisine or pip install cuisine to install it. Otherwise, you can download the source from GitHub and run python setup.py install.

Cuisine requires Python 2.7, and has not been tested with Python 3 yet.

How to get started

Open up a python shell and type:

import cuisine

Cuisine is designed to be a flat-file module, where all functions are prefixed by the type of functionality they offer (e.g., file for file operations, user for user operations). The available groups are:

text_*
Text-processing functions
file_*
File operations
dir_*
Directory operations
package_*
Package management operations
command_*
Shell commands availability
user_*
User creation commands
group*
Group creation commands
mode_*
Configures cuisine's behaviour within the current session.
select_*
Selects a specific option, such as package back-end (apt, yum, zypper, or pacman)

If you're using an interactive Python shell such as IPython you can easily browse the available functions by using tab-completion.

In [2]: cuisine.file_
cuisine.file_append       cuisine.file_is_file      cuisine.file_unlink
cuisine.file_attribs      cuisine.file_is_link      cuisine.file_update
cuisine.file_attribs_get  cuisine.file_link         cuisine.file_upload
cuisine.file_ensure       cuisine.file_local_read   cuisine.file_write
cuisine.file_exists       cuisine.file_read
cuisine.file_is_dir       cuisine.file_sha256

As the functions are prefixed by they type of functionality, it is very easy to get started using an interactive shell.

If you would like to use cuisine without using a fabfile, you can call the mode_local() function.

import cuisine
cuisine.mode_local()
print cuisine.run("echo Hello")

alternatively, you can also directly connect to a server

import cuisine
cuisine.connect("my.server.com")
print cuisine.run("echo Hello")

If you want to use cuisine within a fabfile, simply create a fabfile with the following content:

from cuisine import *

def setup():
    group_ensure("remote_admin")
    user_ensure("admin")
    group_user_ensure("remote_admin", "admin")

Troubleshooting

If you are encoutering problems, please check the following:

  • The user@host is running an SH-compatible shell (sh, dash, bash, zsh should work)
  • The system has openssl base64, md5sum and sha1sum commands in addition to the basic UNIX ones.

If you still have a problem, simply file a bug report here https://github.com/sebastien/cuisine/issues

Right now, cuisine is tested on Ubuntu. Some contributors use it on RHEL and CentOS. If you use on a different system, let us know if it works!

Contributing specific implementations

Cuisine was originally developed as a Debian/Ubuntu-centric tool, but can easily be adapted to other distributions or Unix flavor, the only caveat being that the shell is expected to be bash-compatible.

If you want to implement a specific variant of some functions for a specific platform, you should do the following:

  1. Open the cuisine.py source and look for the definition of the function that you would like to specialize.
  2. If the function is decorated by '@dispatch', it means it already supports specific back-ends (see package_* functions), and you can proceed to the next step. Otherwise, you can either file a ticket on Github or read the source and mimic what we've done for package_*
  3. Create a specific version of the decorated function by creating a new function with the same name, suffixed by your specific backend name. For instance, if you'd like to create a yum backend to package_ensure, you would need to create a function package_ensure_yum with the same arguments as package_ensure
  4. Once you've created your specific functions, make sure that you have a select_* matching your function group. For the package_* functions, this would be select_package.
  5. Look for the supported variable in the select_* and add your backend suffix to it (in our example, this would be yum)

To use a specific backend implementation of a set of features, use the select_* functions.

# To use the 'apt' backend
cuisine.select_package("apt")
# To see the available backends
print cuisine.select_package()

Modules

Cuisine-PostgreSQL http://pypi.python.org/pypi/cuisine-postgresql/

More?

If you want more information, you can:

Comments
  • Methods for PIP and NPM

    Methods for PIP and NPM

    I'm using Cuisine to deploy an app using both PIP for python packages and NPM for node packages and I'm wondering what your thoughts are on the plan regarding these. Do you write your own methods to ensure these packages in Fabric and use them alongside Cuisine or is this something that should be integrated into Cuisine?

    opened by gudbergur 17
  • Make Cuisine work on RHEL compatible systems with yum

    Make Cuisine work on RHEL compatible systems with yum

    I am currently using and testing Cuisine on CentOS, and have rewritten package commands to use yum instead. Since I'd like to contribute the code back, I was thinking about implementing both for apt-get and yum via some global config and perhaps package abstraction, but then I realized that package_* defs ARE a form of abstraction. So other than if-elif branches, any suggestions how to support more than one package manager?

    opened by ghost 17
  • Host documentation on ReadTheDocs

    Host documentation on ReadTheDocs

    Hi Sebastien

    I've noticed you pushed Sphinx-generated docs to the repo, would you consider hosting it at ReadTheDocs instead? I like this approach for two reasons:

    1. It's easy to access from the browser -- Github doesn't preview HTML pages, afaik
    2. One can allways build a local copy with sphinx-build

    What do you think?

    opened by superbobry 12
  • PEP8, consistency and a few bug fixes.

    PEP8, consistency and a few bug fixes.

    Here are a few commits to give cuisine.py more consistincy and pretty close to PEP8. The biggest ones are the Untabify and teh use 4 spaces for indent. All the others are pretty much dependent on these.

    I tried to break up the commits based on the PEP8 section that they applied and have attached any relevant PEP8 link into the commit messages.

    Let me know if this is too intrusive.

    opened by adamrt 9
  • Improve local mode

    Improve local mode

    This set of commits adds tests for some discrepancies between cuisine.run() and fabric.run() in local mode, then adds fixes for those discrepancies. Most changes have to do with wrapping commands the same way that fabric does so that various context managers and env variables get picked up and applied properly.

    opened by davehughes 9
  • Pip installs 0.0.1 instead of 0.0.4

    Pip installs 0.0.1 instead of 0.0.4

    Great work on this saved me doing something similar. I don't have time right now to provide fixes but wanted to give some feedback on bits that didn't work as I expected.

    Installing via pip/easy_install installed 0.0.1 rather than 0.0.4 not sure if this matters as it also didn't work when I tried

    from cuisine import *

    So I just included the cuisine.py file in the same dir as my fabfile.py and that works great.

    As the api docs are a bit lacking I started by using the presentation which is great btw. But then I found that there was a oh-my-zsh plugin at https://github.com/santiycr/oh-my-zsh/ which is a fork of the main oh-my-zsh and there is a pull request to bring the fab plugin into the main repo. I just added https://github.com/santiycr/oh-my-zsh/ as another git remote and merged the changes manually. This makes using cuisine really easy as the tab completion on fab command line now lists all the cuisine tasks and they are named well so its pretty easy to work out which one you want for something.

    Anyways great job.

    opened by cabbiepete 9
  • mode_sudo ought to be a context manager

    mode_sudo ought to be a context manager

    Rather than doing this:

    mode_sudo()
    # ... do stuff as superuser...
    mode_user()
    # ... do normal stuff...
    

    It would instead be nice to do this:

    with mode_sudo():
        # ... do stuff as superuser...
    # ... do normal stuff...
    

    This is more in line with how Fabric does similar things. It would probably be really easy with contextlib.

    opened by eykd 7
  • What is changed between version 0.7.6 and 0.7.7?

    What is changed between version 0.7.6 and 0.7.7?

    I can't find any changelog and our code stopped working correctly after upgrade to 0.7.7. It also does not work on 0.7.9.

    $ sudo pip install cuisine==0.7.6
    $ fab config.prod start
    [...] Executing task 'start'
    [...] sudo: service service1 start ; true
    ...
    Done.
    $ sudo pip install cuisine==0.7.7
    $ fab config.prod start
    [...] Executing task 'start'
    ERROR:root:service1: unrecognized service
    

    like it executes locally, not on remote machine

    opened by Tolsi 6
  • Issue/163

    Issue/163

    This is a first attempt to deal with issue #163. Tests with apt, pip and easy_install on Ubuntu 13.10 look fine.

    I did not adopt the other package managers to the new model (no testing possible).

    The CuisineResult class is not derived from str, as proposed, but implements a str method instead. We need to nail down if this is good enough.

    opened by troeger 6
  • ssh_authorize duplicates keys

    ssh_authorize duplicates keys

    I would expect ssh_authorize to be idempotent, but running it repeatedly results in duplicate keys in .ssh/authorized_keys.

    I attempted to rewrite it using something like file_update(keyf, lambda _: text_ensure_line(_, key)) but this produces duplicate lines as well.

    opened by eykd 6
  • file_write issue: relying on 'bzip2' is installed

    file_write issue: relying on 'bzip2' is installed

    When file_write is performed on a system on which 'bzip2' is not installed (like a vanilla Debain Squeeze), it will fail and leave the target file empty. This will also happen when the target file had content before. One way to solve this problem would be to perform package_ensure() on the target system first.

    opened by skoenig 5
  • Support for Fabric 2.x?

    Support for Fabric 2.x?

    One of the many changes for Fabric 2.x is removal of fabric.api. Maybe we can make cuisine compatible with both by trying to import from .api and falling back to fabric if it fails?

    opened by miketwo 1
  • Newline at end of updated text

    Newline at end of updated text

    Great tool, thanks!

    Function text_ensure_line doesn't add a newline at the end of the text. This is not ideal for e.g. updating configuration files which may need a final newline.

    This can be corrected by changing the final line to:

    return eol.join(res) + eol
    

    Please consider this. Thanks!

    opened by stefan-imp 0
  • file_upload() behavior for lcd context incompatible with fabric put()

    file_upload() behavior for lcd context incompatible with fabric put()

    The put() method in fabric honors lcd context, but file_upload() does not. This makes file_upload() fail whenever an lcd context is in place because the either file_upload() code or put() will use the wrong path.

    To reproduce this bug just do

    cd 'different_local_directory' with lcd('local_directory'): file_upload(target_path, 'some_file_in_local_directory')

    The relevant code from put is at fabric/operations.py:364

    I'd have written a patch, but the behavior of put() wrt paths is complex enough that it seems wrong to duplicate it in file_upload() w/o refactoring fabric to expose it all for reuse.

    opened by elgow 4
  • Bugfix for function process_find

    Bugfix for function process_find

    1. Modified function process_find to display pid id if the pid is less than 3 digits:

      eg:

    ['', '416', '?', '00:00:00 udevd'] ['12305', '?', '00:00:00', 'udevd']

    After Modifications: ['416', '?', '00:00:00', 'udevd'] ['12305', '?', '00:00:00', 'udevd']

    2 . Extended functionality for strace of process eg : cuisine.process_strace(416)

    Output:


    ERROR:root:Process 416 attached ERROR:root:restart_syscall(<... resuming interrupted call ...>Process 416 detached ERROR:root: <detached ...>


    opened by kheshav 0
Owner
SΓ©bastien Pierre
SΓ©bastien Pierre
The low-level, core functionality of boto 3.

botocore A low-level interface to a growing number of Amazon Web Services. The botocore package is the foundation for the AWS CLI as well as boto3. On

the boto project 1.2k Jan 3, 2023
Manage your SSH like a boss.

--- storm is a command line tool to manage your ssh connections. features adding, editing, deleting, listing, searching across your SSHConfig. command

Emre YΔ±lmaz 3.9k Jan 3, 2023
Wubes is like Qubes but for Windows.

Qubes containerization on Windows. The idea is to leverage the Windows Sandbox technology to spawn applications in isolation.

NCC Group Plc 124 Dec 16, 2022
Oncall is a calendar tool designed for scheduling and managing on-call shifts. It can be used as source of dynamic ownership info for paging systems like http://iris.claims.

Oncall See admin docs for information on how to run and manage Oncall. Development setup Prerequisites Debian/Ubuntu - sudo apt-get install libsasl2-d

LinkedIn 928 Dec 22, 2022
Tools for writing awesome Fabric files

About fabtools includes useful functions to help you write your Fabric files. fabtools makes it easier to manage system users, packages, databases, et

null 1.3k Dec 30, 2022
Fabric mod where anyone can PR anything, concerning or not. I'll merge everything as soon as it works.

Guess What Will Happen In This Fabric mod where anyone can PR anything, concerning or not (Unless it's too concerning). I'll merge everything as soon

anatom 65 Dec 25, 2022
Utility for converting IP Fabric webhooks into a Teams format.

IP Fabric Webhook Integration for Microsoft Teams Setup IP Fabric Setup Go to Settings > Webhooks > Add webhook Provide a name URL will be: 'http://<Y

Community Fabric 1 Jan 26, 2022
Utility for converting IP Fabric webhooks into a Teams format.

IP Fabric Webhook Integration for Microsoft Teams and/or Slack Setup IP Fabric Setup Go to Settings > Webhooks > Add webhook Provide a name URL will b

Community Fabric 1 Jan 26, 2022
Utility for converting IP Fabric webhooks into a Teams format

IP Fabric Webhook Integration for Microsoft Teams and/or Slack Setup IP Fabric Setup Go to Settings > Webhooks > Add webhook Provide a name URL will b

Community Fabric 1 Jan 26, 2022
πŸ”© Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as β€” and yet conspicuously mis

Mahmoud Hashemi 6k Jan 6, 2023
πŸ”© Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as β€” and yet conspicuously mis

Mahmoud Hashemi 5.4k Feb 20, 2021
You like pytorch? You like micrograd? You love tinygrad! ❀️

For something in between a pytorch and a karpathy/micrograd This may not be the best deep learning framework, but it is a deep learning framework. Due

George Hotz 9.7k Jan 5, 2023
πŸ”© Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as β€” and yet conspicuously mis

Mahmoud Hashemi 6k Jan 4, 2023
A C-like hardware description language (HDL) adding high level synthesis(HLS)-like automatic pipelining as a language construct/compiler feature.

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆ

Julian Kemmerer 391 Jan 1, 2023
Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo

Django JET Modern template for Django admin interface with improved functionality Attention! NEW JET We are proud to announce completely new Jet. Plea

Geex Arts 3.4k Dec 29, 2022
An intuitive library to add plotting functionality to scikit-learn objects.

Welcome to Scikit-plot Single line functions for detailed visualizations The quickest and easiest way to go from analysis... ...to this. Scikit-plot i

Reiichiro Nakano 2.3k Dec 31, 2022
A Python interface to AFL, allowing for easy injection of testcases and other functionality.

Fuzzer This module provides a Python wrapper for interacting with AFL (American Fuzzy Lop: http://lcamtuf.coredump.cx/afl/). It supports starting an A

Shellphish 614 Dec 26, 2022
A curses based mpd client with basic functionality and album art.

Miniplayer A curses based mpd client with basic functionality and album art. After installation, the player can be opened from the terminal with minip

Tristan Ferrua 102 Dec 24, 2022