Esempio n. 1
0
 def mount_smb_share(self, share_path, username=None, password=None):
     try:
         LOG.debug('Mounting share: %s', share_path)
         self._smb_conn.Msft_SmbMapping.Create(RemotePath=share_path,
                                               UserName=username,
                                               Password=password)
     except wmi.x_wmi as exc:
         err_msg = (_(
             'Unable to mount SMBFS share: %(share_path)s '
             'WMI exception: %(wmi_exc)s') % {'share_path': share_path,
                                              'wmi_exc': exc})
         raise exceptions.SMBException(err_msg)
Esempio n. 2
0
    def unmount_smb_share(self, share_path, force=False):
        mappings = self._smb_conn.Msft_SmbMapping(RemotePath=share_path)
        if not mappings:
            LOG.debug('Share %s is not mounted. Skipping unmount.', share_path)

        for mapping in mappings:
            # Due to a bug in the WMI module, getting the output of
            # methods returning None will raise an AttributeError
            try:
                mapping.Remove(Force=force)
            except AttributeError:
                pass
            except exceptions.x_wmi:
                # If this fails, a 'Generic Failure' exception is raised.
                # This happens even if we unforcefully unmount an in-use
                # share, for which reason we'll simply ignore it in this
                # case.
                if force:
                    raise exceptions.SMBException(
                        _("Could not unmount share: %s") % share_path)