def do_setup(self, context): self._check_os_platform() super(WindowsSmbfsDriver, self).do_setup(context) image_utils.check_qemu_img_version(self._MINIMUM_QEMU_IMG_VERSION) config = self.configuration.smbfs_shares_config if not config: msg = (_("SMBFS config file not set (smbfs_shares_config).")) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.exists(config): msg = (_("SMBFS config file at %(config)s doesn't exist.") % { 'config': config }) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.isabs(self.base): msg = _("Invalid mount point base: %s") % self.base LOG.error(msg) raise exception.SmbfsException(msg) self.shares = {} # address : options self._ensure_shares_mounted() self._setup_pool_mappings()
def do_setup(self, context): image_utils.check_qemu_img_version(self._MINIMUM_QEMU_IMG_VERSION) config = self.configuration.smbfs_shares_config if not config: msg = (_("SMBFS config file not set (smbfs_shares_config).")) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.exists(config): msg = (_("SMBFS config file at %(config)s doesn't exist.") % { 'config': config }) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.isabs(self.base): msg = _("Invalid mount point base: %s") % self.base LOG.error(msg) raise exception.SmbfsException(msg) if not self.configuration.smbfs_oversub_ratio > 0: msg = _( "SMBFS config 'smbfs_oversub_ratio' invalid. Must be > 0: " "%s") % self.configuration.smbfs_oversub_ratio LOG.error(msg) raise exception.SmbfsException(msg) if ((not self.configuration.smbfs_used_ratio > 0) and (self.configuration.smbfs_used_ratio <= 1)): msg = _("SMBFS config 'smbfs_used_ratio' invalid. Must be > 0 " "and <= 1.0: %s") % self.configuration.smbfs_used_ratio LOG.error(msg) raise exception.SmbfsException(msg) self.shares = {} # address : options self._ensure_shares_mounted()
def mount(self, export_path, mnt_options=None): if not os.path.isdir(self._mount_base): os.makedirs(self._mount_base) mnt_point = self.get_mount_point(export_path) norm_path = os.path.abspath(export_path) mnt_options = mnt_options or {} username = (mnt_options.get('username') or mnt_options.get('user')) password = (mnt_options.get('password') or mnt_options.get('pass')) if not self._smbutils.check_smb_mapping( norm_path, remove_unavailable_mapping=True): self._smbutils.mount_smb_share(norm_path, username=username, password=password) if os.path.exists(mnt_point): if not self._pathutils.is_symlink(mnt_point): raise exception.SmbfsException(_("Link path already exists " "and its not a symlink")) else: self._pathutils.create_sym_link(mnt_point, norm_path)
def do_setup(self, context): self._check_os_platform() if self.configuration.smbfs_oversub_ratio is not None: self.configuration.max_over_subscription_ratio = ( self.configuration.smbfs_oversub_ratio) if self.configuration.smbfs_used_ratio is not None: self.configuration.reserved_percentage = ( 1 - self.configuration.smbfs_used_ratio) * 100 super(WindowsSmbfsDriver, self).do_setup(context) image_utils.check_qemu_img_version(self._MINIMUM_QEMU_IMG_VERSION) config = self.configuration.smbfs_shares_config if not config: msg = (_("SMBFS config file not set (smbfs_shares_config).")) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.exists(config): msg = (_("SMBFS config file at %(config)s doesn't exist.") % { 'config': config }) LOG.error(msg) raise exception.SmbfsException(msg) if not os.path.isabs(self.base): msg = _("Invalid mount point base: %s") % self.base LOG.error(msg) raise exception.SmbfsException(msg) if not self.configuration.max_over_subscription_ratio > 0: msg = _("SMBFS config 'max_over_subscription_ratio' invalid. " "Must be > 0: %s" ) % self.configuration.max_over_subscription_ratio LOG.error(msg) raise exception.SmbfsException(msg) if not 0 <= self.configuration.reserved_percentage <= 100: msg = _("SMBFS config 'reserved_percentage' invalid. " "Must be > 0 and <= 100: %s" ) % self.configuration.reserved_percentage LOG.error(msg) raise exception.SmbfsException(msg) self.shares = {} # address : options self._ensure_shares_mounted() self._setup_pool_mappings()
def _get_share_from_pool_name(self, pool_name): mappings = {pool: share for share, pool in self._pool_mappings.items()} share = mappings.get(pool_name) if not share: msg = _("Could not find any share for pool %(pool_name)s. " "Pool mappings: %(pool_mappings)s.") raise exception.SmbfsException( msg % dict(pool_name=pool_name, pool_mappings=self._pool_mappings)) return share
def mount(self, export_path, mnt_options=None): if not os.path.isdir(self._mount_base): os.makedirs(self._mount_base) export_hash = self._get_hash_str(export_path) norm_path = os.path.abspath(export_path) mnt_options = mnt_options or {} if not self.check_smb_mapping(norm_path): self._mount(norm_path, mnt_options) link_path = os.path.join(self._mount_base, export_hash) if os.path.exists(link_path): if not self.is_symlink(link_path): raise exception.SmbfsException(_("Link path already exists " "and its not a symlink")) else: self.create_sym_link(link_path, norm_path)
def _create_windows_image(self, volume_path, volume_size, volume_format): """Creates a VHD or VHDX file of a given size.""" # vhd is regarded as vpc by qemu if volume_format == self._DISK_FORMAT_VHD: volume_format = self._DISK_FORMAT_VHD_LEGACY else: qemu_version = self.get_qemu_version() if qemu_version < [1, 7]: err_msg = _("This version of qemu-img does not support vhdx " "images. Please upgrade to 1.7 or greater.") raise exception.SmbfsException(err_msg) self._execute('qemu-img', 'create', '-f', volume_format, volume_path, str(volume_size * units.Gi), run_as_root=True)
def _setup_pool_mappings(self): self._pool_mappings = self.configuration.smbfs_pool_mappings pools = list(self._pool_mappings.values()) duplicate_pools = set( [pool for pool in pools if pools.count(pool) > 1]) if duplicate_pools: msg = _("Found multiple mappings for pools %(pools)s. " "Requested pool mappings: %(pool_mappings)s") raise exception.SmbfsException( msg % dict(pools=duplicate_pools, pool_mappings=self._pool_mappings)) shares_missing_mappings = (set(self.shares).difference( set(self._pool_mappings))) for share in shares_missing_mappings: msg = ("No pool name was requested for share %(share)s " "Using the share name instead.") LOG.warning(msg, dict(share=share)) self._pool_mappings[share] = self._get_share_name(share)
def get_volume_format(self, volume, qemu_format=False): volume_path_template = self._get_local_volume_path_template(volume) volume_path = self._lookup_local_volume_path(volume_path_template) if volume_path: ext = os.path.splitext(volume_path)[1].strip('.').lower() if ext in self._SUPPORTED_IMAGE_FORMATS: volume_format = ext else: # Hyper-V relies on file extensions so we're enforcing them. raise exception.SmbfsException( _("Invalid image file extension: %s") % ext) else: volume_format = (self._get_volume_format_spec(volume) or self.configuration.smbfs_default_volume_format) if qemu_format and volume_format == self._DISK_FORMAT_VHD: volume_format = self._DISK_FORMAT_VHD_LEGACY elif volume_format == self._DISK_FORMAT_VHD_LEGACY: volume_format = self._DISK_FORMAT_VHD return volume_format
def _check_os_platform(self): if sys.platform != 'win32': _msg = _("This system platform (%s) is not supported. This " "driver supports only Win32 platforms.") % sys.platform raise exception.SmbfsException(_msg)
def _delete_snapshot_online(self, context, snapshot, info): msg = _("This driver does not support deleting in-use snapshots.") raise exception.SmbfsException(msg)
def _create_snapshot_online(self, snapshot, backing_filename, new_snap_path): msg = _("This driver does not support snapshotting in-use volumes.") raise exception.SmbfsException(msg)