Beispiel #1
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace, output: AbstractOutputWriter):
        # check that the script exists
        script_name = args.script_name
        scripts = instance_manager.project_config.scripts
        if script_name not in scripts:
            raise ValueError('Script "%s" is not defined in the configuration file.' % script_name)

        # replace script parameters
        params = parse_parameters(args.parameter)
        script_content = render_script(scripts[script_name], params)

        # check that the instance is started
        if not instance_manager.is_running():
            raise InstanceNotRunningError(instance_manager.instance_config.name)

        # sync the project with the instance
        if args.sync:
            instance_manager.sync(output)

        # tmux session name
        session_name = args.session_name if args.session_name else 'spotty-script-%s' % script_name

        # run the script on the instance
        run_script(host=instance_manager.get_ip_address(),
                   port=instance_manager.ssh_port,
                   user=instance_manager.ssh_user,
                   key_path=instance_manager.ssh_key_path,
                   script_name=script_name,
                   script_content=script_content,
                   tmux_session_name=session_name,
                   restart=args.restart,
                   logging=args.logging)
Beispiel #2
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace, output: AbstractOutputWriter):

        instance_manager.stop(output)

        output.write('\n'
                     '----------------------------------\n'
                     'Instance was successfully deleted.\n'
                     '----------------------------------')
Beispiel #3
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace,
             output: AbstractOutputWriter):
        filters = [{'exclude': ['*']}, {'include': args.filters}]

        dry_run = args.dry_run
        with output.prefix('[dry-run] ' if dry_run else ''):
            instance_manager.download(filters, output, dry_run)

        output.write('Done')
Beispiel #4
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace,
             output: AbstractOutputWriter):
        if args.list_sessions:
            remote_cmd = ['tmux', 'ls', ';', 'echo', '']
        else:
            # tmux session name
            session_name = args.session_name
            if not session_name:
                session_name = 'spotty-ssh-host-os' if args.host_os else 'spotty-ssh-container'

            # a command to connect to the host OS or to the container
            remote_cmd = ['tmux', 'new', '-s', session_name, '-A']
            if not args.host_os:
                # connect to the container or keep the tmux window in case of a failure
                container_cmd = subprocess.list2cmdline(
                    ['sudo', '/tmp/spotty/instance/scripts/container_bash.sh'])
                tmux_cmd = '%s || tmux set remain-on-exit on' % container_cmd
                remote_cmd += [tmux_cmd]

        remote_cmd = subprocess.list2cmdline(remote_cmd)

        # connect to the instance
        ssh_command = get_ssh_command(instance_manager.get_ip_address(),
                                      instance_manager.ssh_port,
                                      instance_manager.ssh_user,
                                      instance_manager.ssh_key_path,
                                      remote_cmd)
        subprocess.call(ssh_command)
Beispiel #5
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace,
             output: AbstractOutputWriter):
        # start the instance
        dry_run = args.dry_run
        with output.prefix('[dry-run] ' if dry_run else ''):
            instance_manager.start(output, dry_run)

        if not dry_run:
            instance_name = ''
            if len(instance_manager.project_config.instances) > 1:
                instance_name = ' ' + instance_manager.instance_config.name

            output.write(
                '\nThe instance was successfully started.\n'
                '\n%s\n'
                '\nUse the "spotty ssh%s" command to connect to the Docker container.\n'
                % (instance_manager.get_status_text(), instance_name))
Beispiel #6
0
 def _run(self, instance_manager: AbstractInstanceManager, args: Namespace,
          output: AbstractOutputWriter):
     output.write(instance_manager.get_status_text())
Beispiel #7
0
    def _run(self, instance_manager: AbstractInstanceManager, args: Namespace, output: AbstractOutputWriter):
        dry_run = args.dry_run
        with output.prefix('[dry-run] ' if dry_run else ''):
            instance_manager.sync(output, dry_run)

        output.write('Done')