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


Python env.host_string方法代碼示例

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


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

示例1: _track_event_graphite

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def _track_event_graphite(self, event):
        """
        Track who deployed what service and what the release dir is to Graphite's events UI
        """
        if not self._graphite_host:
            print red('unable to track deployment event in graphite, no graphite host configured in ~/.mendel.conf')
            return

        url = 'http://%s/events/' % self._graphite_host

        user = getpass.getuser()
        what = '%s %s %s on host %s' % (user, event, self._service_name, env.host_string)
        data = ''
        tags = [str(s) for s in (self._service_name, event)]

        data = {'what': what, 'tags': tags, 'data': data}
        r = urllib2.urlopen(url, json.dumps(data))
        if r.code != 200:
            print red('Unable to track deployment event in graphite (HTTP %s)' % r.code)
        else:
            print cyan('Tracked deploy in graphite (data=%s' % json.dumps(data)) 
開發者ID:sproutsocial,項目名稱:mendel,代碼行數:23,代碼來源:core.py

示例2: _track_event_api

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def _track_event_api(self, event):
        """
        Track who deployed what service and what the release dir is to an external REST API
        """
        if not self._track_event_endpoint:
            print red('Unable to track deployment event in custom api, no api endpoint configured in ~/.mendel.conf')
            return

        data = {
            'service': self._api_service_name or self._service_name,
            'host': env.host_string,
            'deployer': getpass.getuser(),
            'event': event
        }

        url = 'http://%s' % self._track_event_endpoint

        r = requests.post(url, data)
        if r.status_code != 200:
            print red('Unable to track deployment event to the external API (HTTP %s)' % r.status_code) 
開發者ID:sproutsocial,項目名稱:mendel,代碼行數:22,代碼來源:core.py

示例3: suggest_localhost

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def suggest_localhost(func):
    '''Prompt user for value of env.host_string with default to 'localhost'
    when env.host_string is empty.

    Modification of decorator function fabric.network.needs_host
    '''
    from fabric.network import handle_prompt_abort, to_dict

    @wraps(func)
    def host_prompting_wrapper(*args, **kwargs):
        while not env.get('host_string', False):
            handle_prompt_abort("the target host connection string")
            host_string = raw_input("No hosts found. Please specify "
                                    "host string for connection [localhost]: ")
            if host_string == '':
                host_string = 'localhost'
            env.update(to_dict(host_string))
        return func(*args, **kwargs)
    host_prompting_wrapper.undecorated = func
    return host_prompting_wrapper 
開發者ID:theno,項目名稱:fabsetup,代碼行數:22,代碼來源:fabutils.py

示例4: combine_rc

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def combine_rc(rc_filename, overlay=None):
    """Take a rc filename, load it as fabric would.

    If it specifies an _extends value, consider this file
    to be an overlay of the named file."""
    from fabric.main import load_settings
    assert os.path.exists(rc_filename), "Can't find " + rc_filename
    service_config = load_settings(rc_filename)
    if '_extends' in service_config:
        fname = service_config['_extends']
        # We want fname to be usable both on host and target.
        # Use project-path-relative names to that effect.
        if fname.startswith('~/'):
            path = dirname(__file__)
            if not is_local(env.host_string):
                path = env.get('projectpath', path)
            fname = join(path, fname[2:])
        else:
            fname = join(dirname(rc_filename), fname)
        service_config = combine_rc(fname, service_config)
    if overlay is not None:
        service_config.update(overlay)
    service_config.pop('_extends', None)
    service_config.pop('', None)
    return service_config 
開發者ID:conversence,項目名稱:idealoom,代碼行數:27,代碼來源:fabfile.py

示例5: _track_event_slack

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def _track_event_slack(self, event):
        """
        Notify Slack that a mendel event has taken place
        """
        text = "%s %s %s @ %s to host(s) %s" % (getpass.getuser(), event, self._service_name, self._get_commit_hash(), env.host_string)
        if self._slack_url is not None:
            params = {
                'username': 'Mendel',
                'text': text,
                'icon_emoji': self._slack_emoji
            }
            req = urllib2.Request(self._slack_url, json.dumps(params))
            urllib2.urlopen(req)
        else:
            print 'No slack_url found skipping slack notification: [%s]' % text 
開發者ID:sproutsocial,項目名稱:mendel,代碼行數:17,代碼來源:core.py

示例6: restart

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def restart():
        with settings(hide('warnings'), warn_only=True):
            click.echo('\n\n--------------------------------------------------------')
            click.echo("--> HOST: [%s]" % env.host_string)
            run('reboot')
            click.echo('--------------------------------------------------------') 
開發者ID:vicobits,項目名稱:suarm,代碼行數:8,代碼來源:tasks.py

示例7: set_alpha_channel

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def set_alpha_channel():
        click.echo('\n\n--------------------------------------------------------')
        click.echo("--> HOST: [%s]" % env.host_string)
        run('echo "GROUP=alpha" > /etc/coreos/update.conf')
        run('systemctl restart update-engine')
        run('update_engine_client -update')
        click.echo('--------------------------------------------------------') 
開發者ID:vicobits,項目名稱:suarm,代碼行數:9,代碼來源:tasks.py

示例8: docker_version

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def docker_version():
        with settings(hide('warnings'), warn_only=True):
            click.echo('\n\n--------------------------------------------------------')
            click.echo("--> HOST: [%s]" % env.host_string)
            run('docker -v')
            click.echo('--------------------------------------------------------') 
開發者ID:vicobits,項目名稱:suarm,代碼行數:8,代碼來源:tasks.py

示例9: _func

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def _func(kwargs, func_local=fabric.api.local, func_remote=fabric.api.run):
    env.host = env.host_string
    func = func_remote
    print_msg(kwargs.pop('msg', None))
    if env.host_string == 'localhost':
        func = func_local
    else:
        kwargs.pop('capture', None)
    return func, kwargs 
開發者ID:theno,項目名稱:fabsetup,代碼行數:11,代碼來源:fabutils.py

示例10: update_or_append_line

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def update_or_append_line(filename, prefix, new_line, keep_backup=True,
                          append=True):
    '''Search in file 'filename' for a line starting with 'prefix' and replace
    the line by 'new_line'.

    If a line starting with 'prefix' not exists 'new_line' will be appended.
    If the file not exists, it will be created.

    Return False if new_line was appended, else True (i.e. if the prefix was
    found within of the file).
    '''
    result = None
    if env.host_string == 'localhost':
        result = update_or_append_local(filename, prefix, new_line,
                                        keep_backup, append)
    else:
        tmp_dir = tempfile.mkdtemp(suffix='', prefix='fabsetup_')
#        fabric.api.local(flo('chmod 777 {tmp_dir}'))
        local_path = os.path.join(tmp_dir, os.path.basename(filename))
        fabric.operations.get(remote_path=filename, local_path=local_path,
                              use_sudo=True, temp_dir='/tmp')
        result = update_or_append_local(local_path, prefix, new_line,
                                        keep_backup, append)
        put(local_path, remote_path=filename, use_sudo=True, temp_dir='/tmp')
        with quiet():
            fabric.api.local(flo('rm -rf {tmp_dir}'))
    return result 
開發者ID:theno,項目名稱:fabsetup,代碼行數:29,代碼來源:fabutils.py

示例11: sanitize_env

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def sanitize_env():
    """Ensure boolean and list env variables are such"""
    for name in (
            "uses_memcache", "uses_uwsgi", "uses_apache",
            "uses_global_supervisor", "uses_apache",
            "uses_ngnix", "mac", "is_production_env"):
        # Note that we use as_bool() instead of bool(),
        # so that a variable valued "False" in the .ini
        # file is recognized as boolean False
        setattr(env, name, as_bool(getattr(env, name, False)))
    public_hostname = env.get("public_hostname", "localhost")
    if not env.get('hosts', None):
        env.hosts = [public_hostname]
    elif not isinstance(env.hosts, list):
        env.hosts = env.hosts.split()
    # Note: normally, fab would set host_string from hosts.
    # But since we use the private name _hosts, and fallback
    # at this stage within task execution, neither env.hosts
    # nor env.host_string are set properly. Revisit with Fabric2.
    if not env.get('host_string', None):
        env.host_string = env.hosts[0]
    #Are we on localhost
    is_local = are_local(env.hosts)
    if env.get('mac', None) is None:
        if is_local:
            #WARNING:  This code will run locally, NOT on the remote server,
            # so it's only valid if we are connecting to localhost
            env.mac = system().startswith('Darwin')
        else:
            env.mac = False
    env.projectpath = env.get('projectpath', dirname(__file__))
    if not env.get('venvpath', None):
        if is_local:
            # Trust VIRTUAL_ENV, important for Jenkins case.
            env.venvpath = getenv('VIRTUAL_ENV', None)
        if not env.get('venvpath', None):
            env.venvpath = join(env.projectpath, 'venv')
    env.random_file = env.get('random_file', 'random.ini')
    env.dbdumps_dir = env.get('dbdumps_dir', join(
        env.projectpath, '%s_dumps' % env.get("projectname", 'idealoom')))
    env.ini_file = env.get('ini_file', 'local.ini') 
開發者ID:conversence,項目名稱:idealoom,代碼行數:43,代碼來源:fabfile.py

示例12: check_and_create_database_user

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def check_and_create_database_user(host=None, user=None, password=None):
    """
    Create a user and a DB for the project
    """
    host = host or env.db_host
    user = user or env.db_user
    password = password or env.db_password
    with settings(warn_only=True):
        checkUser = venvcmd('assembl-pypsql -1 -u {user} -p {password} -n {host} "{command}"'.format(
            command="SELECT 1 FROM pg_roles WHERE rolname='%s'" % (user),
            password=password, host=host, user=user, projectpath=env.projectpath))
    if checkUser.failed:
        print(yellow("User does not exist, let's try to create it. (The error above is not problematic if the next command which is going to be run now will be successful. This next command tries to create the missing Postgres user.)"))
        db_user = system_db_user()
        if is_local(env.host_string) and db_user:
            db_password_string = ''
            sudo_user = db_user
        else:
            db_password = env.get('postgres_db_password', None)
            assert db_password is not None, "We need a password for postgres on " + host
            db_password_string = "-p '%s'" % db_password
            sudo_user = None
        run_db_command('python {pypsql} -u {db_user} -n {host} {db_password_string} "{command}"'.format(
            command="CREATE USER %s WITH CREATEDB ENCRYPTED PASSWORD '%s'; COMMIT;" % (
                user, password),
            pypsql=join(env.projectpath, 'assembl', 'scripts', 'pypsql.py'),
            db_user=db_user, host=host, db_password_string=db_password_string),
            sudo_user)
    else:
        print(green("User exists and can connect")) 
開發者ID:conversence,項目名稱:idealoom,代碼行數:32,代碼來源:fabfile.py

示例13: install_postfix

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def install_postfix():
    """Install postfx for SMTP."""
    assert not env.mac
    # take mail host from mail.host
    external_smtp_host = env.smtp_host
    if is_local(env.external_smtp_host):
        external_smtp_host = None
    sudo("debconf-set-selections <<< 'postfix postfix/mailname string %s'" % (env.host_string,))
    if external_smtp_host:
        sudo("debconf-set-selections <<< 'postfix postfix/main_mailer_type string \"Internet with smarthost\"'")
        sudo("debconf-set-selections <<< 'postfix postfix/relayhost string %s'" % (external_smtp_host,))
    else:
        sudo("debconf-set-selections <<< 'postfix postfix/main_mailer_type string \"Internet site\"'")
    sudo("DEBIAN_FRONTEND=noninteractive apt-get -y install postfix") 
開發者ID:conversence,項目名稱:idealoom,代碼行數:16,代碼來源:fabfile.py

示例14: create_local_ini

# 需要導入模塊: from fabric.state import env [as 別名]
# 或者: from fabric.state.env import host_string [as 別名]
def create_local_ini():
    """Replace the local.ini file with one composed from the current .rc file"""
    execute(update_vendor_config)
    random_ini_path = os.path.join(env.projectpath, env.random_file)
    local_ini_path = os.path.join(env.projectpath, env.ini_file)
    if exists(local_ini_path):
        run('cp %s %s.bak' % (local_ini_path, local_ini_path))

    if is_local(env.host_string):
        # The easy case: create a local.ini locally.
        venvcmd("python -massembl.scripts.ini_files compose -o %s %s" % (
            env.ini_file, env.rcfile))
    else:
        # Create a local.ini file on the remote server
        # without disturbing local random/local.ini files.

        # OK, this is horrid because I need the local venv.
        local_venv = env.get("venvpath", "./venv")
        if not os.path.exists(local_venv):
            local_venv = os.environ.get("VIRTUAL_ENV", None)
        assert os.path.exists(local_venv + "/bin/python"),\
            "No usable local venv"
        # get placeholder filenames
        with NamedTemporaryFile(delete=False) as f:
            random_file_name = f.name
        with NamedTemporaryFile(delete=False) as f:
            local_file_name = f.name
        try:
            # remote server case
            # Load the random file if any in a temp file
            if exists(random_ini_path):
                get(random_ini_path, random_file_name)
            rt = os.path.getmtime(random_file_name)
            # create the local.ini in a temp file
            with settings(host_string="localhost", venvpath=local_venv,
                          user=getuser(), projectpath=os.getcwd()):
                venvcmd("python -massembl.scripts.ini_files compose -o %s -r %s %s" % (
                    local_file_name, random_file_name, env.rcfile))
            # send the random file if changed
            if rt != os.path.getmtime(random_file_name):
                put(random_file_name, random_ini_path)
            # send the local file
            put(local_file_name, local_ini_path)
        finally:
            os.unlink(random_file_name)
            os.unlink(local_file_name) 
開發者ID:conversence,項目名稱:idealoom,代碼行數:48,代碼來源:fabfile.py


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