Ejemplo n.º 1
0
    def stop(self):
        """
        Stops the container started by this class instance.

        :return: The docker object
        """
        sleep(2)
        execute('docker kill {0}'.format(self.container_name))
        execute('docker rm {0}'.format(self.container_name))
        return self
Ejemplo n.º 2
0
    def stop(self):
        """
        Stops the container started by this class instance.

        :return: The docker object
        """
        sleep(2)
        execute('docker kill {0}'.format(self.container_name))
        execute('docker rm {0}'.format(self.container_name))
        return self
Ejemplo n.º 3
0
    def _cp(self, src, dest):
        command = "docker cp {} {}".format(
                src,
                dest
        )
        result = execute(command)

        return result
Ejemplo n.º 4
0
    def run(self,
            command,
            working_directory='',
            stdin='',
            login=False,
            tty=False):
        """
        Runs the command with docker exec in the given working directory.

        :param command: The command that should be run with docker exec. The command will be wrapped
                        in  `bash -c \'command\'".
        :type command: str
        :param working_directory: The path to the directory where the command should be run. This
                                  will be evaluated with ``_get_working_directory``, thus relative
                                  paths will become absolute paths.
        :type working_directory: str
        :type stdin: str
        :param login: Will add --login on the bash call.
        :type login: boolean
        :param tty: Will add -t on the bash call.
        :type tty: boolean
        :return: A ProcessResult object containing information on the result of the command.
        :rtype: ProcessResult
        """
        working_directory = self._get_working_directory(working_directory)
        command = command.replace('\'', '"')
        command_string = 'cd {working_directory} && {envs} {command}'

        if self.combine_outputs:
            command_string += ' 2>&1'

        env_string = ' '.join([
            '{0}={1}'.format(key, self.env_variables[key])
            for key in self.env_variables
        ])

        result = execute(
            'docker exec -i{tty} {container} bash{login} -c \'{command}\''.
            format(envs=env_string,
                   container=self.container_name,
                   login='******' if login else '',
                   tty=' -t' if tty else '',
                   command=command_string.format(
                       working_directory=working_directory,
                       command=command,
                       envs=env_string)), stdin)

        return result
Ejemplo n.º 5
0
    def run(self, command, working_directory='', stdin='', login=False, tty=False):
        """
        Runs the command with docker exec in the given working directory.

        :param command: The command that should be run with docker exec. The command will be wrapped
                        in  `bash -c \'command\'".
        :type command: str
        :param working_directory: The path to the directory where the command should be run. This
                                  will be evaluated with ``_get_working_directory``, thus relative
                                  paths will become absolute paths.
        :type working_directory: str
        :type stdin: str
        :param login: Will add --login on the bash call.
        :type login: boolean
        :param tty: Will add -t on the bash call.
        :type tty: boolean
        :return: A ProcessResult object containing information on the result of the command.
        :rtype: ProcessResult
        """
        working_directory = self._get_working_directory(working_directory)
        command = command.replace('\'', '"')
        command_string = 'cd {working_directory} && {envs} {command}'

        if self.combine_outputs:
            command_string += ' 2>&1'

        env_string = ' '.join([
            '{0}={1}'.format(key, self.env_variables[key]) for key in self.env_variables
        ])

        result = execute(
            'docker exec -i{tty} {container} bash{login} -c \'{command}\''.format(
                envs=env_string,
                container=self.container_name,
                login='******' if login else '',
                tty=' -t' if tty else '',
                command=command_string.format(
                    working_directory=working_directory,
                    command=command,
                    envs=env_string
                )
            ),
            stdin
        )

        return result
Ejemplo n.º 6
0
    def start(self):
        """
        Starts a container based on the parameters passed to __init__.

        :return: The docker object
        """
        if self.privilege:
            command_string = 'docker run -d --privileged {0} --name {1} {2} /bin/sleep {3}'
        else:
            command_string = 'docker run -d {0} --name {1} {2} /bin/sleep {3}'

        result = execute(
            command_string.format(self.ports, self.container_name, self.image,
                                  self.timeout))

        self.raise_from_process_result(result)

        return self
Ejemplo n.º 7
0
    def start(self):
        """
        Starts a container based on the parameters passed to __init__.

        :return: The docker object
        """
        if self.privilege:
            command_string = 'docker run -d --privileged {0} --name {1} {2} /bin/sleep {3}'
        else:
            command_string = 'docker run -d {0} --name {1} {2} /bin/sleep {3}'

        result = execute(command_string.format(
            self.ports,
            self.container_name,
            self.image,
            self.timeout
        ))

        self.raise_from_process_result(result)

        return self
Ejemplo n.º 8
0
    def _cp(self, src, dest):
        command = "docker cp {} {}".format(src, dest)
        result = execute(command)

        return result