Code Monkey home page Code Monkey logo

cloth's Introduction

A set of tasks for use with Fabric and EC2.

Installation

Now available on PyPi at http://pypi.python.org/pypi/cloth. Installation is therefore as simple as:

pip install cloth

Configuration

Export your EC2 credntials as environment variables.

export AWS_EC2_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=<your-access-key>
export AWS_SECRET_ACCESS_KEY=<your-secret-key>

Usages

To use just import some or all of the tasks into your fabric file. Or create a blank fabfile.py with the following contents.

#! /usr/bin/env python
from cloth.tasks import *

This will give you a good few commands.

⚡ fab -l
Available commands:

  all         All nodes
  free        Show memory stats
  list        List EC2 name and public and private ip address
  nodes       Select nodes based on a regular expression
  preview     Preview nodes
  production  Production nodes
  updates     Show package counts needing updates
  upgrade     Upgrade packages with apt-get
  uptime      Show uptime and load

Of most interest should be the 'all' and 'nodes' tasks. These allow you to load EC2 instances for further command running.

⚡ fab all list

The above should list all of your EC2 instances including the name and public and private ip addresses.

⚡ fab nodes:"^production.*" list

The above should list all of your EC2 instances that start with 'production'. This takes a regex as the argument so you can get whatever instances you like.

⚡ fab all uptime

As an example of running a command on a set of EC2 instances try the above. This should show the uptime and load averages for all your EC2 instances. Use -P as well to have that happen in parallel.

Opinionated Tasks

I generally use a convention for the names of my EC2 machines, in particular:

<platform>-<role>-<unique-identifier>

The production and preview tasks simple filter for those with a platform value of production or preview. More interesting is that roles are being set based on the second part of the name. For instance if I have a set of instances called:

  • production-backend-1
  • production-backend-2
  • production-backend-3
  • production-proxy
  • production-database

I could write a task like so:

@task
@roles('backend')
def passenger():
    "Show details about passenger performance"
    sudo('passenger-memory-stats')
    sudo('passenger-status')

The run that task with:

⚡ fab all passenger

That task would only be run on the three backend instances.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.