def ssh_handler(args, config): if config.dig('inventory', 'update_at_start') or args['-u']: update_handler(args, config) if args ['--tmux'] or config.dig('ssh', 'tmux'): question = "What instances would you like to ssh into?" targets = prompt_targets(question, targets=args['<host>'], config=config) else: question = "What instance would you like to ssh into?" targets = prompt_targets(question, targets=args['<host>'], config=config, multiple=False) if len(targets) == 0: logger.info("No matching instances found") sys.exit(1) commands = collections.OrderedDict() for idx, instance in enumerate(targets): name = '{}-{}'.format(instance.name, idx) commands[name] = Ssh(config, instance).command layout = None if args['--layout']: layout = args['--layout'] if args['--tmux'] or config.dig('ssh', 'tmux'): tmux.run(config, commands, args['-w'], layout, args['-d'], args['-s']) else: cmd = list(commands.values())[0] if args['-d']: logger.debug(cmd) else: os.system(cmd)
def exec_handler(args, config): if config.dig('inventory', 'update_at_start') or args['-u']: update_handler(args, config) if args['--tmux'] or config.dig('ssh', 'tmux'): question = "What containers would you like to exec into?" targets = prompt_targets(question, targets=args['<container>'], config=config, type=InstanceType.ECS, filter_sources=args['--source']) else: question = "What containers would you like to exec into?" targets = prompt_targets(question, targets=args['<container>'], config=config, type=InstanceType.ECS, filter_sources=args['--source'], multiple=False) if len(targets) == 0: logger.info("No matching instances found") sys.exit(1) for instance in targets: if instance.container_id == None: logger.info("Could not find container id for instance: %s" % instance) sys.exit(1) commands = collections.OrderedDict() for idx, instance in enumerate(targets): name = '{}-{}'.format(instance.name, idx) commands[name] = Ssh(config, instance, command="sudo -i docker exec -ti %s bash" % instance.container_id).command layout = None if args['--layout']: layout = args['--layout'] if args['--tmux'] or config.dig('ssh', 'tmux'): tmux.run(config, commands, args['-w'], layout, args['-d'], args['-s']) else: cmd = list(commands.values())[0] if args['-d']: logger.debug(cmd) else: os.system(cmd)