def push_dump(db=False, es=False): """push the dump file to the other host(jenkins master for now). :param db: if push the database dump file. :type db: bool :param es: if push the es dump file. :type es: bool """ config = _get_config() mirrors = config['dump_mirrors'] for mirror, mirrorinfo in mirrors.iteritems(): env.user = mirrorinfo['dump_user'] env.port = 22 env.host_string = mirrorinfo['dump_domain'] env.dump_path = mirrorinfo['dump_path'] try: with cd(env.dump_path): if db: env.run('rm -f %(new_dbdump_file)s' % config) env.put('%(local_dbdump)s' % config, '%(new_dbdump_file)s' % config) env.run('rm -f %(dbdump_file)s' % config) env.run('mv %(new_dbdump_file)s %(dbdump_file)s' % config) if es: env.run('rm -f %(new_esdump_file)s' % config) env.put('%(local_esdump)s' % config, '%(new_esdump_file)s' % config) env.run('rm -f %(esdump_file)s' % config) env.run('mv %(new_esdump_file)s %(esdump_file)s' % config) except Exception, e: logging.error('Failed to push dump file to remote host %s. Reason: %s' % (mirror['dump_domain'], str(e)))
def _upload_postactivate(postactivate_file, venv_folder, bin_folder): """ Uploads postactivate shell script file to server. """ # full filepath for the uploaded file. postactivate_path = '{bin}/postactivate'.format(bin=bin_folder,) # full filepath for python virtual environment activation shellscript on the server. activate_path = '{venv}/bin/activate'.format(venv=venv_folder,) # add bash command to activate shellscript to source (run) postactivate # script when the virtualenvironment is activated. env.append(activate_path, 'source {postactivate}'.format(postactivate=postactivate_path,)) # upload file. env.put(postactivate_file, postactivate_path)
def _deploy_configs(site_url, user_name=None, user_group=None, upload=True): """ Creates new configs for webserver and services and uploads them to webserver. If a custom version of config exists locally that is newer than the template config, a new config file will not be created from template. """ user_name = user_name or site_url.replace('.', '_') user_group = user_group or LINUXGROUP configs = _get_configs(site_url) for service in configs: # services are webserver, wsgi service and so on. config = configs[service] template = config['template'] # template config file target = join(dirname(template), config['filename']) # name for parsed config file # server filepath to place config file. Outside git repo. destination = join(config['target folder'], config['filename']) if not os.path.exists(target) or os.path.getctime(target) < os.path.getctime(template): # Generate config file from template if a newer custom file does not exist. # use sed to change variable names that will differ between deployments and sites. local(( 'cat "{template}" | ' 'sed "s/SITEURL/{url}/g" | ' 'sed "s/USERNAME/{user}/g" | ' 'sed "s/USERGROUP/{group}/g" > ' '"{filename}"' ).format( template=template, url=site_url, user=user_name, group=user_group, filename=target, )) if upload: # upload config file env.put(target, destination, use_sudo=True) with shell_env(FILENAME=destination): # env.run command to make service register new config and restart if needed. env.run(config['install'])
print("New User (%s): %s, admin: %s" % (username, comment,admin)) pass def git_push(commit="git commit"): with settings(warn_only=True): result1 = local("git add . && git commit -m %s" % commit) result2 = local("git push") if result1.failed or result2.failed and not confirm("Tests failed. Continue anyway?"): abort("Aborting at user request.") ''' Remote interactivity fab -f fab1.py -H ec2-user@rhev-1 deploy1 ''' """ env.put(localfile,remotefile) sftp put """ def deploy1(): code_dir = '/home/ec2-user/py-study/' with settings(warn_only=True): if run("test -d %s" % code_dir).failed: run("git clone [email protected]:Dingou/Python-tools.git %s" % code_dir) with cd(code_dir): run("git pull") def _checkout_branch(branchname=None): with lcd('/srv/devops/salt/salt-master/salt'): local('pwd') try: