-
-
Save cezarsa/1062656 to your computer and use it in GitHub Desktop.
provy sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from provy.core import Role | |
class FrontEnd(Role): | |
def provision(self): | |
pass | |
class BackEnd(Role): | |
def provision(self): | |
pass | |
servers = { | |
'test': { | |
'frontend': { | |
'address': '33.33.33.33', | |
'user': 'vagrant', | |
'roles': [ | |
FrontEnd | |
] | |
}, | |
'backend': { | |
'address': '33.33.33.34', | |
'user': 'vagrant', | |
'roles': [ | |
BackEnd | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from provy.core import Role | |
from provy.more.debian import UserRole | |
class FrontEnd(Role): | |
def provision(self): | |
pass | |
class BackEnd(Role): | |
def provision(self): | |
with self.using(UserRole) as role: | |
role.ensure_user('backend', identified_by='pass', is_admin=True) | |
servers = { | |
'test': { | |
'frontend': { | |
'address': '33.33.33.33', | |
'user': 'vagrant', | |
'roles': [ | |
FrontEnd | |
] | |
}, | |
'backend': { | |
'address': '33.33.33.34', | |
'user': 'vagrant', | |
'roles': [ | |
BackEnd | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from provy.core import Role | |
from provy.more.debian import UserRole | |
class FrontEnd(Role): | |
def provision(self): | |
pass | |
class BackEnd(Role): | |
def provision(self): | |
with self.using(UserRole) as role: | |
role.ensure_user('backend', identified_by='pass', is_admin=True) | |
self.update_file('website.py', '/home/frontend/website.py', owner='frontend') | |
servers = { | |
'test': { | |
'frontend': { | |
'address': '33.33.33.33', | |
'user': 'vagrant', | |
'roles': [ | |
FrontEnd | |
] | |
}, | |
'backend': { | |
'address': '33.33.33.34', | |
'user': 'vagrant', | |
'roles': [ | |
BackEnd | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python website.py 8000 | |
>> Website running at http://0.0.0.0:8000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will provision both servers | |
$ provy -s test | |
# will provision only the frontend server | |
$ provy -s test.frontend | |
# will provision only the backend server | |
$ provy -s test.backend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from provy.core import Role | |
from provy.more.debian import UserRole, AptitudeRole | |
class SimpleServer(Role): | |
def provision(self): | |
with self.using(UserRole) as role: | |
role.ensure_user('my-user', identified_by='my-pass', is_admin=True) | |
with self.using(AptitudeRole) as role: | |
role.ensure_package_installed('vim') | |
servers = { | |
'frontend': { | |
'address': '33.33.33.33', | |
'user': 'root', | |
'roles': [ | |
SimpleServer | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vagrant box add base http://files.vagrantup.com/lucid32.box |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vagrant init | |
create Vagrantfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant::Config.run do |config| | |
config.vm.define :frontend do |inner_config| | |
inner_config.vm.box = "base" | |
inner_config.vm.forward_port("http", 80, 8080) | |
inner_config.vm.network("33.33.33.33") | |
end | |
config.vm.define :backend do |inner_config| | |
inner_config.vm.box = "base" | |
inner_config.vm.forward_port("http", 80, 8081) | |
inner_config.vm.network("33.33.33.34") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import sys | |
import tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
port = int(sys.argv[1]) | |
application.listen(port, '0.0.0.0') | |
print ">> Website running at http://0.0.0.0:%d" % port | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment