You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.8 KiB
107 lines
2.8 KiB
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from app import settings
|
|
|
|
from deployer.node import Node
|
|
from deployer.utils import esc1
|
|
|
|
|
|
class Debian(Node):
|
|
def _configure_instance(self, tasks):
|
|
# Configure the instance that was just created
|
|
for item in tasks:
|
|
try:
|
|
print item['message']
|
|
except KeyError:
|
|
pass
|
|
|
|
getattr(self, "_" + item['action'])(item['params'])
|
|
|
|
# Actions
|
|
# def _virtualenv(params):
|
|
# """
|
|
# Allows running commands on the server
|
|
# with an active virtualenv
|
|
# """
|
|
# with cd(fabconf['APPS_DIR']):
|
|
# _virtualenv_command(_render(params))
|
|
|
|
def _apt(self, params):
|
|
"""
|
|
Runs apt-get install commands
|
|
"""
|
|
for pkg in params:
|
|
self._sudo("apt-get install -y -qq %s" % pkg)
|
|
|
|
def _pip(self, params):
|
|
"""
|
|
Runs pip install commands
|
|
"""
|
|
for pkg in params:
|
|
self._sudo("pip install %s" % pkg)
|
|
|
|
def _run(self, params):
|
|
"""
|
|
Runs command with active user
|
|
"""
|
|
command = self._render(params)
|
|
self.hosts.run(command)
|
|
|
|
def _sudo(self, params):
|
|
"""
|
|
Run command as root
|
|
"""
|
|
command = self._render(params)
|
|
self.hosts.sudo(command)
|
|
|
|
def _put(self, params):
|
|
"""
|
|
Moves a file from local computer to server
|
|
"""
|
|
for host in self.hosts.get_hosts():
|
|
host = host()
|
|
host.put_file(
|
|
self._render(params['file']),
|
|
self._render(params['destination'])
|
|
)
|
|
|
|
def _put_template(self, params, context=settings.__dict__):
|
|
"""
|
|
Same as _put() but it loads a file and does variable replacement
|
|
"""
|
|
f = open(self._render(params['template']), 'r')
|
|
template = f.read()
|
|
|
|
self.hosts.run(
|
|
self._write_to(
|
|
self._render(template, context),
|
|
self._render(params['destination'])
|
|
)
|
|
)
|
|
|
|
def _render(self, template, context=settings.__dict__):
|
|
"""
|
|
Does variable replacement
|
|
"""
|
|
return template % context
|
|
|
|
def _write_to(self, string, path):
|
|
"""
|
|
Writes a string to a file on the server
|
|
"""
|
|
return "echo '" + string + "' > " + path
|
|
|
|
def _append_to(self, string, path):
|
|
"""
|
|
Appends to a file on the server
|
|
"""
|
|
return "echo '" + string + "' >> " + path
|
|
|
|
def _virtualenv(self, command):
|
|
"""
|
|
Activates virtualenv and runs command
|
|
"""
|
|
with self.hosts.prefix(settings.ACTIVATE):
|
|
with self.hosts.cd(settings.PROJECT_DIR, expand=True):
|
|
self.hosts.run(self._render(command))
|
|
|