def unmount_handler(args, config): Sshfs.ensure_sshfs_installed() question = "What instances would you like to have unmounted?" if args['-a']: instances = inventory.instances(config) sshfs_objs = [Sshfs(config, instance, dry_run=args['-d']) for instance in instances] mounted_targets = [obj.instance for obj in sshfs_objs if obj.is_mounted] target_instances = mounted_targets else: desired_targets = args['<host>'] instances = inventory.search(config, desired_targets) sshfs_objs = [Sshfs(config, instance, dry_run=args['-d']) for instance in instances] mounted_targets = [obj.instance for obj in sshfs_objs if obj.is_mounted] target_instances = prompt_targets(question, instances=mounted_targets, multiple=False, config=config) if len(target_instances) == 0: logger.error("No matching mounts found") if args['-a']: logger.warn("Did you select targets with <space> and confirm with <enter>?") sys.exit(1) for sshfsObj in sshfs_objs: if sshfsObj.instance in target_instances: if sshfsObj.unmount(): logger.info("Unmounted %s" % sshfsObj.instance.name) else: logger.error("Unable to unmount %s" % sshfsObj.instance.name)
def mount_handler(args, config): Sshfs.ensure_sshfs_installed() if config.dig('inventory', 'update_at_start') or args['-u']: update_handler(args, config) fields = args['<host>:<remotedir>'].split(':') if len(fields) != 2: logger.error("Requires exactly 2 arguments: host:remotedir") sys.exit(1) desired_target, remotedir = fields instances = inventory.search(config, [desired_target]) sshfs_objs = [Sshfs(config, instance, remotedir, dry_run=args['-d']) for instance in instances] unmounted_targets = [obj.instance for obj in sshfs_objs if not obj.is_mounted] question = "What instances would you like to have mounted?" target_instances = prompt_targets(question, instances=unmounted_targets, multiple=False, config=config) if len(target_instances) == 0: logger.info("No matching instances found") sys.exit(1) for sshfsObj in sshfs_objs: if sshfsObj.instance in target_instances: if sshfsObj.mount(): logger.info("Mounted %s at %s" % (sshfsObj.instance.name, sshfsObj.mountpoint)) else: logger.error("Unable to mount %s" % sshfsObj.instance.name)
def list_mounts_handler(args, config): Sshfs.ensure_sshfs_installed() if args['-d']: return for mountpoint in Sshfs.mounts(config.mount_root_dir): logger.info(mountpoint)