Skip to content

Instantly share code, notes, and snippets.

@cezarsa
Forked from heynemann/VagrantFile
Created July 3, 2011 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cezarsa/1062656 to your computer and use it in GitHub Desktop.
Save cezarsa/1062656 to your computer and use it in GitHub Desktop.
provy sample code
#!/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
]
}
}
}
#!/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
]
}
}
}
#!/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
]
}
}
}
$ python website.py 8000
>> Website running at http://0.0.0.0:8000
# 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
#!/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
]
}
}
$ vagrant box add base http://files.vagrantup.com/lucid32.box
$ vagrant init
create Vagrantfile
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
#!/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