fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Providing a fallback for roles at runtime


From: Michael Gliwinski
Subject: Re: [Fab-user] Providing a fallback for roles at runtime
Date: Thu, 19 Dec 2013 11:33:25 +0000
User-agent: KMail/4.7.3 (Linux/3.0.0-32-generic; KDE/4.7.4; x86_64; ; )

On Thursday 19 Dec 2013 08:44:15 Paul Walsh wrote:
...
> "execute this task on db if db is in roles, otherwise, execute on default."
> 
> So, to achieve that, I tried:
> 
> import utilities
> 
> @roles(utilities.get_role('db'))
> @task
> def drop():
>     utilities.alert(u'Dropping the database.')
>     run('dropdb {name}'.format(name=env.db_name))
> 
> 
> # utilities.py
> def get_role(target_role):
>     if target_role in env.roles:
>         return target_role
>     else:
>         return 'default'
> 
> 
> However, the task still attempts to run on roles['default']. I'm diving in
> but I'm also wondering if there is another way I could, in the fabfile
> itself, dynamically set the role for a task like this.

I'm not sure how you set env.roles, but note that utilities.get_role will be 
executed when your fabfile is loaded.

Roles can actually be callables, so you could do something like:

  def db_or_default():
      if ...: return ['5.6.7.8']
      return env.roledefs['default']

  env.roledefs = {'default': ['1.2.3.4'], 'db': db_or_default}


**********************************************************************************************
The information in this email is confidential and may be legally privileged.  
It is intended solely for the addressee and access to the email by anyone else 
is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution or 
any action taken or omitted to be taken in reliance on it, is prohibited and 
may be unlawful.
When addressed to our clients, any opinions or advice contained in this e-mail 
are subject to the terms and conditions expressed  in the governing client 
engagement leter or contract.
If you have received this email in error please notify address@hidden

John Henderson (Holdings) Ltd
Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, 
BT36 4RT.
Registered in Northern Ireland
Registration Number NI010588
Vat No.: 814 6399 12
*********************************************************************************




reply via email to

[Prev in Thread] Current Thread [Next in Thread]