Mount based on which OS is running.
777225
def _mount(self):
        """"""
        # mount_afp "afp://scraig:<password>@address/share" <mnt_point>
        if is_osx():
            if self.connection["jss"].verbose:
                print self.connection["mount_url"]
            if mount_share:
                self.connection["mount_point"] = mount_share(
                    self.connection["mount_url"])
            else:
                # Non-Apple OS X python:
                args = ["mount", "-t", self.protocol,
                        self.connection["mount_url"],
                        self.connection["mount_point"]]
                if self.connection["jss"].verbose:
                    print " ".join(args)
                subprocess.check_call(args)
        elif is_linux():
            args = ["mount_afp", "-t", self.protocol,
                    self.connection["mount_url"],
                    self.connection["mount_point"]]
            if self.connection["jss"].verbose:
                print " ".join(args)
            subprocess.check_call(args)
        else:
            raise JSSError("Unsupported OS.")
18323
def sync_mounts(self, active_mounts, resources, vault_client):
        """"""
        # Create a resource set that is only explicit mounts
        # and sort so removals are first
        mounts = [x for x in resources
                  if isinstance(x, (Mount, AWS))]

        s_resources = sorted(mounts, key=absent_sort)
        # Iterate over explicit mounts only
        for resource in s_resources:
            active_mounts = self.actually_mount(vault_client,
                                                resource,
                                                active_mounts)

        # OK Now iterate over everything but make sure it is clear
        # that ad-hoc mountpoints are deprecated as per
        # https://github.com/Autodesk/aomi/issues/110
        for resource in [x for x in resources
                         if isinstance(x, Secret)]:
            n_mounts = self.actually_mount(vault_client,
                                           resource,
                                           active_mounts)
            if len(n_mounts) != len(active_mounts):
                LOG.warning("Ad-Hoc mount with %s. Please specify"
                            " explicit mountpoints.", resource)

            active_mounts = n_mounts

        return active_mounts, [x for x in resources
                               if not isinstance(x, (Mount))]
638322
def detect_mountpoint(self):
        

        if self.info.get('lastmountpoint'):
            return self.info.get('lastmountpoint')
        if not self.mountpoint:
            return None

        result = None
        paths = os.listdir(self.mountpoint)
        if 'grub' in paths:
            result = '/boot'
        elif 'usr' in paths and 'var' in paths and 'root' in paths:
            result = '/'
        elif 'bin' in paths and 'lib' in paths and 'local' in paths and 'src' in paths and 'usr' not in paths:
            result = '/usr'
        elif 'bin' in paths and 'lib' in paths and 'local' not in paths and 'src' in paths and 'usr' not in paths:
            result = '/usr/local'
        elif 'lib' in paths and 'local' in paths and 'tmp' in paths and 'var' not in paths:
            result = '/var'
        # elif sum(['bin' in paths, 'boot' in paths, 'cdrom' in paths, 'dev' in paths, 'etc' in paths, 'home' in paths,
        #          'lib' in paths, 'lib64' in paths, 'media' in paths, 'mnt' in paths, 'opt' in paths,
        #          'proc' in paths, 'root' in paths, 'sbin' in paths, 'srv' in paths, 'sys' in paths, 'tmp' in paths,
        #          'usr' in paths, 'var' in paths]) > 11:
        #    result = '/'

        if result:
            self.info['lastmountpoint'] = result
            if not self.info.get('label'):
                self.info['label'] = self.info['lastmountpoint']
            logger.info("Detected mountpoint as {0} based on files in volume".format(self.info['lastmountpoint']))

        return result
1031691
def chrootedSystemCall(chrootDir, cmd, sh=True, mountPseudoFs=True, log=None):
    ''''''
    if log is None:
        log = conduct.app.log

    # determine mount points for pseudo fs
    proc = path.join(chrootDir, 'proc')
    sys = path.join(chrootDir, 'sys')
    dev = path.join(chrootDir, 'dev')
    devpts = path.join(chrootDir, 'dev', 'pts')

    # mount pseudo fs
    if mountPseudoFs:
        mount('proc', proc, '-t proc')
        mount('/sys', sys, '--rbind')
        mount('/dev', dev, '--rbind')

    try:
        # exec chrooted cmd
        log.debug('Execute chrooted command ...')
        cmd = 'chroot %s %s' % (chrootDir, cmd)
        return systemCall(cmd, sh, log)
    finally:
        # umount if pseudo fs was mounted
        if mountPseudoFs:
            # handle devpts
            if path.exists(devpts):
                umount(devpts, '-lf')
            # lazy is ok for pseudo fs
            umount(dev, '-lf')
            umount(sys, '-lf')
            umount(proc, '-lf')
373486
def fstab_mount(mountpoint):
    """"""
    cmd_args = ['mount', mountpoint]
    try:
        subprocess.check_output(cmd_args)
    except subprocess.CalledProcessError as e:
        log('Error unmounting {}\n{}'.format(mountpoint, e.output))
        return False
    return True
69699
def is_mounted(self):
        
        mount_check = subprocess.check_output("mount").splitlines()
        # The mount command returns lines like this on OS X...
        # //username@pretendco.com/JSS%20REPO on /Volumes/JSS REPO
        # (afpfs, nodev, nosuid, mounted by local_me)
        # and like this on Linux...
        # //pretendco.com/jamf on /mnt/jamf type cifs (rw,relatime,
        # <options>...)

        valid_mount_strings = self._get_valid_mount_strings()
        was_mounted = False
        if is_osx():
            mount_string_regex = re.compile(r"\(([\w]*),*.*\)$")
            mount_point_regex = re.compile(r"on ([\w/ -]*) \(.*$")
        elif is_linux():
            mount_string_regex = re.compile(r"type ([\w]*) \(.*\)$")
            mount_point_regex = re.compile(r"on ([\w/ -]*) type .*$")
        else:
            raise JSSError("Unsupported OS.")

        for mount in mount_check:
            fs_match = re.search(mount_string_regex, mount)
            fs_type = fs_match.group(1) if fs_match else None
            # Automounts, non-network shares, and network shares
            # all have a slightly different format, so it's easiest to
            # just split.
            mount_string = mount.split(" on ")[0]
            # Does the mount_string match one of our valid_mount_strings?
            if [mstring for mstring in valid_mount_strings if
                    mstring in mount_string] and self.fs_type == fs_type:
                # Get the mount point string between from the end back to
                # the last "on", but before the options (wrapped in
                # parenthesis). Considers alphanumerics, / , _ , - and a
                # blank space as valid, but no crazy chars.
                match = re.search(mount_point_regex, mount)
                mount_point = match.group(1) if match else None
                was_mounted = True
                # Reset the connection's mount point to the discovered
                # value.
                if mount_point:
                    self.connection["mount_point"] = mount_point
                    if self.connection["jss"].verbose:
                        print ("%s is already mounted at %s.\n" %
                               (self.connection["url"], mount_point))

                # We found the share, no need to continue.
                break

        if not was_mounted:
            # If the share is not mounted, check for another share
            # mounted to the same path and if found, incremement the
            # name to avoid conflicts.
            count = 1
            while os.path.ismount(self.connection["mount_point"]):
                self.connection["mount_point"] = (
                    "%s-%s" % (self.connection["mount_point"], count))
                count += 1

        # Do an inexpensive double check...
        return os.path.ismount(self.connection["mount_point"])
604089
def mount(self, readonly=True):
        
        self._handler.add_drive_opts(self.disk_path, readonly=True)
        self._handler.launch()

        for mountpoint, device in self._inspect_disk():
            if readonly:
                self._handler.mount_ro(device, mountpoint)
            else:
                self._handler.mount(device, mountpoint)

        if self._handler.inspect_get_type(self._root) == 'windows':
            self.path = self._windows_path
        else:
            self.path = posix_path
628424
def in_use(self):
        """"""
        if self.is_mounted or self.is_unlocked:
            return True
        if self.is_partition_table:
            for device in self._daemon:
                if device.partition_slave == self and device.in_use:
                    return True
        return False
1175193
def _active_mounts_freebsd(ret):
    '''
    
    '''
    for line in __salt__['cmd.run_stdout']('mount -p').split('\n'):
        comps = re.sub(r"\s+", " ", line).split()
        ret[comps[1]] = {'device': comps[0],
                         'fstype': comps[2],
                         'opts': _resolve_user_group_names(comps[3].split(','))}
    return ret
268188
def GetMountpoints():
  """"""
  devices = {}

  for filesys in GetFileSystems():
    devices[filesys.f_mntonname] = (filesys.f_mntfromname, filesys.f_fstypename)

  return devices
50168
def _mount_avfs(self):
        """"""

        self._paths['avfs'] = tempfile.mkdtemp(prefix='image_mounter_avfs_')

        # start by calling the mountavfs command to initialize avfs
        _util.check_call_(['avfsd', self._paths['avfs'], '-o', 'allow_other'], stdout=subprocess.PIPE)

        # no multifile support for avfs
        avfspath = self._paths['avfs'] + '/' + os.path.abspath(self.paths[0]) + '#'
        targetraw = os.path.join(self.mountpoint, 'avfs')

        os.symlink(avfspath, targetraw)
        logger.debug("Symlinked {} with {}".format(avfspath, targetraw))
        raw_path = self.get_raw_path()
        logger.debug("Raw path to avfs is {}".format(raw_path))
        if raw_path is None:
            raise MountpointEmptyError()
1124246
protected function findOS()
    {
        if (isset($this->os)) return $this->os;

        switch (true) {
            case stristr(PHP_OS, 'DAR'):
                return $this->os = static::OS_OSX;

            case stristr(PHP_OS, 'WIN'):
                return $this->os = static::OS_WIN;

            case stristr(PHP_OS, 'LINUX'):
                return $this->os = static::OS_LINUX;

            default:
                return $this->os = static::OS_OTHER;
        }
    }
664399
def _platform_is_windows(platform=sys.platform):
        """"""
        matched = platform in ('cygwin', 'win32', 'win64')
        if matched:
            error_msg = "Windows isn't supported yet"
            raise OSError(error_msg)
        return matched
260267
def _call_mount(self, volume, mountpoint, type=None, opts=""):
        """"""

        # default arguments for calling mount
        if opts and not opts.endswith(','):
            opts += ","
        opts += 'loop,offset=' + str(volume.offset) + ',sizelimit=' + str(volume.size)

        # building the command
        cmd = ['mount', volume.get_raw_path(), mountpoint, '-o', opts]

        # add read-only if needed
        if not volume.disk.read_write:
            cmd[-1] += ',ro'

        # add the type if specified
        if type is not None:
            cmd += ['-t', type]

        _util.check_output_(cmd, stderr=subprocess.STDOUT)
1356073
def mount(self, image, sudo=None):
    '''
    '''
    return self._state_command(image, command="mount", sudo=sudo)
23636
def ensure_backend(resource, backend, backends, opt, managed=True):
    """"""
    existing_mount = find_backend(resource.mount, backends)
    if not existing_mount:
        new_mount = backend(resource, opt, managed=managed)
        backends.append(new_mount)
        return new_mount

    return existing_mount
749931
def mount(name, device, mkmnt=False, fstype='', opts='defaults', user=None, util='mount'):
    '''
    
    '''
    if util != 'mount':
        # This functionality used to live in img.mount_image
        if util == 'guestfs':
            return __salt__['guestfs.mount'](name, root=device)
        elif util == 'qemu_nbd':
            mnt = __salt__['qemu_nbd.init'](name, device)
            if not mnt:
                return False
            first = next(six.iterkeys(mnt))
            __context__['img.mnt_{0}'.format(first)] = mnt
            return first
        return False

    # Darwin doesn't expect defaults when mounting without other options
    if 'defaults' in opts and __grains__['os'] in ['MacOS', 'Darwin', 'AIX']:
        opts = None

    if isinstance(opts, six.string_types):
        opts = opts.split(',')

    if not os.path.exists(name) and mkmnt:
        __salt__['file.mkdir'](name, user=user)

    args = ''
    if opts is not None:
        lopts = ','.join(opts)
        args = '-o {0}'.format(lopts)

    if fstype:
        # use of fstype on AIX differs from typical Linux use of -t
        # functionality AIX uses -v vfsname, -t fstype mounts all with
        # fstype in /etc/filesystems
        if 'AIX' in __grains__['os']:
            args += ' -v {0}'.format(fstype)
        elif 'solaris' in __grains__['os'].lower():
            args += ' -F {0}'.format(fstype)
        else:
            args += ' -t {0}'.format(fstype)

    cmd = 'mount {0} {1} {2} '.format(args, device, name)
    out = __salt__['cmd.run_all'](cmd, runas=user, python_shell=False)
    if out['retcode']:
        return out['stderr']
    return True