当前位置: 首页>>代码示例>>Python>>正文


Python api.run函数代码示例

本文整理汇总了Python中refabric.api.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install_solr

def install_solr():
    with sudo():
        version = blueprint.get('version')
        version_tuple = tuple(map(int, version.split('.')))

        archive = 'solr-{}.tgz'.format(version)
        if version_tuple < (4, 1, 0):
            archive = 'apache-{}'.format(archive)
        url = 'https://archive.apache.org/dist/lucene/solr/{}/{}'.format(version, archive)

        with cd('/tmp'):
            info('Download {} ({})', 'Solr', version)
            run('wget {}'.format(url))

            info('Extracting archive...')
            with silent():
                run('tar xzf {}'.format(archive))
                solr_version_dir = os.path.splitext(archive)[0]
                solr_version_path = os.path.join('/usr', 'share', solr_version_dir)
                debian.chmod(solr_version_dir, 755, 'solr', 'solr', recursive=True)
                if files.exists(solr_version_path):
                    info('Found same existing version, removing it...')
                    debian.rm(solr_version_path, recursive=True)
                debian.mv(solr_version_dir, '/usr/share/')
                debian.ln(solr_version_path, solr_home)
                debian.rm(archive)
开发者ID:Sportamore,项目名称:blues,代码行数:26,代码来源:solr.py

示例2: dump

def dump(schema=None, ignore_tables=''):
    """
    Dump and download a schema.

    :param schema: Specific shema to dump and download.
    :param ignore_tables: Tables to skip, separated by | (pipe)
    """
    if not schema:
        schemas = blueprint.get('schemas', {}).keys()
        for i, schema in enumerate(schemas, start=1):
            print("{i}. {schema}".format(i=i, schema=schema))
        valid_indices = '[1-{}]+'.format(len(schemas))
        schema_choice = prompt('Select schema to dump:', default='1', validate=valid_indices)
        schema = schemas[int(schema_choice)-1]

    now = datetime.now().strftime('%Y-%m-%d')
    output_file = '/tmp/{}_{}.backup.gz'.format(schema, now)
    filename = os.path.basename(output_file)

    info('Dumping schema {}...', schema)
    extra_args = []
    for table in ignore_tables.split('|'):
        extra_args.append('--ignore-table={}.{}'.format(schema, table))

    dump_cmd = 'mysqldump {} {} | gzip > {}'.format(schema, ' '.join(extra_args), output_file)

    run('sudo su root -c "{}"'.format(dump_cmd))
    info('Downloading dump...')
    local_file = '~/%s' % filename
    fabric.contrib.files.get(output_file, local_file)

    with sudo(), silent():
        debian.rm(output_file)

    info('New smoking hot dump at {}', local_file)
开发者ID:5monkeys,项目名称:blues,代码行数:35,代码来源:percona.py

示例3: update_modules

def update_modules(beat):
    changes = []

    # Get desired state
    desired_modules = set(blueprint.get('{}.modules'.format(beat), []))

    # Get current state
    with silent():
        module_files = run('find /etc/{}/modules.d -iname "*.yml"'.format(beat)).split()
        enabled_modules = {os.path.basename(module).split('.')[0] for module in module_files}

    # Disable extra services
    for extra in enabled_modules - desired_modules:
        info('Disabling {} module: {}', beat, extra)
        changes.append(extra)

        with silent(), sudo():
            run('{} modules disable {}'.format(beat, extra))

    # Enable services
    for missing in desired_modules - enabled_modules:
        info('Enabling {} module: {}', beat, missing)
        changes.append(missing)

        with silent(), sudo():
            run('{} modules enable {}'.format(beat, missing))

    return changes
开发者ID:Sportamore,项目名称:blues,代码行数:28,代码来源:beats.py

示例4: send_deploy_event

def send_deploy_event():

    newrelic_key = blueprint.get('newrelic_key', None)
    app_name = blueprint.get('app_name', None)

    if newrelic_key and app_name:
        url = 'https://api.newrelic.com/deployments.xml'
        headers = {'x-api-key': newrelic_key}
        with cd(python_path()):
            tag = run('git describe --tags')
            commit_hash = run('git rev-parse HEAD')

        deployer = git.get_local_commiter()

        payload = {
                'deployment[app_name]': app_name,
                # 'application_id': '1234567',
                'deployment[description]': tag,
                'deployment[revision]': commit_hash,
                # 'deployment[changelog]': changes,
                'deployment[user]': deployer,
            }

        response = requests.post(url, data=payload, headers=headers)
        info(response.text)
    else:
        info('No key found')

#http://gc-taylor.com/blog/2013/02/11/fabric-task-for-notifying-new-relic-code-deploy/#sthash.5AnhN3An.sfju
开发者ID:zalphi,项目名称:blues,代码行数:29,代码来源:newrelic.py

示例5: install

def install():
    with sudo():
        # Generate a root password and save it in root home
        root_conf_path = '/root/.my.cnf'
        if not fabric.contrib.files.exists(root_conf_path):
            root_pw = generate_password()
            blueprint.upload('root_my.cnf', '/root/.my.cnf', {'password': root_pw})
            debian.chmod('/root/.my.cnf', mode=600)
        else:
            # TODO: use fabric.operations.get instead of cat when up to date with upstream
            with silent():
                output = run('cat {}'.format(root_conf_path))
            fd = StringIO(output)
            config_parser = ConfigParser.RawConfigParser()
            config_parser.readfp(fd)
            root_pw = config_parser.get('client', 'password')

        # Install external PPA
        info('Adding apt key for {}', __name__)
        run("apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A")

        info('Adding apt repository for {}', __name__)
        debian.add_apt_repository('http://repo.percona.com/apt trusty main')
        debian.apt_get('update')

        # Percona/MySQL base dependencies
        dependencies = (
            'percona-server-server',
            'percona-server-client',
            'libmysqlclient-dev',
            'mysqltuner'
        )

        # Configure debconf to autoset root password on installation prompts
        server_package = dependencies[0]
        debian.debconf_communicate('PURGE', server_package)
        with silent():
            debian.debconf_set_selections(
                '{}/root_password password {}'.format(server_package, root_pw),
                '{}/root_password_again password {}'.format(server_package, root_pw)
            )

        # Install package
        info('Installing {}', __name__)
        debian.apt_get('install', *dependencies)
        debian.debconf_communicate('PURGE', server_package)

        # Auto-answer mysql_secure_installation prompts
        prompts = {
            'Enter current password for root (enter for none): ': root_pw,
            'Change the root password? [Y/n] ': 'n',
            'Remove anonymous users? [Y/n] ': 'Y',
            'Disallow root login remotely? [Y/n] ': 'Y',
            'Remove test database and access to it? [Y/n] ': 'Y',
            'Reload privilege tables now? [Y/n] ': 'Y'

        }
        # Run mysql_secure_installation to remove test-db and remote root login
        with settings(prompts=prompts):
            run('mysql_secure_installation')
开发者ID:5monkeys,项目名称:blues,代码行数:60,代码来源:percona.py

示例6: install

def install():
    with sudo():
        info('Install python dependencies')
        debian.apt_get('install', 'python-dev', 'python-setuptools')
        run('easy_install pip')
        run('touch {}'.format(pip_log_file))
        debian.chmod(pip_log_file, mode=777)
        pip('install', 'setuptools', '--upgrade')
开发者ID:gelbander,项目名称:blues,代码行数:8,代码来源:python.py

示例7: flush

def flush():
    """
    Delete all cached keys
    """
    info('Flushing Memcached...')
    with sudo(), silent():
        run('echo "flush_all" | /bin/netcat -q 2 127.0.0.1 11211')
    info('Down the drain!')
开发者ID:gelbander,项目名称:blues,代码行数:8,代码来源:memcached.py

示例8: pip_sync

def pip_sync(manifest, quiet=False):
    pip('install', 'pip-tools', quiet=quiet)

    options = ""
    if quiet:
        options += ' -q'

    run('pip-sync{} {}'.format(options, manifest), pty=False)
开发者ID:Sportamore,项目名称:blues,代码行数:8,代码来源:python.py

示例9: configure

def configure():
    """
    Configure newrelic server
    """

    with sudo():
        info('Adding license key to config')
        newrelic_key = blueprint.get('newrelic_key', None)
        run('nrsysmond-config --set license_key={}'.format(newrelic_key))
开发者ID:zalphi,项目名称:blues,代码行数:9,代码来源:newrelic.py

示例10: create_server_ssl_cert

def create_server_ssl_cert():
    with sudo():
        info('Generating SSL certificate...')
        debian.mkdir('/etc/pki/tls/certs')
        debian.mkdir('/etc/pki/tls/private')
        with cd('/etc/pki/tls'):
            key = 'private/logstash-forwarder.key'
            crt = 'certs/logstash-forwarder.crt'
            run('openssl req -x509 -batch -nodes -days 3650 -newkey rsa:2048 -keyout {} -out {}'.format(key, crt))
开发者ID:gelbander,项目名称:blues,代码行数:9,代码来源:logstash.py

示例11: ctl

def ctl(command=None):
    """
    Run rabbitmqctl with given command
    :param command: Control command to execute
    """
    if not command:
        abort('No command given, $ fab rabbitmq.ctl:stop_app')

    with sudo():
        run('rabbitmqctl {}'.format(command))
开发者ID:Sportamore,项目名称:blues,代码行数:10,代码来源:rabbitmq.py

示例12: reload

    def reload(self, vassals=None):
        """
        Touch reload specified vassals

        :param vassals: Vassals to reload
        """
        for vassal_ini in vassals or self.list_vassals():
            vassal_ini_path = os.path.join(self.get_config_path(), vassal_ini)
            with sudo(), silent():
                run('touch {}'.format(vassal_ini_path))
开发者ID:lericson,项目名称:blues,代码行数:10,代码来源:uwsgi.py

示例13: create

def create(path):
    options = ''

    if python.requested_version() >= (3,):
        options += ' -p /usr/bin/python3'

    if not files.exists(path):
        info('Creating virtualenv: {}', path)
        run('virtualenv{options} {}'.format(path, options=options))
    else:
        info('Virtualenv already exists: {}', path)
开发者ID:Sportamore,项目名称:blues,代码行数:11,代码来源:virtualenv.py

示例14: top

def top(vassal_name=None):
    """
    Launch uwsgitop for vassal stats socket

    :param vassal_name: The vassal to show stats for (Default: project setting)
    """
    # TODO: fix missing output
    with sudo(), hide_prefix():
        vassal = vassal_name or blueprint.get('project')
        stats_path = os.path.join(tmpfs_path, '{}-stats.sock'.format(vassal))
        run('uwsgitop {}'.format(stats_path))
开发者ID:lericson,项目名称:blues,代码行数:11,代码来源:uwsgi.py

示例15: fifo

def fifo(vassal_name, command):
    """
    Issue FIFO commands to a vassal.

    :param vassal_name: The vassal to command
    :param command: The FIFO command to issue

    See: http://uwsgi-docs.readthedocs.org/en/latest/MasterFIFO.html
    """
    fifo_file = '/run/uwsgi/fifo-{}'.format(vassal_name)
    with sudo(), silent():
        run('echo {} > {}'.format(command, fifo_file))
开发者ID:lericson,项目名称:blues,代码行数:12,代码来源:uwsgi.py


注:本文中的refabric.api.run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。