Python fabric.api.env.password() Examples

The following are 29 code examples of fabric.api.env.password(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fabric.api.env , or try the search function .
Example #1
Source File: utils.py    From commcare-cloud with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #2
Source File: __init__.py    From urbanfootprint with GNU General Public License v3.0 6 votes vote down vote up
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' 
Example #3
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_update():
    print('Update the newarkstg repo via svn.')

    # Create necessary directory
    run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')

    with cd(svn_ns_dir):
        run('svn update --username '+svn_username+' --password '+svn_password+' '+svn_ns_dir+'')

    print('Update finished!')

# Shutdown the core platform via the stop.sh scripts function. 
Example #4
Source File: utils.py    From commcare-cloud with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, user_name, password, command, user_as=None):
        """
        :param user_name: Username to login with
        :param password: Password of the user
        :param command: command to execute (This command will be executed using sudo. )
        """
        self.user_name = user_name
        self.password = password
        self.command = command
        self.user_as = user_as 
Example #5
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co():
    print('Checkout the newarkstg repo via svn.')
    
    # Create necessary directory
    run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')

    #run('ls -l '+path+'')
    with cd(svn_ns_dir):
        run('svn co --username '+svn_username+' --password '+svn_password+' '+svn_url+' '+svn_ns_dir+'')

    print('Checkout finished!')

# Update the newarkstg repo via svn function. 
Example #6
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_update():
    print green('Update the newarkstg repo via svn.')

    # Create necessary directory
    run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')

    with cd(svn_ns_dir):
        run('svn update --username '+svn_username+' --password '+svn_password+' '+svn_ns_dir+'')

    print green('Update finished!')

# Shutdown the core platform via the stop.sh scripts function. 
Example #7
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co():
    print green('Checkout the newarkstg repo via svn.')
    
    # Create necessary directory
    run('mkdir -p '+svn_ns_dir+' 2>/dev/null >/dev/null')

    #run('ls -l '+path+'')
    with cd(svn_ns_dir):
        run('svn co --username '+svn_username+' --password '+svn_password+' '+svn_url+' '+svn_ns_dir+'')

    print green('Checkout finished!')

# Update the newarkstg repo via svn function. 
Example #8
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_api():

    print green('Checkout the mall api repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_sw_dir+' 2>/dev/null >/dev/null')
    run('mkdir -p '+svn_api_path+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_sw_dir):
        run('svn co --username '+svn_api_username+' --password '+svn_api_password+' '+svn_api_url+' '+svn_api_path+'')

    print green('Checkout finished!')

# Update the mall admin repo via svn function. 
Example #9
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_shop():

    print green('Checkout the shop repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_shop_dir+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_shop_dir):
        run('svn co --username '+svn_username+' --password '+svn_password+' '+svn_url+' '+svn_shop_dir+'')

    print green('Checkout finished!')

# Update the shop repo via svn function. 
Example #10
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_api():

    print green('Checkout the mall api repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_sw_dir+' 2>/dev/null >/dev/null')
    run('mkdir -p '+svn_api_path+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_sw_dir):
        run('svn co --username '+svn_api_username+' --password '+svn_api_password+' '+svn_api_url+' '+svn_api_path+'')

    print green('Checkout finished!')

# Update the mall admin repo via svn function. 
Example #11
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_admin():

    print green('Checkout the mall admin repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_sw_dir+' 2>/dev/null >/dev/null')
    run('mkdir -p '+svn_admin_path+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_sw_dir):
        run('svn co --username '+svn_admin_username+' --password '+svn_admin_password+' '+svn_admin_url+' '+svn_admin_path+'')

    print green('Checkout finished!')

# Checkout the mall api repo via svn function. 
Example #12
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_api():

    print green('Checkout the mall api repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_sw_dir+' 2>/dev/null >/dev/null')
    run('mkdir -p '+svn_api_path+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_sw_dir):
        run('svn co --username '+svn_api_username+' --password '+svn_api_password+' '+svn_api_url+' '+svn_api_path+'')

    print green('Checkout finished!')

# Update the mall admin repo via svn function. 
Example #13
Source File: auto_deploy_app_v_final.py    From python-auto-deploy with MIT License 5 votes vote down vote up
def svn_co_admin():

    print green('Checkout the mall admin repo via svn.')

    # Create necessary directory.
    run('mkdir -p '+svn_sw_dir+' 2>/dev/null >/dev/null')
    run('mkdir -p '+svn_admin_path+' 2>/dev/null >/dev/null')

    # Check out.
    with cd(svn_sw_dir):
        run('svn co --username '+svn_admin_username+' --password '+svn_admin_password+' '+svn_admin_url+' '+svn_admin_path+'')

    print green('Checkout finished!')

# Checkout the mall api repo via svn function. 
Example #14
Source File: 16_4_install_python_package_remotely.py    From Python-Network-Programming with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.user = prompt('Enter user name: ')
    env.password = getpass('Enter password: ') 
Example #15
Source File: 16_5_run_mysql_command_remotely.py    From Python-Network-Programming with MIT License 5 votes vote down vote up
def create_db():
    """Create a MySQL DB for App version"""
    if not env.db_name:
        db_name = prompt("Enter the DB name:")
    else:
        db_name = env.db_name
    run('echo "CREATE DATABASE %s default character set utf8 collate utf8_unicode_ci;"|mysql --batch --user=%s --password=%s --host=%s'\
         % (db_name, env.mysqluser, env.mysqlpassword, env.mysqlhost), pty=True) 
Example #16
Source File: 16_5_run_mysql_command_remotely.py    From Python-Network-Programming with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.user = prompt('Enter your system username: ')
    env.password = getpass('Enter your system user password: ')
    env.mysqlhost = 'localhost'
    env.mysqluser = prompt('Enter your db username: ')
    env.mysqlpassword = getpass('Enter your db user password: ')
    env.db_name = '' 
Example #17
Source File: 16_6_transfer_file_over_ssh.py    From Python-Network-Programming with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.password = getpass('Enter your system password: ')
    env.home_folder = '/tmp' 
Example #18
Source File: 6_5_run_mysql_command_remotely.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def create_db():
    """Create a MySQL DB for App version"""
    if not env.db_name:
        db_name = prompt("Enter the DB name:")
    else:
        db_name = env.db_name
    run('echo "CREATE DATABASE %s default character set utf8 collate utf8_unicode_ci;"|mysql --batch --user=%s --password=%s --host=%s'\
         % (db_name, env.mysqluser, env.mysqlpassword, env.mysqlhost), pty=True) 
Example #19
Source File: 6_5_run_mysql_command_remotely.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.user = prompt('Enter your system username: ')
    env.password = getpass('Enter your system user password: ')
    env.mysqlhost = 'localhost'
    env.mysqluser = prompt('Enter your db username: ')
    env.mysqlpassword = getpass('Enter your db user password: ')
    env.db_name = '' 
Example #20
Source File: 6_6_transfer_file_over_ssh.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.password = getpass('Enter your system password: ')
    env.home_folder = '/tmp' 
Example #21
Source File: 6_7_configure_Apache_for_hosting_website_remotely.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.user = prompt('Enter user name: ')
    env.password = getpass('Enter your system password: ') 
Example #22
Source File: 6_4_install_python_package_remotely.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
def remote_server():
    env.hosts = ['127.0.0.1']
    env.user = prompt('Enter user name: ')
    env.password = getpass('Enter password: ') 
Example #23
Source File: fabfile.py    From ansible-mezzanine with MIT License 5 votes vote down vote up
def db_pass():
    """
    Prompts for the database password if unknown.
    """
    if not env.db_pass:
        env.db_pass = getpass("Enter the database password: ")
    return env.db_pass 
Example #24
Source File: methods.py    From urbanfootprint with GNU General Public License v3.0 5 votes vote down vote up
def setup_databases():
    """
        Create production postgres database using local_settings for the DB
    """

    logger.info("confirming Postgres knows about username:{user} password:{pwd}".format(
        user=env.deploy_user,
        pwd=env.password))
    fabtools.icanhaz.postgres.user(
        env.deploy_user,
        env.password,
        superuser=True,
        createdb=True,
        createrole=True,
        login=True)

    run_as_pg("""psql -U postgres -h {host} -c "ALTER USER {user} password '{pwd}';" """.format(
        user=env.deploy_user,
        pwd=env.password,
        host=os.environ['DATABASE_HOST']
    ))

    run_as_pg("""psql -U postgres -h {host} -c "ALTER USER {user} SUPERUSER;" """.format(
        user=env.deploy_user,
        host=os.environ['DATABASE_HOST']
    ))

    database_name = os.environ['DATABASE_NAME']
    fabtools.icanhaz.postgres.database(database_name, env.deploy_user)
    # the following two lines below should be enabled for postgis 2.0 (also remove template_postgis from above lines)
    psql("CREATE EXTENSION IF NOT EXISTS POSTGIS")
    psql("CREATE EXTENSION IF NOT EXISTS DBLINK")

    psql("ALTER DATABASE {database_name} SET search_path = '$user',public,postgis;".format(database_name=database_name)) 
Example #25
Source File: methods.py    From urbanfootprint with GNU General Public License v3.0 5 votes vote down vote up
def psql(command, user=None, host=None, database_name=None, port=None, password=None):

    if not user:
        user = os.environ.get('DATABASE_USERNAME')

    if not password:
        password = os.environ.get('DATABASE_PASSWORD')

    if not host:
        host = os.environ.get('DATABASE_HOST')

    if not database_name:
        database_name = os.environ.get('DATABASE_NAME')

    if not port:
        port = os.environ.get('DATABASE_PORT')

    full_command = """PGPASSWORD={password} psql -U {user} -h {host} -p {port} -d {database_name} -c "{command}" """.format(
        password=password,
        user=user,
        host=host,
        port=port,
        database_name=database_name,
        command=command
    )

    return run(full_command) 
Example #26
Source File: __init__.py    From urbanfootprint with GNU General Public License v3.0 5 votes vote down vote up
def local_prod():
    """
    Sets up a production environment to pretend that localhost is a remote server
    """
    env.hosts = ['localhost']
    env.user = 'calthorpe'
    env.deploy_user = 'calthorpe'
    env.virtualenv_directory = '/srv/calthorpe_env'
    env.password = 'Calthorpe123'
    env.DATA_DUMP_PATH = '/srv/datadump'
    env.dev = False
    env.client = 'default'
    env.settings = 'production' 
Example #27
Source File: fabfile.py    From commcare-cloud with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def check_status():
    env.user = 'ansible'
    env.sudo_user = 'root'
    env.password = getpass('Enter the password for the ansbile user: ')

    execute(check_servers.ping)
    execute(check_servers.postgresql)
    execute(check_servers.elasticsearch) 
Example #28
Source File: remote_add_environment.py    From f5-openstack-lbaasv2-driver with Apache License 2.0 4 votes vote down vote up
def add_diff_env_to_controller(differentiated_environment):
    """Add a differentiated environment remotely and bounce services.

    This function is used in:

     *  test/functional/test_environment_add.py

    Examine that example for further explanation.

    Given an appropriate host_string and password, this function:

    (0) halts services on a Neutron controller;
    (1) reconfigures the relevant files to add an "environment"
        service_provider;
    (2) restarts the services.

    (CRITICAL NOTE: The relevant credentials are hardcoded
    via the 'source keystonerc_testlab' line.
    NOT apropriate for use in a production environment.)
    """
    env.host_string = ''.join(
        [pytest.symbols.tenant_name,
         '@',
         pytest.symbols.controller_ip,
         ':22'])

    @hosts(env.host_string)
    def setup_env_oncontroller(diff_env):
        env.password = pytest.symbols.tenant_password
        execute(lambda: run('sudo ls -la'))

        # Stop existing agent
        execute(lambda: run('sudo systemctl stop f5-openstack-agent'))
        # Stop neutron server / f5_plugin
        execute(lambda: run('sudo systemctl stop neutron-server'))
        # Edit agent configuration to use new environment
        sedtempl = '''sed -i "s/^\(environment_prefix = \)\(.*\)$/\\1%s/"''' +\
                   ''' /etc/neutron/services/f5/f5-openstack-agent.ini'''
        sedstring = 'sudo ' + sedtempl % diff_env
        execute(lambda: run(sedstring))
        # Add diff env to neutron_lbaas.conf and installed Python package
        add_string = 'sudo add_f5agent_environment %s' % diff_env
        execute(lambda: run(add_string))
        # Start neutron-server / f5_plugin
        execute(lambda: run('sudo systemctl start neutron-server'))
        # Start existing agent
        execute(lambda: run('source keystonerc_testlab && '
                            'sudo systemctl start f5-openstack-agent'))

    setup_env_oncontroller(differentiated_environment) 
Example #29
Source File: fabfile.py    From commcare-cloud with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def deploy_commcare(confirm="yes", resume='no', offline='no', skip_record='no'):
    """Preindex and deploy if it completes quickly enough, otherwise abort
    fab <env> deploy_commcare:confirm=no  # do not confirm
    fab <env> deploy_commcare:resume=yes  # resume from previous deploy
    fab <env> deploy_commcare:offline=yes  # offline deploy
    fab <env> deploy_commcare:skip_record=yes  # skip record_successful_release
    """
    _require_target()
    if strtobool(confirm) and (
        not _confirm_translated() or
        not console.confirm(
            'Are you sure you want to preindex and deploy to '
            '{env.deploy_env}?'.format(env=env), default=False)
    ):
        utils.abort('Deployment aborted.')

    env.full_deploy = True

    if resume == 'yes':
        try:
            cached_payload = retrieve_cached_deploy_env()
            checkpoint_index = retrieve_cached_deploy_checkpoint()
        except Exception:
            print(red('Unable to resume deploy, please start anew'))
            raise
        env.update(cached_payload)
        env.resume = True
        env.checkpoint_index = checkpoint_index or 0
        print(magenta('You are about to resume the deploy in {}'.format(env.code_root)))

    env.offline = offline == 'yes'

    if env.offline:
        print(magenta(
            'You are about to run an offline deploy.'
            'Ensure that you have run `fab prepare_offline_deploy`.'
        ))
        offline_ops.check_ready()
        if not console.confirm('Are you sure you want to do an offline deploy?'.format(default=False)):
            utils.abort('Task aborted')

        # Force ansible user and prompt for password
        env.user = 'ansible'
        env.password = getpass('Enter the password for the ansbile user: ')

    _deploy_without_asking(skip_record)