Пример #1
0
    def install_launcher_cli(self, args):

        if not args.accept_tos:
            print('''\
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER
LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n'''
                  )
            agree = input('Do you accept the terms of service? [y/n]: ')
            if agree not in ['y', 'Y', 'yes']:
                print('You must accept the terms of service to continue.')
                sys.exit(2)

        args = self._install_launcher_interactive(args.hub,
                                                  args.profile,
                                                  domain=args.domain,
                                                  invite_code=args.invite_code)

        if not args.invite_code:
            print('invite-code is required to provision Noteworthy Launcher.')
            sys.exit(2)
        elif not args.domain:
            print('domain is required to provision Noteworthy Launcher')
            sys.exit(2)

        c = self.launch_launcher_taproot(args.domain, args.hub,
                                         args.invite_code, args.profile)
        if not self.args.no_install_messenger:
            dockerpty.exec_command(self.docker.api, c.id,
                                   'notectl install messenger')
Пример #2
0
 def run(self, command: List[str]) -> None:
     self.container.start()
     dockerpty.exec_command(
         client=self.client.api,
         container=self.container.id,
         command=command,
     )
Пример #3
0
 def run(self, command: List[str]) -> None:
     if dockerpty is None:
         raise RuntimeError('cannot run Docker on Windows')
     self.container.start()
     dockerpty.exec_command(
         client=self.client.api,
         container=self.container.id,
         command=command,
     )
Пример #4
0
    def attach_interactive_shell(self, shell='/bin/bash'):
        # Note that this is blocking the event loop, but it's fine because it
        # is used for debugging purposes from the CLI.
        import dockerpty

        instance_id, image = self.instance['Id'][:12], self.instance['image']
        log.info(f"Attaching an interactive shell '{shell}' to container with "
                 f"id '{instance_id}' and image '{image}'")

        with self.docker_client() as client:
            dockerpty.exec_command(
                client=client,
                container=self.instance,
                command=shell,
                interactive=True
            )
Пример #5
0
def enter_project(name):
    path = get_existing_project_path(name)
    container_name = get_container_name(name)
    client = docker.Client()
    try:
        info = client.inspect_container(container_name)
    except docker.errors.NotFound:
        run_shell_at(path)
        return
    except docker.errors.APIError as error:
        die(error.explanation.decode())

    if not info['State']['Running']:
        client.start(container_name)

    dockerpty.exec_command(client, container_name, '/bin/bash')
Пример #6
0
def enter_project(name):
    path = get_existing_project_path(name)
    container_name = get_container_name(name)
    client = docker.Client()
    try:
        info = client.inspect_container(container_name)
    except docker.errors.NotFound:
        run_shell_at(path)
        return
    except docker.errors.APIError as error:
        die(error.explanation.decode())

    if not info['State']['Running']:
        client.start(container_name)

    dockerpty.exec_command(client, container_name, '/bin/bash')
Пример #7
0
    def exec(self, command: str, as_user: bool = False, relpath: str = None):
        """ Executes the command in the container

        Arguments:
            command {str} -- The command to run. Usually /bin/bash <>
            relpath {str} -- Relative path to project root to enter before executing. Optional, defaults to none.
        Raises:
            ContainerNotFound: The container was not found
            ContainerNotRunning: The container was not running
        """
        if not self.is_running():
            raise ContainerNotRunning()

        cdto = ENVY_CONFIG.get_project_mount_path()
        if relpath is not None:
            cdto = Path(ENVY_CONFIG.get_project_mount_path(), relpath)

        command_inside_project = "/bin/bash -c 'cd {}; {}'".format(
            cdto, command.replace("'", "'\\''"))

        if as_user:
            groups = ",".join(str(x) for x in os.getgroups())
            userspec = str(os.getuid()) + ":" + str(os.getgid())
            command_inside_project = "/usr/sbin/chroot --groups={} --userspec={} / /bin/bash -c 'export HOME=/uhome; cd {}; {}'".format(
                groups,
                userspec,
                ENVY_CONFIG.get_project_mount_path(),
                command.replace("'", "'\\''"),
            )

        exit_code = dockerpty.exec_command(self.docker_client,
                                           self.container_id,
                                           command_inside_project)

        if exit_code != 0:
            raise ContainerError(exit_code)
Пример #8
0
import docker
import dockerpty
import sys

base_url = "unix://var/run/docker.sock"
api_version = "1.24"
client = docker.APIClient(base_url=base_url, version=api_version)
#container = client.containers.get("test_client")
container = client.containers()[0]

    

dockerpty.exec_command(client, container, "/bin/bash", True, sys.stdout, sys.stderr, sys.stdin)
Пример #9
0
 def execstream(self, cmd, stdout=None, stdin=None, stderr=None):
     self.removeoldexecid()
     dockerpty.exec_command(Container.client, self.id, cmd, True, stdout,
                            stderr, stdin)
Пример #10
0
 def execstream(self,cmd='bash',stdout=None,stdin=None,stderr=None):
     self.removeoldexecid();
     dockerpty.exec_command(Container.client,self.id,cmd,True,stdout,stderr,stdin);
Пример #11
0
 def exec_with_pty(self, command: Union[str, List]) -> None:
     dockerpty.exec_command(self._client.api, self._container.id, command=command)