Python fabric.api.env.hosts() Examples
The following are 30
code examples of fabric.api.env.hosts().
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 |
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: test_server.py From presto-admin with Apache License 2.0 | 6 votes |
def call_and_assert_install_with_rpm_specifier(self, mock_download_rpm, mock_check_rpm, mock_execute, location, rpm_specifier, rpm_path): if location == 'local' or location == 'download': server.install(rpm_specifier) if location == 'local': mock_download_rpm.assert_not_called() else: self.assertTrue(mock_download_rpm.called) mock_check_rpm.assert_called_with(rpm_path) mock_execute.assert_called_with(server.deploy_install_configure, rpm_path, hosts=get_host_list()) elif location == 'none': self.assertRaises(SystemExit, server.install, rpm_specifier) mock_check_rpm.assert_not_called() mock_execute.assert_not_called() else: exit('Cannot assert because of invalid location: %s' % location)
Example #3
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 6 votes |
def getrunning(config): """ Gets all the running Cassandra processes so you know if C* is fully running across the cluster """ _set_hosts(config) results = execute(_getpid) i = 1 completed = 0 for host, result in results.items(): print "host {} [{}] pid is [{}]".format(i, host, result.strip()) i += 1 if len(result) > 1: completed += 1 print "-"*50 print "{} out of {} hosts are running C*".format(completed, len(results)) print "-"*50
Example #4
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 6 votes |
def cmd(config, cmd): """ EXECS a unix command on the remote hosts: fab -i ~/.ssh/id_cass -u ubuntu cmd:config=c4-ebs-hvm,cmd="df -h" """ # Examples # fab cmd:config=c4-ebs-hvm,cmd="java -version 2>&1 | grep version | awk '{print $NF}'" # fab cmd:config=c4-ebs-hvm,cmd="grep MAX_HEAP_SIZE /etc/dse/cassandra/cassandra-env.sh | grep G" # delete commit log with lots of files #fab -u ubuntu cmd:config=c4-ebs-hvm,cmd="find /raid0/cassandra/commitlog -name '*.log' -print0 | xargs -0 sudo rm" # remove files # fab -u ubuntu cmd:c4-ebs-hvm,cmd="find /raid0/cassandra/commitlog/* -name "*.log" -print0 | xargs -0 sudo rm" _set_hosts(config) results = execute(_exec, cmd=cmd) i = 1 for host, result in results.items(): print "host {} [{}] result is [{}]".format(i, host, result.strip()) i += 1
Example #5
Source File: init.py From boss with MIT License | 6 votes |
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()
Example #6
Source File: __init__.py From urbanfootprint with GNU General Public License v3.0 | 6 votes |
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 #7
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 6 votes |
def _bootstrapcass(): # FIX HOSTS FILE for metrics to record remote IP properly host = 'ip-%s' % env.host_string.replace('.','-') sudo('sed -i "/127/c\\127.0.0.1 {} localhost" /etc/hosts'.format(host)) sudo("apt-get update") # install required packages sudo("""apt-get -y install --fix-missing libjna-java binutils pssh pbzip2 xfsprogs schedtool zip unzip ruby openssl ruby-dev libruby1.9.1 curl liblzo2-dev ntp subversion python-pip unzip xfsprogs ethtool""") # install sysadmin tools sudo("apt-get -y install --fix-missing iftop sysstat htop s3cmd nethogs nmon dstat tree collectd collectd-utils") execute(_installjava) #fix clocksource -> network performance sudo("echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource")
Example #8
Source File: methods.py From urbanfootprint with GNU General Public License v3.0 | 6 votes |
def build(build_type='prod'): """ Drops and recreates the databases for development, then initializes main This will raise an error if 127.0.0.1 is not in env.hosts to protect live databases Make sure complete migration scripts exist prior to running this :return: """ restart_supervisor() prepare_build_or_deploy(build_type=build_type) start = datetime.datetime.now() recreate_db(build_type) with cd(get_django_setting(build_type, 'ROOT_PATH')): manage_py('syncdb --noinput', build_type) manage_py('migrate', build_type) manage_py('collectstatic --noinput', build_type) setup_tilestache_user() build_database(build_type=build_type) post_build_database() end = datetime.datetime.now() elapsed = end - start print elapsed npm_install()
Example #9
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 6 votes |
def _yamlfile(config): host = env.host_string src_file = "configs/{}/cassandra.yaml".format(config) green("Syncing YAML File from [{}]".format(src_file)) dest_file = "{}/cassandra.yaml".format(config_dir) put(src_file, dest_file, use_sudo=True) aftertext = "rpc_address: {}".format(host) sed(dest_file,before='rpc_address: \$HOST',after=aftertext,use_sudo=True,backup=".bak") aftertext = "listen_address: {}".format(host) sed(dest_file,before='listen_address: \$HOST',after=aftertext,use_sudo=True,backup='') # grab the first 3 hosts in the host file and use as seed nodes, could be improved seed_str = ",".join(env.hosts[0:3]) aftertext = 'seeds: "{}"'.format(seed_str) sed(dest_file,before='seeds: \$SEEDS',after=aftertext,use_sudo=True,backup='')
Example #10
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 5 votes |
def _set_hosts(config): hostfile = "configs/{}/hostfile.txt".format(config) hostfile = prompt('Specify hostfile you want to perform operation on. Note you can use something like /tmp/hosts.txt', 'hostfile', default=hostfile) green("Setting hosts from [{}]".format(hostfile)) hosts = open(hostfile, 'r').readlines() hosts = [x.strip() for x in hosts] env.hosts = hosts print hosts
Example #11
Source File: test_server.py From presto-admin with Apache License 2.0 | 5 votes |
def test_check_success_status(self, mock_run_sql, string_config_mock, mock_run, mock_presto_config): env.roledefs = { 'coordinator': ['Node1'], 'worker': ['Node1', 'Node2', 'Node3', 'Node4'], 'all': ['Node1', 'Node2', 'Node3', 'Node4'] } env.hosts = env.roledefs['all'] env.host = 'Node1' string_config_mock.return_value = 'Node1' mock_run_sql.return_value = [['Node2', 'some stuff'], ['Node1', 'some other stuff']] self.assertEqual(server.check_server_status(), True)
Example #12
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 5 votes |
def _set_hosts_stress(): hostfile = "../stress/hostfile.txt" hostfile = prompt('Specify Stress hostfile you want to perform operation on. Note you can use something like /tmp/hosts.txt', 'hostfile', default=hostfile) green("Setting hosts from [{}]".format(hostfile)) hosts = open(hostfile, 'r').readlines() hosts = [x.strip() for x in hosts] env.hosts = hosts print hosts
Example #13
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 5 votes |
def stop(config): """ Stop DSE across the hosts """ _set_hosts(config) execute(_stop)
Example #14
Source File: fabfile.py From cassandra-tools with Apache License 2.0 | 5 votes |
def _agentip(config): ''' Use this task to control what IP is used for opscenter ''' src_file = "configs/{}/address.yaml".format(config) dest_file = "/var/lib/datastax-agent/conf/address.yaml" put(src_file, dest_file, use_sudo=True) aftertext = 'hosts: ["{}"]'.format(env.host_string) sed(dest_file,before='hosts: \["\$HOST"\]',after=aftertext,use_sudo=True,backup='') #sed("/var/lib/datastax-agent/conf/address.yaml", \ #before="^stomp_interface: .*$", \ #after="stomp_interface: {}".format(ip), use_sudo=True, backup='.bak')
Example #15
Source File: 6_4_install_python_package_remotely.py From Python-Network-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def remote_server(): env.hosts = ['127.0.0.1'] env.user = prompt('Enter user name: ') env.password = getpass('Enter password: ')
Example #16
Source File: 6_7_configure_Apache_for_hosting_website_remotely.py From Python-Network-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
def remote_server(): env.hosts = ['127.0.0.1'] env.user = prompt('Enter user name: ') env.password = getpass('Enter your system password: ')
Example #17
Source File: 6_6_transfer_file_over_ssh.py From Python-Network-Programming-Cookbook-Second-Edition with MIT License | 5 votes |
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 |
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 #19
Source File: fabfile.py From restpie3 with MIT License | 5 votes |
def production(): """Set target host to production server""" if confirm("DEPLOY PRODUCTION, YOU SURE ??????", default=False): env.hosts = [PRODUCTION_SERVER] print("Deploying soon... ", env.hosts[0].upper()) # wait a little so you can still stop... time.sleep(5) else: print("Exiting") sys.exit(1)
Example #20
Source File: 16_6_transfer_file_over_ssh.py From Python-Network-Programming with MIT License | 5 votes |
def remote_server(): env.hosts = ['127.0.0.1'] env.password = getpass('Enter your system password: ') env.home_folder = '/tmp'
Example #21
Source File: 16_5_run_mysql_command_remotely.py From Python-Network-Programming with MIT License | 5 votes |
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 #22
Source File: 16_4_install_python_package_remotely.py From Python-Network-Programming with MIT License | 5 votes |
def remote_server(): env.hosts = ['127.0.0.1'] env.user = prompt('Enter user name: ') env.password = getpass('Enter password: ')
Example #23
Source File: auto_deploy_app_v_final.py From python-auto-deploy with MIT License | 5 votes |
def getConfig(section, key): config = ConfigParser.ConfigParser() path = os.path.split(os.path.realpath(__file__))[0] + '/'+config_file config.read(path) return config.get(section, key) # Remote server hosts.
Example #24
Source File: methods.py From urbanfootprint with GNU General Public License v3.0 | 5 votes |
def recreate_db(build_type='prod'): """ Drops and recreates the databases :param build_type: :return: """ is_remote = '127.0.0.1' not in env.hosts and 'localhost' not in env.hosts if build_type == 'dev': # this is a super-hack to make sure we use a build file with CELERY_ALWAYS_EAGER=False # TODO: unify this with 'dev' and/or provide a way to override this celery setting. build_type = 'devbuild' if is_remote and not getattr(env, 'allow_remote_recreate', False): raise Exception("build is not allowed for non-localhosts for security purposes") if not getattr(env, 'allow_remote_recreate', False): if not confirm("This command destroys the database and regenerates it -- proceed?", default=False): return if not get_django_setting(build_type, 'USE_SAMPLE_DATA_SETS'): if not confirm("THIS IS A PRODUCTION DATA SET! REALLY DELETE IT?", default=False): return logger.info("dropping databases...") drop_databases() logger.info("creating database...") setup_databases()
Example #25
Source File: fabfile.py From openvpn-admin-ui with Apache License 2.0 | 5 votes |
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
Example #26
Source File: fabfile.py From openvpn-admin-ui with Apache License 2.0 | 5 votes |
def development(): global SERVER_ENV, UWSGI_ENV, DB_DIR, DB_FILE env.hosts = ['192.168.0.121'] env.user = 'admin' SERVER_ENV = 'development' UWSGI_ENV = 'development' DB_DIR = config.DevelopmentConfig.DB_DIR DB_FILE = config.DevelopmentConfig.DB_FILE
Example #27
Source File: fabfile.py From openvpn-admin-ui with Apache License 2.0 | 5 votes |
def devserver(): global SERVER_ENV, UWSGI_ENV, DB_DIR, DB_FILE env.hosts = ['local-vm-win10-centos6'] env.user = 'caritasem' SERVER_ENV = 'development' UWSGI_ENV = 'development' DB_DIR = config.DevelopmentConfig.DB_DIR DB_FILE = config.DevelopmentConfig.DB_FILE
Example #28
Source File: fabfile.py From commcare-cloud with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _require_target(): require('root', 'code_root', 'hosts', 'deploy_env', provided_by=('staging', 'production', 'softlayer'))
Example #29
Source File: fabfile.py From commcare-cloud with BSD 3-Clause "New" or "Revised" License | 5 votes |
def rollback(): """ Rolls back the servers to the previous release if it exists and is same across servers. """ number_of_releases = execute(release.get_number_of_releases) if not all(n > 1 for n in number_of_releases): print(red('Aborting because there are not enough previous releases.')) exit() releases = execute(release.get_previous_release) unique_releases = set(releases.values()) if len(unique_releases) != 1: print(red('Aborting because not all hosts would rollback to same release')) exit() unique_release = unique_releases.pop() if not unique_release: print(red('Aborting because release path is empty. ' 'This probably means there are no releases to rollback to.')) exit() if not console.confirm('Do you wish to rollback to release: {}'.format(unique_release), default=False): print(blue('Exiting.')) exit() exists = execute(release.ensure_release_exists, unique_release) if all(exists.values()): print(blue('Updating current and restarting services')) execute(release.update_current, unique_release) silent_services_restart(use_current_release=True) execute(release.mark_last_release_unsuccessful) else: print(red('Aborting because not all hosts have release')) exit()
Example #30
Source File: main.py From rorolite with Apache License 2.0 | 5 votes |
def cli(verbose=False): """rorolite is a tool to deploy ML applications to your server. """ conf = config.load_config(".") fabric_env.hosts = [conf.host] fabric_env.user = conf.user