Ejemplo n.º 1
0
    def _mount(self):
        if self._config.volume_dir.startswith(('~', '/')):
            self._volume_root = os.path.expanduser(self._config.volume_dir)
        else:
            self._volume_root = os.path.join(self._config.aminator_root,
                                             self._config.volume_dir)
        self._mountpoint = os.path.join(self._volume_root,
                                        os.path.basename(self._dev))
        if not os.path.exists(self._mountpoint):
            os.makedirs(self._mountpoint)

        if not mounted(self._mountpoint):
            # Handle optional partition
            dev = self._dev
            if self._blockdevice.partition is not None:
                dev = '{0}{1}'.format(dev, self._blockdevice.partition)

            mountspec = MountSpec(dev, None, self._mountpoint, None)

            result = mount(mountspec)
            if not result.success:
                msg = 'Unable to mount {0.dev} at {0.mountpoint}: {1}'.format(
                    mountspec, result.result.std_err)
                log.critical(msg)
                raise VolumeException(msg)
        log.debug(
            'Mounted {0.dev} at {0.mountpoint} successfully'.format(mountspec))
Ejemplo n.º 2
0
 def _unmount(self):
     if mounted(self._mountpoint):
         if busy_mount(self._mountpoint).success:
             raise VolumeException('Unable to unmount {0} from {1}'.format(self._dev, self._mountpoint))
         result = unmount(self._mountpoint)
         if not result.success:
             raise VolumeException('Unable to unmount {0} from {1}: {2}'.format(self._dev, self._mountpoint, result.result.std_err))
Ejemplo n.º 3
0
 def _teardown_chroot_mounts(self):
     config = self._config.plugins[self.full_name]
     for mountdef in reversed(config.chroot_mounts):
         dev, fstype, mountpoint, options = mountdef
         mountspec = MountSpec(
             dev, fstype,
             os.path.join(self._mountpoint, mountpoint.lstrip('/')),
             options)
         log.debug('Attempting to unmount {0}'.format(mountspec))
         if not mounted(mountspec.mountpoint):
             log.warn('{0} not mounted'.format(mountspec.mountpoint))
             continue
         result = unmount(mountspec.mountpoint)
         if not result.success:
             log.error(
                 'Unable to unmount {0.mountpoint}: {1.stderr}'.format(
                     mountspec, result))
             return False
     log.debug('Checking for stray mounts')
     for mountpoint in lifo_mounts(self._mountpoint):
         log.debug('Stray mount found: {0}, attempting to unmount'.format(
             mountpoint))
         result = unmount(mountpoint)
         if not result.success:
             log.error(
                 'Unable to unmount {0.mountpoint}: {1.stderr}'.format(
                     mountspec, result))
             return False
     log.debug('Teardown of chroot mounts succeeded!')
     return True
Ejemplo n.º 4
0
 def _unmount(self):
     if mounted(self._mountpoint):
         if busy_mount(self._mountpoint).success:
             raise VolumeException('Unable to unmount {0} from {1}'.format(self._dev, self._mountpoint))
         result = unmount(self._mountpoint)
         if not result.success:
             raise VolumeException('Unable to unmount {0} from {1}: {2}'.format(self._dev, self._mountpoint,
                                                                                result.result.std_err))
Ejemplo n.º 5
0
 def _mount(self, mountspec):
     if not mounted(mountspec):
         result = mount(mountspec)
         if not result.success:
             msg = 'Unable to mount {0.dev} at {0.mountpoint}: {1}'.format(mountspec, result.result.std_err)
             log.critical(msg)
             return False
     log.debug('Device {0.dev} mounted at {0.mountpoint}'.format(mountspec))
     return True
 def _mount(self, mountspec):
     if not mounted(mountspec):
         result = mount(mountspec)
         if not result.success:
             msg = 'Unable to mount {0.dev} at {0.mountpoint}: {1}'.format(
                 mountspec, result.result.std_err)
             log.critical(msg)
             return False
     log.debug('Device {0.dev} mounted at {0.mountpoint}'.format(mountspec))
     return True
Ejemplo n.º 7
0
 def _unmount(self, mountspec):
     recursive_unmount = self.plugin_config.get('recursive_unmount', False)
     if mounted(mountspec):
         result = unmount(mountspec, recursive=recursive_unmount)
         if not result.success:
             err = 'Failed to unmount {0}: {1}'
             err = err.format(mountspec.mountpoint, result.result.std_err)
             open_files = busy_mount(mountspec.mountpoint)
             if open_files.success:
                 err = '{0}. Device has open files:\n{1}'.format(err, open_files.result.std_out)
             raise VolumeException(err)
     log.debug('Unmounted {0.mountpoint}'.format(mountspec))
Ejemplo n.º 8
0
 def _configure_chroot_mounts(self):
     config = self._config.plugins[self.full_name]
     for mountdef in config.chroot_mounts:
         dev, fstype, mountpoint, options = mountdef
         mountspec = MountSpec(dev, fstype, os.path.join(self._mountpoint, mountpoint.lstrip('/')), options)
         log.debug('Attempting to mount {0}'.format(mountspec))
         if not mounted(mountspec.mountpoint):
             result = mount(mountspec)
             if not result.success:
                 log.critical('Unable to configure chroot: {0.std_err}'.format(result.result))
                 return False
     log.debug('Mounts configured')
     return True
 def _unmount(self, mountspec):
     recursive_unmount = self.plugin_config.get('recursive_unmount', False)
     if mounted(mountspec):
         result = unmount(mountspec, recursive=recursive_unmount)
         if not result.success:
             err = 'Failed to unmount {0}: {1}'
             err = err.format(mountspec.mountpoint, result.result.std_err)
             open_files = busy_mount(mountspec.mountpoint)
             if open_files.success:
                 err = '{0}. Device has open files:\n{1}'.format(
                     err, open_files.result.std_out)
             raise VolumeException(err)
     log.debug('Unmounted {0.mountpoint}'.format(mountspec))
Ejemplo n.º 10
0
    def _mount(self):
        if self._config.volume_dir.startswith(('~', '/')):
            self._volume_root = os.path.expanduser(self._config.volume_dir)
        else:
            self._volume_root = os.path.join(self._config.aminator_root, self._config.volume_dir)
        self._mountpoint = os.path.join(self._volume_root, os.path.basename(self._dev))
        if not os.path.exists(self._mountpoint):
            os.makedirs(self._mountpoint)

        if not mounted(self._mountpoint):
            mountspec = MountSpec(self._dev, None, self._mountpoint, None)
            result = mount(mountspec)
            if not result.success:
                msg = 'Unable to mount {0.dev} at {0.mountpoint}: {1}'.format(mountspec, result.result.std_err)
                log.critical(msg)
                raise VolumeException(msg)
        log.debug('Mounted {0.dev} at {0.mountpoint} successfully'.format(mountspec))
Ejemplo n.º 11
0
 def _teardown_chroot_mounts(self):
     config = self._config.plugins[self.full_name]
     for mountdef in reversed(config.chroot_mounts):
         dev, fstype, mountpoint, options = mountdef
         mountspec = MountSpec(dev, fstype, os.path.join(self._mountpoint, mountpoint.lstrip('/')), options)
         log.debug('Attempting to unmount {0}'.format(mountspec))
         if not mounted(mountspec.mountpoint):
             log.warn('{0} not mounted'.format(mountspec.mountpoint))
             continue
         result = unmount(mountspec.mountpoint)
         if not result.success:
             log.error('Unable to unmount {0.mountpoint}: {1.stderr}'.format(mountspec, result))
             return False
     log.debug('Checking for stray mounts')
     for mountpoint in lifo_mounts(self._mountpoint):
         log.debug('Stray mount found: {0}, attempting to unmount'.format(mountpoint))
         result = unmount(mountpoint)
         if not result.success:
             log.error('Unable to unmount {0.mountpoint}: {1.stderr}'.format(mountspec, result))
             return False
     log.debug('Teardown of chroot mounts succeeded!')
     return True