當前位置: 首頁>>代碼示例>>Python>>正文


Python env.user方法代碼示例

本文整理匯總了Python中fabric.api.env.user方法的典型用法代碼示例。如果您正苦於以下問題:Python env.user方法的具體用法?Python env.user怎麽用?Python env.user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fabric.api.env的用法示例。


在下文中一共展示了env.user方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_supervisor

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def setup_supervisor():
    # We use supervisord to keep Crestify running in the background
    # Recover from crashes, and to start automatically on bootup
    # Also, using more than 1 gunicorn worker resulted in socket not being released, so only 1 worker will be used
    sudo('apt-get -y install supervisor')
    sudo('mkdir /var/log/crestify/')
    sudo(
        'cd /home/crestify/crestify && ../crestifyenv/bin/honcho export -s /bin/sh -a crestify supervisord /etc/supervisor/conf.d')
    fd = StringIO()
    get('/etc/supervisor/conf.d/crestify.conf', fd)
    content = fd.getvalue().splitlines()
    for n, i in enumerate(content):
        if i.startswith("environment="):
            content[n] = i + ",PATH=/home/crestify/crestifyenv/bin:%(ENV_PATH)s"
        if i.startswith("user="):
            content[n] = "user=crestify"
        if i.startswith("stopsignal="):
            content[n] = "stopsignal=TERM"  # Both Gunicorn and Celery use SIGTERM for graceful shutdown
    content = StringIO("\n".join(content))
    put(content, "/etc/supervisor/conf.d/crestify.conf", use_sudo=True)
    sudo('supervisorctl reread')
    sudo('supervisorctl update') 
開發者ID:dhamaniasad,項目名稱:crestify,代碼行數:24,代碼來源:fabfile.py

示例2: run_command

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def run_command(self, hosts, parallel_pool_size=1):
        from fabric.api import execute, sudo, env, parallel
        if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)):
            env.use_ssh_config = True
        env.forward_agent = True
        # pass `-E` to sudo to preserve environment for ssh agent forwarding
        env.sudo_prefix = "sudo -SE -p '%(sudo_prompt)s' "
        env.user = self.user_name
        env.password = self.password
        env.hosts = hosts
        env.warn_only = True

        def _task():
            result = sudo(self.command, user=self.user_as)
            return result

        task = _task
        if parallel_pool_size > 1:
            task = parallel(pool_size=parallel_pool_size)(_task)

        res = execute(task)
        return res 
開發者ID:dimagi,項目名稱:commcare-cloud,代碼行數:24,代碼來源:utils.py

示例3: _setup_path

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def _setup_path():
    # using posixpath to ensure unix style slashes.
    # See bug-ticket: http://code.fabfile.org/attachments/61/posixpath.patch
    env.root = posixpath.join(env.home, 'www', env.deploy_env)
    env.log_dir = posixpath.join(env.home, 'www', env.deploy_env, 'log')
    env.releases = posixpath.join(env.root, 'releases')
    env.code_current = posixpath.join(env.root, 'current')
    env.code_root = posixpath.join(env.releases, env.deploy_metadata.timestamp)
    env.project_root = posixpath.join(env.code_root, env.project)
    env.project_media = posixpath.join(env.code_root, 'media')

    env.py3_virtualenv_current = posixpath.join(env.code_current, 'python_env-3.6')
    env.py3_virtualenv_root = posixpath.join(env.code_root, 'python_env-3.6')

    env.services = posixpath.join(env.code_root, 'services')
    env.db = '%s_%s' % (env.project, env.deploy_env)
    env.offline_releases = posixpath.join('/home/{}/releases'.format(env.user))
    env.offline_code_dir = posixpath.join('{}/{}'.format(env.offline_releases, 'offline'))
    env.airflow_home = posixpath.join(env.home, 'airflow')
    env.airflow_env = posixpath.join(env.airflow_home, 'env')
    env.airflow_code_root = posixpath.join(env.airflow_home, 'pipes') 
開發者ID:dimagi,項目名稱:commcare-cloud,代碼行數:23,代碼來源:fabfile.py

示例4: localhost

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def localhost(skip_ssh=False):
    """
    Sets up a development environment to pretend that localhost is a remote server
    """
    if not skip_ssh:
        env.hosts = ['127.0.0.1']

    env.user = env.deploy_user = 'calthorpe'
    env.deploy_user = 'calthorpe'
    env.virtualenv_directory = '/srv/calthorpe_env'
    env.password = 'Calthorpe123'
    env.DATA_DUMP_PATH = '/srv/datadump'
    env.settings = 'dev'
    env.dev = True
    env.use_ssl = False
    env.client = 'default' 
開發者ID:CalthorpeAnalytics,項目名稱:urbanfootprint,代碼行數:18,代碼來源:__init__.py

示例5: configure_env

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def configure_env():
    ''' Configures the fabric env. '''
    config = get_config()
    stage = get_stage()
    stage_config = get_stage_config(stage)
    env.user = stage_config.get('user') or config['user']
    env.port = stage_config.get('port') or config['port']
    env.cwd = stage_config.get('cwd') or config['cwd']
    env.key_filename = stage_config.get(
        'key_filename') or config['key_filename']
    env.hosts = [stage_config['host']]
    ssh_forward_agent = stage_config.get(
        'ssh_forward_agent') or config['ssh_forward_agent']

    env.forward_agent = (
        ssh_forward_agent and
        str(ssh_forward_agent).lower() == 'true'
    )

    # If Verbose logging is turned on show verbose logs.
    verbose_logging = stage_config.get('verbose_logging') or config[
        'verbose_logging']

    if str(verbose_logging).lower() == 'true':
        set_verbose_logging() 
開發者ID:kabirbaidhya,項目名稱:boss,代碼行數:27,代碼來源:init.py

示例6: check_server_status

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def check_server_status():
    """
    Checks if server is running for env.host. Retries connecting to server
    until server is up or till RETRY_TIMEOUT is reached

    Parameters:
        client - client that executes the query

    Returns:
        True or False
    """
    if len(get_coordinator_role()) < 1:
        warn('No coordinator defined.  Cannot verify server status.')
    with closing(PrestoClient(get_coordinator_role()[0], env.user)) as client:
        node_id = lookup_string_config('node.id', os.path.join(constants.REMOTE_CONF_DIR, 'node.properties'), env.host)

        try:
            return query_server_for_status(client, node_id)
        except RetryError:
            return False 
開發者ID:prestodb,項目名稱:presto-admin,代碼行數:22,代碼來源:server.py

示例7: collect_node_information

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def collect_node_information():
    with closing(PrestoClient(get_coordinator_role()[0], env.user)) as client:
        with settings(hide('warnings')):
            error_message = check_presto_version()
        if error_message:
            external_ip = 'Unknown'
            is_running = False
        else:
            with settings(hide('warnings', 'aborts', 'stdout')):
                try:
                    external_ip = get_ext_ip_of_node(client)
                except:
                    external_ip = 'Unknown'
                try:
                    is_running = service('status')
                except:
                    is_running = False
        return external_ip, is_running, error_message 
開發者ID:prestodb,項目名稱:presto-admin,代碼行數:20,代碼來源:server.py

示例8: setup_vhost

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def setup_vhost():
    """ Setup a test website """
    print ("Preparing the Apache vhost setup...")
    print ("Setting up the document root...")
    if exists(WWW_DOC_ROOT):
        sudo("rm -rf %s" %WWW_DOC_ROOT)
    sudo("mkdir -p %s" %WWW_DOC_ROOT)
    sudo("chown -R %s.%s %s" %(env.user, env.user, WWW_DOC_ROOT))
    put(local_path="index.html", remote_path=WWW_DOC_ROOT)
    sudo("chown -R %s.%s %s" %(WWW_USER, WWW_GROUP, WWW_DOC_ROOT))
    print ("Setting up the vhost...")
    sudo("chown -R %s.%s %s" %(env.user, env.user, APACHE_SITES_PATH))
    put(local_path="vhost.conf", remote_path=APACHE_SITES_PATH)
    sudo("chown -R %s.%s %s" %('root', 'root', APACHE_SITES_PATH))
    sudo("%s restart" %APACHE_INIT_SCRIPT)
    print ("Setup complete. Now open the server path http://abc.remote-server.org/ in your web browser.") 
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:18,代碼來源:6_7_configure_Apache_for_hosting_website_remotely.py

示例9: __action

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def __action(**kwargs):
    redata = kwargs['redata']
    jdata = kwargs['jdata']
    if ShouldRun(redata, jdata):
        env.gateway = redata['data']['gateway']
        env.host_string = redata['data']['host_string']
        env.user = redata['data']['username']
        env.key = redata['data']['sshkey']
        env.disable_known_hosts = True
        env.warn_only = True
        env.abort_on_prompts = True
        env.shell = "/bin/sh -c"
        try:
            results = run_cmd(redata['data']['cmd'])
            if results.succeeded:
                return True
            else:
                raise Exception(
                    'Command Execution Failed: {0} - {1}'.format(results.return_code, results))
        except:
            raise Exception(
                'Command failed to execute') 
開發者ID:Runbook,項目名稱:runbook,代碼行數:24,代碼來源:__init__.py

示例10: check

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def check(**kwargs):
    ''' Login over SSH and execute shell command '''
    jdata = kwargs['jdata']
    logger = kwargs['logger']

    env.gateway = jdata['data']['gateway']
    env.host_string = jdata['data']['host_string']
    env.user = jdata['data']['username']
    env.key = jdata['data']['sshkey']
    env.shell = "/bin/sh -c"
    env.disable_known_hosts = True
    env.warn_only = True
    env.abort_on_prompts = True
    try:
        results = run_cmd(jdata['data']['cmd'])
        logger.debug("execute-shell-command: requested command" +
                     " returned with exit code {0}".format(results.return_code))
        if results.succeeded:
            return True
        else:
            return False
    except:
        return None 
開發者ID:Runbook,項目名稱:runbook,代碼行數:25,代碼來源:__init__.py

示例11: check

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def check(**kwargs):
    ''' Login over SSH and execute shell command '''
    jdata = kwargs['jdata']
    logger = kwargs['logger']

    env.gateway = jdata['data']['gateway']
    env.host_string = jdata['data']['host_string']
    env.user = jdata['data']['username']
    env.key = jdata['data']['sshkey']
    env.shell = "/bin/sh -c"
    env.disable_known_hosts = True
    env.warn_only = True
    env.abort_on_prompts = True
    results = run_cmd("uptime")
    if results.succeeded:
        data = results.split()
        load = float(data[-3].rstrip(","))
    else:
        return None

    logger.debug("load-average: 1 minute load average is {0}".format(load))
    if load < float(jdata['data']['threshold']):
        return True
    else:
        return False 
開發者ID:Runbook,項目名稱:runbook,代碼行數:27,代碼來源:__init__.py

示例12: _get_vagrant_connection

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def _get_vagrant_connection():
    local('vagrant up')
    result = local('vagrant ssh-config', capture=True)
    hostname = re.findall(r'HostName\s+([^\n]+)', result)[0]
    port = re.findall(r'Port\s+([^\n]+)', result)[0]
    env.hosts = ['%s:%s' % (hostname, port)]
    env.user = re.findall(r'User\s+([^\n]+)', result)[0]
    env.key_filename = re.findall(r'IdentityFile\s+([^\n]+)', result)[0].lstrip("\"").rstrip("\"") 
開發者ID:dhamaniasad,項目名稱:crestify,代碼行數:10,代碼來源:fabfile.py

示例13: create_database

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def create_database():
    # Create the user and database for Crestify. User and db name can be changed given you change
    # SQLALCHEMY_DATABASE_URI in the config
    create_user_command = "CREATE ROLE crestify WITH PASSWORD 'crestify' LOGIN;"
    create_db_cmd = "CREATE DATABASE crestify OWNER postgres ENCODING 'UTF8' TEMPLATE template0 LC_CTYPE 'en_US.UTF8' LC_COLLATE 'en_US.UTF8'"
    with cd('/var/lib/postgresql'):
        with settings(sudo_user="postgres"):
            sudo('psql -c "{}"'.format(create_user_command))
            sudo('psql -c "{}"'.format(create_db_cmd)) 
開發者ID:dhamaniasad,項目名稱:crestify,代碼行數:11,代碼來源:fabfile.py

示例14: create_marvin_engines_prefix

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def create_marvin_engines_prefix():
    sudo("mkdir -p /opt/marvin/engines")
    sudo("chown {user}:{user} /opt/marvin/engines".format(user=env.user))
    sudo("mkdir -p /var/log/marvin/engines")
    sudo("chown {user}:{user} /var/log/marvin/engines".format(user=env.user))
    sudo("mkdir -p /var/run/marvin/engines")
    sudo("chown {user}:{user} /var/run/marvin/engines".format(user=env.user)) 
開發者ID:marvin-ai,項目名稱:marvin-python-toolbox,代碼行數:9,代碼來源:fabfile.py

示例15: production

# 需要導入模塊: from fabric.api import env [as 別名]
# 或者: from fabric.api.env import user [as 別名]
def production():
    global SERVER_ENV, UWSGI_ENV, DB_DIR, DB_FILE
    env.hosts = ['haoli-normal-06-vpn-dns']
    env.user = 'haoli'
    SERVER_ENV = 'production'
    UWSGI_ENV = 'production'
    DB_DIR = config.ProductionConfig.DB_DIR
    DB_FILE = config.ProductionConfig.DB_FILE

#development Env 
開發者ID:sibosend,項目名稱:openvpn-admin-ui,代碼行數:12,代碼來源:fabfile.py


注:本文中的fabric.api.env.user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。