espenak / awsfabrictasks

Other
84 stars 26 forks source link

Multitag Support #11

Closed imlucas closed 10 years ago

imlucas commented 11 years ago

This also fixes the @ec2instance deco to behave like everything else.

New stuff:

Allow specifying multiple tags and region on @ec2instance

from fabric.api import task, env
from awsfabrictasks.decorators import ec2instance

@task
@ec2instance(tags={'Environment': 'production', 'Service Name': 'pythonapp'}, region='us-east-1')
def run_on_production_pythonapp_instances():
    run('whoami')

Allow defining dynamically populated role defs. I find this to be a lot nicer than specifying key pairs to --ec2tags every time.

from fabric.api import task, env
from awsfabrictasks import expand_roledefs

env.roledefs.update({
    'prod_web': {
        'ec2:tagged': {
            'Environment': 'production',
            'Service Name': 'pythonapp',
            'region': 'us-east-1'
        }
    },
    'prod_celeryworkers': {
        'ec2:tagged': {
            'Environment': 'production',
            'Service Name': 'worker',
            'region': 'us-east-1'
        }
    },
    'prod_celerybeat': {
        'ec2:tagged': {
            'Environment': 'production',
            'Service Name': 'celerybeat',
            'region': 'us-east-1'
        }
    },
    'all_prod': {
        'ec2:tagged': {
            'Environment': 'production',
            'region': 'us-east-1'
        }
    }
})

expand_roledefs()

@roles('prod_web')
def run_on_prod_pythonapp():
    run('whoami')

@roles('prod_celeryworkers')
def restart_celeryworkers():
    run('supervisorctl restart celery:celeryworkers:*')
espenak commented 11 years ago

I am very very sorry about not replying to this earlier. The notification must have been lost in the mass of email during my summer vacation.

Looks like a very useful addition to the library.

I have a lot of work that needs to be completed by the end of this week, but I will test your pull request as soon as I have some time.

imlucas commented 11 years ago

No worries. Been using this patch almost daily to manage 75+ instances since I sent the initial PR so I think it's working pretty well :p excited to see some new stuff coming soon!

On Monday, August 19, 2013, Espen Angell Kristiansen wrote:

I am very very sorry about not replying to this earlier. The notification must have been lost in the mass of email during my summer vacation.

Looks like a very useful addition to the library.

I have a lot of work that needs to be completed by the end of this week, but I will test your pull request as soon as I have some time.

— Reply to this email directly or view it on GitHubhttps://github.com/espenak/awsfabrictasks/pull/11#issuecomment-22861436 .

imlucas commented 11 years ago

Any updates on this?