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


Python env.user方法代码示例

本文整理汇总了Python中fabric.state.env.user方法的典型用法代码示例。如果您正苦于以下问题:Python env.user方法的具体用法?Python env.user怎么用?Python env.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fabric.state.env的用法示例。


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

示例1: run_bench

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def run_bench(stack):
    '''
    Log into the RabbitMQ machine
    Execute python run.py with production settings
    '''
    env.user = 'ubuntu'
    # check if rabbit and celery started correctly
    instance_dict = get_ec2_instances(stack, logical_id='RabbitAutoScaling')
    execute(_verify_rabbit, hosts=instance_dict['running'])
    execute(_verify_cloud_init, hosts=instance_dict['running'])
    celery_instance_dict = get_ec2_instances(stack, logical_id='CeleryAutoScaling')
    execute(_verify_celery, hosts=celery_instance_dict['running'])
    cassandra_instance_dict = get_ec2_instances(stack, logical_id='CassandraAutoScaling')
    execute(_verify_cassandra, hosts=cassandra_instance_dict['running'])
    # start the actual benchmark
    execute(_run_bench, hosts=instance_dict['running']) 
开发者ID:GetStream,项目名称:Stream-Framework-Bench,代码行数:18,代码来源:fabfile.py

示例2: authorizeSshKey

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def authorizeSshKey(username, sshId):
    """Add specified SSH public key to the user's ~/.ssh/authorized_keys.
    If there is no such file, one will be created for the user.

    @param username: The name of the user whose authorized_keys is being
                     updated.
    @param sshId: Path to SSH public key (usually ~/.ssh/id_rsa.pub)
    """
    with settings(user='ubuntu',
                  key_filename=os.environ['EC2_KEYPAIR_PATH']):
        sshPath = os.path.join('~%s' % username, '.ssh')
        sudo('mkdir -p %s' % sshPath)
        sudo('chmod 700 %s' % sshPath)
        sudo('chown %s:%s %s' % (username, username, sshPath))
        authorizedKeysPath = os.path.join(sshPath, 'authorized_keys')
        pubKey = open(sshId, 'r').readline().strip()
        sudo("echo '%s' >> %s" % (pubKey, authorizedKeysPath))
        sudo('chmod 600 %s' % authorizedKeysPath)
        sudo('chown %s:%s %s' % (username, username, authorizedKeysPath)) 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:21,代码来源:deployment.py

示例3: addAdmin

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def addAdmin(username, sshId, user, identity):
    """Add a user with admin privileges to an Ubuntu server.

    @param username: The name of the new user.
    @param sshId: Path to SSH public key (usually ~/.ssh/id_rsa.pub)
    @param user: Optionally, the user to connect as.
    @param identity: Optionally, the SSH identity to use when connecting.
    """
    if identity:
        env.key_filename = identity
    if user:
        env.user = user
    sudo('adduser --disabled-password --gecos ",,," %s' % username)
    sudo('usermod -p "" %s' % username)
    sudo('chage -d 0 %s' % username)
    sudo('gpasswd --add %s admin' % username)
    authorizeSshKey(username, sshId) 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:19,代码来源:deployment.py

示例4: prepareInstance

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def prepareInstance(username, sshId):
    """Prepare an instance updating the packages and creating a new user.

    @param username: The name of the new user.
    @param sshId: Path to SSH public key (usually ~/.ssh/id_rsa.pub)
    """
    print os.environ['EC2_KEYPAIR_PATH']
    with settings(user='ubuntu',
                  key_filename=os.environ['EC2_KEYPAIR_PATH']):
        password = getpass('Enter a new password for user %s:' % username)
        password2 = getpass('Enter the password a again:')
        if password != password2:
            raise RuntimeError("Passwords don't match")
        sudo('adduser --disabled-password --gecos ",,," %s' % username)
        cryptedPassword = _hashPassword(password)
        sudo('usermod --password %s %s' % (cryptedPassword, username))
        sudo('gpasswd --add %s admin' % username)
        authorizeSshKey(username, sshId)
        sudo('apt-get update')
        sudo('DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y')
        if exists('/var/run/reboot-required'):
            reboot() 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:24,代码来源:deployment.py

示例5: applyDatabasePatches

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def applyDatabasePatches(deploymentPath, revision):
    """Apply database patches.

    The PostgreSQL database will be backed up before patches are applied,
    which means this could potentially take some time to run.

    @param deploymentPath: The path to deploy Fluidinfo in.
    @param revision: The C{str} revision of the branch being deployed.
    """
    path = os.path.join(deploymentPath, revision, 'fluidinfo')
    postgresBackupScript = os.path.join(deploymentPath, revision,
                                        'scripts', 'backup-postgresql.sh')
    with cd(path):
        with settings(warn_only=True):
            sudo('killall psql', user='postgres')
            logging.info('Backing up the Postgres database.')
            sudo(postgresBackupScript, user='postgres')
            sudo('bin/python bin/fluidinfo '
                 'patch-database postgres:///fluidinfo', user='fluidinfo') 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:21,代码来源:deployment.py

示例6: _set_stage

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def _set_stage(stage_name='test'):
    env.environment = stage_name
    for option, value in STAGES[env.environment].items():
        setattr(env, option, value)

    env.appname = os.path.basename(os.path.abspath(os.path.dirname(__file__)))
    env.deploydir = os.path.abspath(os.path.join(env.root, env.appname))
    env.virtualenv_dir = os.path.join(env.deploydir,'virtualenv')

    groupname = getattr(env, "chown_group", None)
    if groupname is None:
        setattr(env, "chown_group", env.user)

    username = getattr(env, "chown_user", None)
    if username is None:
        setattr(env, "chown_user", env.user) 
开发者ID:dhananisangit,项目名称:inventory_management_system,代码行数:18,代码来源:fabfile.py

示例7: deploy

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def deploy():
    """
    Deploys the latest rev for use
    """

    env.currentrev = _release_name()
    env.app_shortname = env.appname[:3].upper()
    env.releasepath = env.app_shortname + "-" + env.currentrev[:12]
    print cyan("Release: %s" % env.releasepath)

    print red("Deployment user: %s" % env.user)

    pkg_health = _pkg_check()

    if pkg_health:
        abort("One or more required system packages are unavailable.\n\nTry 'fab bootstrap'ing this system or installing the required package(s) by hand.")

    _prep_deploy_dest()
    with lcd(env.deploydir):
        _setup_local_virtualenv(env.virtualenv_dir)

    _copy_release(env.releasepath)
    _deploy_appconf()

    _symlink_release(env.releasepath, env.app_shortname) 
开发者ID:dhananisangit,项目名称:inventory_management_system,代码行数:27,代码来源:fabfile.py

示例8: database_delete

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def database_delete():
    """
    Deletes the database instance
    """
    if(env.is_production_env is True):
        abort(red("You are not allowed to delete the database of a production " +
                "environment.  If this is a server restore situation, you " +
                "have to temporarily declare env.is_production_env = False " +
                "in the environment"))
    execute(check_and_create_database_user)

    with settings(warn_only=True), hide('stdout'):
        checkDatabase = venvcmd('assembl-pypsql -1 -u {user} -p {password} -n {host} "{command}"'.format(
            command="SELECT 1 FROM pg_database WHERE datname='%s'" % (env.db_database),
            password=env.db_password, host=env.db_host, user=env.db_user))
    if not checkDatabase.failed:
        print(yellow("Cannot connect to database, trying to create"))
        deleteDatabase = run('PGPASSWORD=%s dropdb --host=%s --username=%s %s' % (
            env.db_password, env.db_host, env.db_user, env.db_database))
        if deleteDatabase.succeeded:
            print(green("Database deleted successfully!"))
    else:
        print(green("Database does not exist")) 
开发者ID:conversence,项目名称:idealoom,代码行数:25,代码来源:fabfile.py

示例9: cleanup_stage1

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def cleanup_stage1():
    # Remove all packages we installed
    sudo('yum clean all')

    # Do not ship NGAS with a working NGAS directory
    if not docker_keep_ngas_root():
        with settings(user=ngas_user()):
            run("rm -rf %s" % (ngas_root_dir())) 
开发者ID:ICRAR,项目名称:ngas,代码行数:10,代码来源:dockerContainer.py

示例10: create_aws_instances

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def create_aws_instances():
    """
    Create AWS instances and let Fabric point to them

    This method creates AWS instances and points the fabric environment to them with
    the current public IP and username.
    """

    default_if_empty(env, 'AWS_KEY_NAME',      DEFAULT_AWS_KEY_NAME)
    default_if_empty(env, 'AWS_INSTANCE_NAME', default_instance_name)

    # Create the key pair and security group if necessary
    conn = connect()
    aws_create_key_pair(conn)
    sgid = check_create_aws_sec_group(conn)

    # Create the instance in AWS
    host_names = create_instances(conn, sgid)

    # Update our fabric environment so from now on we connect to the
    # AWS machine using the correct user and SSH private key
    env.hosts = host_names
    env.key_filename = key_filename(env.AWS_KEY_NAME)
    if env.AWS_AMI_NAME in ['CentOS', 'SLES']:
        env.user = 'root'
    else:
        env.user = 'ec2-user'

    # Instances have started, but are not usable yet, make sure SSH has started
    puts('Started the instance(s) now waiting for the SSH daemon to start.')
    execute(check_ssh, timeout=300) 
开发者ID:ICRAR,项目名称:ngas,代码行数:33,代码来源:aws.py

示例11: list_instances

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def list_instances():
    """
    Lists the EC2 instances associated to the user's amazon key
    """
    conn = connect()
    res = conn.get_all_instances()
    for r in res:
        for inst in r.instances:
            print
            print_instance(inst)
            print 
开发者ID:ICRAR,项目名称:ngas,代码行数:13,代码来源:aws.py

示例12: updateVersionTag

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def updateVersionTag(deploymentPath, revision):
    """Updates the fluiddb/version tag for changes in the API.

    @param deploymentPath: The path to deploy Fluidinfo in.
    @param revision: The C{str} revision of the branch being deployed.
    """
    fluidinfoPath = os.path.join(deploymentPath, revision, 'fluidinfo')
    with cd(fluidinfoPath):
        with open('deployment/api-version.txt') as versionFile:
            version = versionFile.read()
            sudo('bin/python bin/fluidinfo update-version-tag '
                 'postgres:///fluidinfo '
                 '%s' % version,
                 user='fluidinfo') 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:16,代码来源:deployment.py

示例13: hasUnappliedDatabasePatches

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def hasUnappliedDatabasePatches(deploymentPath, revision):
    """Determine if there are database patches to apply.

    @param deploymentPath: The path to deploy Fluidinfo in.
    @param revision: The C{str} revision of the branch being deployed.
    @return: C{True} if there are outstanding patches, otherwise C{False}.
    """
    path = os.path.join(deploymentPath, revision, 'fluidinfo')
    with cd(path):
        with settings(warn_only=True):
            out = sudo('bin/python bin/fluidinfo '
                       'patch-status postgres:///fluidinfo', user='fluidinfo')
            return out.return_code != 0 
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:15,代码来源:deployment.py

示例14: get_user_home

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def get_user_home(stage="develop"):
    servers = get_server_config()
    return "%(home_path)s/%(user)s" % {
        "home_path": HOME_PATH,
        "user": make_user(servers[stage]["project"]),
    } 
开发者ID:vicobits,项目名称:suarm,代码行数:8,代码来源:config.py

示例15: set_user

# 需要导入模块: from fabric.state import env [as 别名]
# 或者: from fabric.state.env import user [as 别名]
def set_user(superuser=False):
    servers = get_server_config()
    if superuser:
        env.user = username = get_value(env.stage, "superuser", default="root")
        if has_key(env.stage, "key_filename") and os.path.isfile(get_value(env.stage, "key_filename", default=None)):
            env.key_filename = servers[env.stage]["key_filename"]
        else:
            env.password = getpass("Put password for [%s]: " % username)
            if len(env.password) == 0:
                sys.exit("[superuser] password is needed to make server configurations")
    else:
        env.user = make_user(servers[env.stage]["project"])
        env.password = servers[env.stage]["password"] 
开发者ID:vicobits,项目名称:suarm,代码行数:15,代码来源:config.py


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