# 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 .server import custom_sudo as sudo
import logging

    docker_image_id = fields.Many2one(
        'infrastructure.docker_image',
        'Docker Image',
        required=True,
    )
    server_id = fields.Many2one(
        'infrastructure.server',
        'Server',
        required=True,
        ondelete='cascade',
    )

    _sql_constraints = [
        ('image_uniq', 'unique(docker_image_id, server_id)',
            'Docker Image Must be Unique per server'),
    ]

    @api.multi
    def pull_image(self, context=None, detached=False):
        """ Tuvimos que ponerle el context porque desde la vista lo pasa sin
        enmascararlo en self"""
        self.server_id.get_env()
        image = self.docker_image_id
        image_name = image.pull_name
        # if any tag, pull the first one
        if image.tag_ids:
            image_name = '%s:%s' % (image_name, image.tag_ids[0].name)
        _logger.info("Pulling Image %s" % image_name)
        if detached:

# 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_docker_image.py
from openerp import models, fields, api
from .server import custom_sudo as sudo
import logging


    docker_image_id = fields.Many2one(
        'infrastructure.docker_image',
        'Docker Image',
        required=True,
    )
    server_id = fields.Many2one(
        'infrastructure.server',
        'Server',
        required=True,
        ondelete='cascade',
    )

    _sql_constraints = [
        ('image_uniq', 'unique(docker_image_id, server_id)',
            'Docker Image Must be Unique per server'),
    ]

    @api.multi
    def pull_image(self, context=None, detached=False):
        """ Tuvimos que ponerle el context porque desde la vista lo pasa sin
        enmascararlo en self"""
        self.server_id.get_env()
        image = self.docker_image_id
        image_name = image.pull_name
        # if any tag, pull the first one
        if image.tag_ids:
            image_name = '%s:%s' % (image_name, image.tag_ids[0].name)
        _logger.info("Pulling Image %s" % image_name)
        if detached:

            sudo('dtach -n `mktemp -u /tmp/dtach.XXXX` docker pull %s' %