# Path: infrastructure/models/server.py
# def custom_sudo(command, user=False, group=False, dont_raise=False):
#     # TODO esto habria que pasrlo con *args, **kwargs
#     env.warn_only = True
#     if user and group:
#         res = sudo(command, user=user, group=group)
#     elif user:
#         res = sudo(command, user=user)
#     elif group:
#         res = sudo(command, group=group)
#     else:
#         res = sudo(command)
#     if res.failed:
#         if dont_raise:
#             _logger.warning((
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#         else:
#             raise ValidationError(_(
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#     env.warn_only = False
#     return res


from openerp import models, fields, _
from openerp.tools.safe_eval import safe_eval as eval
from fabric.api import run, cd, env
from openerp.exceptions import ValidationError
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
import errno
import time
import os
        'infrastructure.server_configuration',
        string='server_configuration_id',
        ondelete='cascade',
        required=True
    )

    _order = "sequence"

    def execute_command(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        user = self.pool.get('res.users').browse(cr, uid, uid)
        result = []
        server_id = context.get('server_id', False)
        if not server_id:
            raise ValidationError(_('No server in context'))
        server = self.pool['infrastructure.server'].browse(
            cr, uid, server_id, context=context)
        for command in self.browse(cr, uid, ids, context=context):
            command_result = False
            env.user = server.user_name
            env.password = server.password
            env.host_string = server.main_hostname
            env.port = server.ssh_port
            cxt = {
                'self': self,
                'os': os,
                'errno': errno,
                'command': command,
                'run': run,

# Path: infrastructure/models/server.py
# def custom_sudo(command, user=False, group=False, dont_raise=False):
#     # TODO esto habria que pasrlo con *args, **kwargs
#     env.warn_only = True
#     if user and group:
#         res = sudo(command, user=user, group=group)
#     elif user:
#         res = sudo(command, user=user)
#     elif group:
#         res = sudo(command, group=group)
#     else:
#         res = sudo(command)
#     if res.failed:
#         if dont_raise:
#             _logger.warning((
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#         else:
#             raise ValidationError(_(
#                 "Can not run command:\n%s\nThis is what we get:\n%s") % (
#                 res.real_command, unicode(res.stdout, 'utf-8')))
#     env.warn_only = False
#     return res


# Path: infrastructure/models/server_configuration_command.py
from openerp import models, fields, _
from openerp.tools.safe_eval import safe_eval as eval
from fabric.api import run, cd, env
from openerp.exceptions import ValidationError
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
import errno
import time
import os

        'infrastructure.server_configuration',
        string='server_configuration_id',
        ondelete='cascade',
        required=True
    )

    _order = "sequence"

    def execute_command(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        user = self.pool.get('res.users').browse(cr, uid, uid)
        result = []
        server_id = context.get('server_id', False)
        if not server_id:
            raise ValidationError(_('No server in context'))
        server = self.pool['infrastructure.server'].browse(
            cr, uid, server_id, context=context)
        for command in self.browse(cr, uid, ids, context=context):
            command_result = False
            env.user = server.user_name
            env.password = server.password
            env.host_string = server.main_hostname
            env.port = server.ssh_port
            cxt = {
                'self': self,
                'os': os,
                'errno': errno,
                'command': command,
                'run': run,

                'sudo': sudo,