本文整理汇总了Python中fabric.api.task方法的典型用法代码示例。如果您正苦于以下问题:Python api.task方法的具体用法?Python api.task怎么用?Python api.task使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.api
的用法示例。
在下文中一共展示了api.task方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chef_query
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def chef_query(query, api=None, hostname_attr=DEFAULT_HOSTNAME_ATTR, environment=_default_environment):
"""A decorator to use an arbitrary Chef search query to find nodes to execute on.
This is used like Fabric's ``roles()`` decorator, but accepts a Chef search query.
Example::
from chef.fabric import chef_query
@chef_query('roles:web AND tags:active')
@task
def deploy():
pass
.. versionadded:: 0.2.1
"""
api = _api(api)
if api.version_parsed < Environment.api_version_parsed and environment is not None:
raise ChefAPIVersionError('Environment support requires Chef API 0.10 or greater')
rolename = 'query_'+query
env.setdefault('roledefs', {})[rolename] = Roledef(query, api, hostname_attr, environment)
return lambda fn: roles(rolename)(fn)
示例2: chef_tags
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def chef_tags(*tags, **kwargs):
"""A decorator to use Chef node tags to find nodes to execute on.
This is used like Fabric's ``roles()`` decorator, but accepts a list of tags.
Example::
from chef.fabric import chef_tags
@chef_tags('active', 'migrator')
@task
def migrate():
pass
.. versionadded:: 0.2.1
"""
# Allow passing a single iterable
if len(tags) == 1 and not isinstance(tags[0], six.string_types):
tags = tags[0]
query = ' AND '.join('tags:%s'%tag.strip() for tag in tags)
return chef_query(query, **kwargs)
示例3: dev
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def dev():
"""
Put as the first task on the command line to select dev environment.
For example: fab dev release_web_app
Put in this task all the environment specific variables and settings.
"""
env.hosts = ['dev.openconceptlab.com', ]
env.user = 'deploy'
env.web_domain = 'dev.openconceptlab.com'
env.api_domain = 'api.dev.openconceptlab.com'
env.OCL_API_TOKEN = os.environ.get('OCL_API_TOKEN')
env.OCL_ANON_API_TOKEN = os.environ.get('OCL_ANON_API_TOKEN')
env.random_string = _random_string(32)
# which sites.json file to load the django site object from.
env.site_spec = 'dev'
env.AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
env.AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
env.AWS_STORAGE_BUCKET_NAME = 'ocl-source-export-development'
示例4: production
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def production():
"""
Put as the first task on the command line to select production environment.
"""
env.hosts = ['www.openconceptlab.com', ]
env.user = 'deploy'
env.site_spec = 'prod'
env.web_domain = 'www.openconceptlab.com'
env.api_domain = 'api.openconceptlab.com'
env.OCL_API_TOKEN = 'dummy'
env.OCL_ANON_API_TOKEN = 'dummy'
env.random_string = _random_string(32)
env.AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
env.AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
env.AWS_STORAGE_BUCKET_NAME = 'ocl-source-export-production'
## HELPER FUNCTIONS
示例5: execute
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def execute(*args, **kwargs): # pragma: no cover
warnings.warn(
'fabricio.execute() is deprecated in favour of fabric.api.execute()',
DeprecationWarning,
)
warnings.warn(
'fabricio.execute() is deprecated and will be removed in v0.6, '
'use fabric.api.execute() instead',
RuntimeWarning, stacklevel=2,
)
try:
task, args = args[0], args[1:]
except IndexError:
raise TypeError('must provide task to execute')
default_name = '{command}.{task_name}({id})'.format(
command=fab.env.command,
task_name=getattr(task, 'name', task.__name__),
id=id(task),
)
with utils.patch(task, 'name', get_task_name(task) or default_name):
return fab.execute(task, *args, **kwargs)
示例6: __init__
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def __init__(self, callback, color=colors.yellow, title=None):
super(Infrastructure, self).__init__()
# We need to be sure that `default()` will be at first place
# every time when vars(self) is being invoked.
# This is necessary to exclude `default` from the list of task
# because of it's already there as default task.
# See `fabric.main.extract_tasks()` for details
self.__dict__ = utils.PriorityDict(self.__dict__, priority=['default'])
default, confirm = self.default, self.confirm
self.callback = callback
self.name = getattr(callback, '__name__', self.name)
self.title = color(title or self.name)
self.__doc__ = (self.__doc__ or '').format(**self.__dict__)
default.__doc__ = (default.__doc__ or '').format(**self.__dict__)
confirm.__doc__ = (confirm.__doc__ or '').format(**self.__dict__)
# enable "module" behaviour in task mode
self.use_task_objects = not is_task_mode()
示例7: chef_environment
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def chef_environment(name, api=None):
"""A Fabric task to set the current Chef environment context.
This task works alongside :func:`~chef.fabric.chef_roledefs` to set the
Chef environment to be used in future role queries.
Example::
from chef.fabric import chef_environment, chef_roledefs
env.roledefs = chef_roledefs()
.. code-block:: bash
$ fab env:production deploy
The task can be configured slightly via Fabric ``env`` values.
``env.chef_environment_task_alias`` sets the task alias, defaulting to "env".
This value must be set **before** :mod:`chef.fabric` is imported.
``env.chef_environment_validate`` sets if :class:`~chef.Environment` names
should be validated before use. Defaults to True.
.. versionadded:: 0.2
"""
if env.get('chef_environment_validate', True):
api = _api(api)
chef_env = Environment(name, api=api)
if not chef_env.exists:
raise ChefError('Unknown Chef environment: %s' % name)
env['chef_environment'] = name
示例8: make_tasks_for_envs
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def make_tasks_for_envs(available_envs):
tasks = {}
for env_name in available_envs:
environment = get_environment(env_name)
if not environment.meta_config.bare_non_cchq_environment:
tasks[env_name] = task(alias=env_name)(functools.partial(_setup_env, env_name))
tasks[env_name].__doc__ = environment.proxy_config['SITE_HOST']
return tasks
# Automatically create a task for each environment
示例9: run_task
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def run_task(taskname, *args, **kwargs):
task = globals().get(taskname)
if isinstance(task, Task):
execute(task, *args, **kwargs)
else:
raise Exception("Invalid task: " + repr(taskname))
示例10: define_preset_tasks
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def define_preset_tasks(module, config):
''' Define tasks for the configured deployment preset. '''
deployment = deployer.import_preset(config)
# Now that we have deployment preset set, import all the tasks.
for (task_name, func) in deployment.__dict__.iteritems():
if not _is_task(func):
continue
# Set a new task named as the stage name in the main fabfile module.
setattr(module, task_name, func)
示例11: define_stage_tasks
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def define_stage_tasks(module, config):
''' Define tasks for the stages dynamically. '''
for (stage_name, _) in config['stages'].iteritems():
task_func = task(name=stage_name)(configure_env)
task_func.__doc__ = 'Configures the {} server environment.'.format(
stage_name)
# Set a new task named as the stage name in the main fabfile module.
setattr(module, stage_name, task_func)
示例12: staging
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def staging():
"""
Put as the first task on the command line to select staging environment.
"""
env.hosts = ['staging.openconceptlab.com', ]
env.user = 'deploy'
env.web_domain = 'staging.openconceptlab.com'
env.api_domain = 'api.staging.openconceptlab.com'
env.OCL_API_TOKEN = os.environ.get('OCL_API_TOKEN')
env.OCL_ANON_API_TOKEN = os.environ.get('OCL_ANON_API_TOKEN')
env.random_string = _random_string(32)
env.site_spec = 'stage'
env.AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
env.AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
env.AWS_STORAGE_BUCKET_NAME = 'ocl-source-export-staging'
示例13: install_root_key
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def install_root_key():
"""Install your SSH key for root. One time task.
"""
with settings(user='root'):
print yellow('setting up SSH for root')
ssh_path = '/root/.ssh'
if not files.exists(ssh_path, verbose=True):
run('mkdir %s' % ssh_path)
run('chmod 700 %s' % ssh_path)
key_text = _read_key_file('~/.ssh/id_rsa.pub')
files.append('%s/authorized_keys' % ssh_path, key_text)
示例14: add_deploy_user
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def add_deploy_user():
"""Create the deploy user account, one time task.
The deploy user is used for almost all processes.
Your SSH key is pushed so that you can login via ssh keys.
"""
username = 'deploy'
with settings(user='root'):
# Create the user, no password
fastprint('adding the %s user account...' % username)
run('useradd -m -s /bin/bash %s' % username)
run('adduser %s sudo' % username)
# Allow this user to sudo without password
# really should list specific command (the last ALL)
files.append('/etc/sudoers.d/%s' % username,
'%s ALL=(ALL:ALL) NOPASSWD: ALL' % username)
fastprint('setting up SSH')
ssh_path = '/home/%s/.ssh' % username
if not files.exists(ssh_path, verbose=True):
run('mkdir %s' % ssh_path)
run('chmod 700 %s' % ssh_path)
key_text = _read_key_file('~/.ssh/id_rsa.pub')
files.append('%s/authorized_keys' % ssh_path, key_text)
run('chown -R %s:%s %s' % (username, username, ssh_path))
示例15: build_api_app
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import task [as 别名]
def build_api_app():
""" Build the API app, one time task. """
build_app('ocl_api', repo_name='oclapi', no_git=True)
checkout_api_app(do_pip=True)
create_api_database()
## OTHER COMMANDS