tempos modernos com fabric

Post on 15-Feb-2017

151 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Tempos ModernosTempos ModernosCom FabricCom Fabric

/----\ -------/ \ / \ / | -----------------/ --------\ ----------------------------------------------

Carlos Manierocarlosmaniero@gmail.com

carlosmaniero

http://linkedin.com/in/carlosmaniero

É em Python ♥Multi tarefas

SSH

Why Fabric?

Command Line

$ pip install fabric

Instalação

Hello World!fabric.py

def hello(name='World'): print("Hello, {}!".format(name))

Hello World!$ fab helloHello, World!

Done.

$ fab hello:”Charlie Chaplin”Hello, Charlie Chaplin!

Done.

fabric.api

● env● run● sudo● local● get● put● prompt● reboot

fabric.api.env

env.hosts = ['pythonildo@localhost:2020']

env.passwords = {'pythonildo@localhost:2020': '12345'

}

def test():print(env.host_string)

fabric.api.env

env.passwords = {'pythonildo@localhost:2020': '12345'

}

env.hosts = env.password.keys()

from fabric.api import (run, sudo, reboot)

def joke():run('hostname')

sudo('apt-get -y install moo')reboot()

$ fab joke

[pythonildo@localhost:2020] Executing task 'joke'[pythonildo@localhost:2020] run: hostname[pythonildo@localhost:2020] out: ubuntu[pythonildo@localhost:2020] out:

[pythonildo@localhost:2020] sudo: apt-get moo[pythonildo@localhost:2020] out: sudo password:[pythonildo@localhost:2020] out: (__) [pythonildo@localhost:2020] out: (oo) [pythonildo@localhost:2020] out: /------\/ [pythonildo@localhost:2020] out: / | || [pythonildo@localhost:2020] out: * /\---/\ [pythonildo@localhost:2020] out: ~~ ~~ [pythonildo@localhost:2020] out: ..."Have you mooed today?"...[pythonildo@localhost:2020] out:

[pythonildo@localhost:2020] out: sudo password:[pythonildo@localhost:2020] out:

Done.Disconnecting from pythonildo@localhost:2020... done.

[pythonildo@localhost:2020] Executing task 'joke'[pythonildo@localhost:2020] run: hostname[pythonildo@localhost:2020] out: ubuntu[pythonildo@localhost:2020] out:

[pythonildo@localhost:2020] sudo: apt-get moo[pythonildo@localhost:2020] out: sudo password:[pythonildo@localhost:2020] out: (__) [pythonildo@localhost:2020] out: (oo) [pythonildo@localhost:2020] out: /------\/ [pythonildo@localhost:2020] out: / | || [pythonildo@localhost:2020] out: * /\---/\ [pythonildo@localhost:2020] out: ~~ ~~ [pythonildo@localhost:2020] out: ..."Have you mooed today?"...[pythonildo@localhost:2020] out:

[pythonildo@localhost:2020] out: sudo password:[pythonildo@localhost:2020] out:

Done.Disconnecting from pythonildo@localhost:2020... done.

from fabric.api import (local, prompt)

def git_push():check_noob = prompt( 'Quanto é 1 + 1?',

defaulf=1, validate=int ) if check_noob == 2:

local('git push')

from fabric.api import get, put

def set_ngnix_conf():get(

remote_path='/etc/ngnix/conf.d/default', local_path='/bkp/ngnix/default' ) put( remote_path='/etc/ngnix/conf.d/default', local_path='/project/conf/ngnix.conf', use_sudo=True, ) sudo('service ngnix restart')

fabric.context_managers

● cd● lcd

def update_app():

with lcd('/home/pythonildo/project/'):result = local('./manage.py test')if result.failed:

print('foram encontrados erros na app'

)exit(0)

with cd('/var/www/project/'):run('git pull')

from fabric.api import localfrom fabric.context_managers import cd, lcd

/----\ -------/ \ / \ / | -----------------/ --------\ ----------------------------------------------

Carlos Manierocarlosmaniero@gmail.com

carlosmaniero

http://linkedin.com/in/carlosmaniero

top related