# 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, api, _
from openerp.exceptions import except_orm, ValidationError
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
from erppeek import Client
import os
import re
import logging
import fabtools
        # pg start command
        self.run_pg_cmd = 'docker run %s %s %s --name %s %s' % (
            prefix, postgres_run_prefix, pg_volume_links,
            self.pg_container, pg_image_name)

        # kill commands
        self.remove_odoo_cmd = 'docker rm -f %s' % self.odoo_container
        self.remove_pg_cmd = 'docker rm -f %s' % self.pg_container

        # stop commands
        self.stop_odoo_cmd = 'docker stop %s' % self.odoo_container
        self.stop_pg_cmd = 'docker stop %s' % self.pg_container

        # start commands
        self.start_odoo_cmd = 'docker start %s' % self.odoo_container
        self.start_pg_cmd = 'docker start %s' % self.pg_container

        # restart commands
        self.restart_odoo_cmd = 'docker restart %s' % self.odoo_container
        self.restart_pg_cmd = 'docker restart %s' % self.pg_container

        # Logs
        self.odoo_log_cmd = 'tail -f %s' % self.logfile
        self.pg_log_cmd = 'docker logs -f %s' % self.pg_container

    @api.multi
    def get_tunnel_to_pg(self):
        self.ensure_one()
        server = self.server_id
        server.get_env()

# 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/instance.py
from openerp import models, fields, api, _
from openerp.exceptions import except_orm, ValidationError
from .server import custom_sudo as sudo
from fabric.contrib.files import exists, append, sed
from erppeek import Client
import os
import re
import logging
import fabtools

        # pg start command
        self.run_pg_cmd = 'docker run %s %s %s --name %s %s' % (
            prefix, postgres_run_prefix, pg_volume_links,
            self.pg_container, pg_image_name)

        # kill commands
        self.remove_odoo_cmd = 'docker rm -f %s' % self.odoo_container
        self.remove_pg_cmd = 'docker rm -f %s' % self.pg_container

        # stop commands
        self.stop_odoo_cmd = 'docker stop %s' % self.odoo_container
        self.stop_pg_cmd = 'docker stop %s' % self.pg_container

        # start commands
        self.start_odoo_cmd = 'docker start %s' % self.odoo_container
        self.start_pg_cmd = 'docker start %s' % self.pg_container

        # restart commands
        self.restart_odoo_cmd = 'docker restart %s' % self.odoo_container
        self.restart_pg_cmd = 'docker restart %s' % self.pg_container

        # Logs
        self.odoo_log_cmd = 'tail -f %s' % self.logfile
        self.pg_log_cmd = 'docker logs -f %s' % self.pg_container

    @api.multi
    def get_tunnel_to_pg(self):
        self.ensure_one()
        server = self.server_id
        server.get_env()

        ip = sudo(