def _add_mountpoint(self, config, instance): fstab = Fstab() fstab.read(self.__FSTAB) mount_path = self._mount_path(config.export_host, config.export_path) # Create mountpoint if not os.path.exists(config.mountpoint): os.makedirs(config.mountpoint) else: if not os.path.isdir(config.mountpoint): raise Exception('mountpoint: %s is not a directory.' % config.mountpoint) # Check if empty # add a line to fstab if not config.options: stroptions="" else: stroptions = ',' + ','.join(config.options) fstab.lines.append(Line(self.__FSTAB_LINE % (config.mountpoint, config.export_host, config.export_path, instance, stroptions))) fstab.write(self.__FSTAB)
def _remove_mountpoint(self, config): fstab = Fstab() fstab.read(self.__FSTAB) mount_path = self._mount_path(config.export_host, config.export_path) if os.path.exists(config.mountpoint): os.rmdir(config.mountpoint) # remove the line from fstab newlines = [l for l in fstab.lines if l.directory != config.mountpoint] fstab.lines = newlines fstab.write(self.__FSTAB)