Example #1
0
def test_decorator_incompatibility_on_task():
    from fabric.decorators import task, hosts, runs_once, roles
    def foo(): return "foo"
    foo = task(foo)

    # since we aren't setting foo to be the newly decorated thing, its cool
    hosts('me@localhost')(foo)
    runs_once(foo)
    roles('www')(foo)
Example #2
0
def test_decorator_incompatibility_on_task():
    from fabric.decorators import task, hosts, runs_once, roles
    def foo(): return "foo"
    foo = task(foo)

    # since we aren't setting foo to be the newly decorated thing, its cool
    hosts('me@localhost')(foo)
    runs_once(foo)
    roles('www')(foo)
Example #3
0
def hosts(appname, vms=None):
    """hosts(appname, vms=None)

    Run a task on *vms* in application *appname*.

    This function should be used as a decorator on a Fabric task. For example::

      @ravello.hosts('production', 'web')
      def deploy():
          # deploy to VM 'web' here

    Which is identical to::

      @hosts(ravello.lookup('production', 'web'))
      def deploy():
          # deploy to VM 'web' here

    Note that this decorator will do the lookup at the time the decorator is
    called. This lookup requires a Ravello API connection. You must either have
    ``env.ravello_api_user`` and ``env.ravello_api_password`` set, or you
    will be prompted for the API username and password. In case you want to do
    the lookup later, use :func:`lookup` directly and assign the return value
    to ``env.hosts``.
    """
    hosts = lookup(apppname, vms)
    return fab.hosts(*hosts)
 def selectively_attach(func):
     if not env.roles and not env.hosts:
         return roles(*role_list)(func)
     else:
         if env.hosts:
             func = hosts(*env.hosts)(func)
         if env.roles:
             func = roles(*env.roles)(func)
         return func
Example #5
0
def test_decorator_closure_hiding():
    """
    @task should not accidentally destroy decorated attributes from @hosts/etc
    """
    from fabric.decorators import task, hosts
    def foo():
        print(env.host_string)
    foo = task(hosts("me@localhost")(foo))
    eq_(["me@localhost"], foo.hosts)
Example #6
0
def test_decorator_closure_hiding():
    from fabric.decorators import task, hosts
    def foo(): print env.host_string
    foo = hosts("me@localhost")(foo)
    foo = task(foo)

    # this broke in the old way, due to closure stuff hiding in the
    # function, but task making an object
    eq_(["me@localhost"], foo.hosts)
Example #7
0
def test_decorator_closure_hiding():
    """
    @task should not accidentally destroy decorated attributes from @hosts/etc
    """
    from fabric.decorators import task, hosts
    def foo():
        print((env.host_string))
    foo = task(hosts("me@localhost")(foo))
    eq_(["me@localhost"], foo.hosts)
Example #8
0
 def selectively_attach(func):
     """Only decorate if nothing specified on command line"""
     # pylint: disable=W0142
     if not env.roles and not env.hosts:
         return roles(*role_list)(func)
     else:
         if env.hosts:
             func = hosts(*env.hosts)(func)
         if env.roles:
             func = roles(*env.roles)(func)
         return func
Example #9
0
 def selectively_attach(func):
     """Only decorate if nothing specified on command line"""
     # pylint: disable=W0142
     if not env.roles and not env.hosts:
         return roles(*role_list)(func)
     else:
         if env.hosts:
             func = hosts(*env.hosts)(func)
         if env.roles:
             func = roles(*env.roles)(func)
         return func
Example #10
0
    def setup_default_hosts(self):
        default_prod_host = env['prod']['hosts'][0]
        default_local_host = env['local']['hosts'][0]

        self.insert_db = hosts(self.insert_db, default_local_host)
        self.dump_fetch = hosts(self.dump_fetch, default_prod_host)
        self.dump_fetch = hosts(self.dump_fetch, default_prod_host)
        self.fetch = hosts(self.fetch, default_prod_host)
        self.dump = hosts(self.dump, default_prod_host)
        self.migrate = hosts(self.migrate, default_local_host)
        pass
Example #11
0
    def setup_default_hosts(self):
        default_prod_host = env['prod']['hosts'][0]
        default_local_host = env['local']['hosts'][0]

        self.insert_db = hosts(self.insert_db, default_local_host)
        self.dump_fetch = hosts(self.dump_fetch, default_prod_host)
        self.dump_fetch = hosts(self.dump_fetch, default_prod_host)
        self.fetch = hosts(self.fetch, default_prod_host)
        self.dump = hosts(self.dump, default_prod_host)
        self.migrate = hosts(self.migrate, default_local_host)
        pass
Example #12
0
    def __init__(self, hosts=(), roles=(), runs_once=False, **kw):
        super(ManagedTask, self).__init__()
        if 'name' in kw:
            self.name = kw['name']
        else:
            if hasattr(self.__class__, 'name'):
                self.name = getattr(self.__class__, 'name')
            if self.name == 'undefined':
                self.name = self.__class__.__name__.lower()
        self._decorator = lambda x: x
        if roles:
            self._decorator = lambda x: fab_api.roles(roles)(x)
        if hosts:
            self._decorator = lambda x: fab_api.hosts(hosts)(x)
        if runs_once:
            self._decorator = lambda x: fab_api.runs_once()(x)

        for _, f in self.getCommands().items():
            setattr(self, f, self._decorator(getattr(self, f)))
        self.__createTasks()
Example #13
0
def classes():
    """List available classes"""
    for name in sorted(env.roledefs.classes):
        hosts = env.roledefs['class-%s' % name]
        print("%-30.30s %s" % (name, len(hosts())))
Example #14
0
""" 
using fabric as a library without having to call the 
"""

from fabric.api import run, execute, hosts


@hosts('[email protected]:22')
def return_user():
    """ Runs whoami on remote host """
    run('whoami')


if __name__ == '__main__':
    execute(return_user)

    # Can also execute arbitrary commands and save the output
    out = execute(
        hosts('*****@*****.**')(lambda: run('uname -a')))
    print(out)
Example #15
0
from fabric.api import hosts
from fabfile import EyeCandy
from fabfile.FabHacks import maintask

setenv = maintask(hosts('localhost')(EyeCandy.setenv))

Example #16
0
""" 
using fabric as a library without having to call the 
"""

from fabric.api import run,execute,hosts



@hosts('[email protected]:22')
def return_user() : 
	""" Runs whoami on remote host """
	run('whoami')

if __name__ == '__main__' :
	execute(return_user)
	
	# Can also execute arbitrary commands and save the output
	out = execute(hosts('*****@*****.**')(lambda : run('uname -a')))
	print(out)
Example #17
0
def vdcs():
    """List available virtual datacentres"""
    for name in sorted(env.roledefs.vdcs):
        hosts = env.roledefs['vdc-%s' % name]
        print("%-30.30s %s" % (name, len(hosts())))
Example #18
0
def classes():
    """List available classes"""
    for name in sorted(env.roledefs.classes):
        hosts = env.roledefs['class-%s' % name]
        print("%-30.30s %s" % (name, len(hosts())))
Example #19
0
def vdcs():
    """List available virtual datacentres"""
    for name in sorted(env.roledefs.vdcs):
        hosts = env.roledefs['vdc-%s' % name]
        print("%-30.30s %s" % (name, len(hosts())))