示例#1
0
 def clear_access(self, share, white_list=None):
     share_proto = share['share_proto'].upper()
     share_name = unity_utils.get_share_backend_id(share)
     if share_proto == 'CIFS':
         self.client.cifs_clear_access(share_name, white_list)
     elif share_proto == 'NFS':
         self.client.nfs_clear_access(share_name, white_list)
示例#2
0
    def ensure_share(self, context, share, share_server):
        """Ensure that the share is exported."""
        share_name = unity_utils.get_share_backend_id(share)
        share_proto = share['share_proto']

        backend_share = self.client.get_share(share_name, share_proto)
        if not backend_share.existed:
            raise exception.ShareNotFound(share_id=share_name)
示例#3
0
    def extend_share(self, share, new_size, share_server=None):
        share_id = unity_utils.get_share_backend_id(share)
        backend_share = self.client.get_share(share_id, share['share_proto'])

        if not self._is_share_from_snapshot(backend_share):
            self.client.extend_filesystem(backend_share.filesystem, new_size)
        else:
            share_id = share['id']
            reason = ("Driver does not support extending a "
                      "snapshot based share.")
            raise exception.ShareExtendingError(share_id=share_id,
                                                reason=reason)
示例#4
0
 def test_get_cifs_share_id_without_path(self):
     cifs_share = {
         'export_locations': [{
             'path': '',
             'share_instance_id': 'ef4-47e-48-12c6-gf452'
         }],
         'share_proto':
         'CIFS',
         'id':
         'test_cifs_id'
     }
     result = utils.get_share_backend_id(cifs_share)
     expected = 'test_cifs_id'
     self.assertEqual(expected, result)
示例#5
0
 def test_get_cifs_share_id(self):
     cifs_share = {
         'export_locations': [{
             'path': '\\\\17.66.5.3\\bdf-h4e-42c-122c5-b212',
             'share_instance_id': 'ev4-47e-48-126-gfbh452'
         }],
         'share_proto':
         'CIFS',
         'id':
         'test_cifs_id'
     }
     result = utils.get_share_backend_id(cifs_share)
     expected = 'bdf-h4e-42c-122c5-b212'
     self.assertEqual(expected, result)
示例#6
0
 def test_get_nfs_share_id_without_path(self):
     nfs_share = {
         'export_locations': [{
             'path': '',
             'share_instance_id': 'ev24-7e-4-12c6-g45245'
         }],
         'share_proto':
         'NFS',
         'id':
         'test_nfs_id'
     }
     result = utils.get_share_backend_id(nfs_share)
     expected = 'test_nfs_id'
     self.assertEqual(expected, result)
示例#7
0
 def test_get_nfs_share_id(self):
     nfs_share = {
         'export_locations': [{
             'path': '10.10.1.12:/addf-97e-46c-8ac6-55922f',
             'share_instance_id': 'e24-457e-47-12c6-gf345'
         }],
         'share_proto':
         'NFS',
         'id':
         'test_nfs_id'
     }
     result = utils.get_share_backend_id(nfs_share)
     expected = 'addf-97e-46c-8ac6-55922f'
     self.assertEqual(expected, result)
示例#8
0
    def create_snapshot(self, context, snapshot, share_server=None):
        """Create snapshot from share."""
        share = snapshot['share']
        share_name = unity_utils.get_share_backend_id(
            share) if share else snapshot['share_id']
        share_proto = snapshot['share']['share_proto']
        backend_share = self.client.get_share(share_name, share_proto)

        snapshot_name = snapshot['id']
        if self._is_share_from_snapshot(backend_share):
            self.client.create_snap_of_snap(backend_share.snap, snapshot_name)
        else:
            self.client.create_snapshot(backend_share.filesystem,
                                        snapshot_name)
        return {'provider_location': snapshot_name}
示例#9
0
    def delete_share(self, context, share, share_server=None):
        """Delete a share."""
        share_name = unity_utils.get_share_backend_id(share)
        try:
            backend_share = self.client.get_share(share_name,
                                                  share['share_proto'])
        except storops_ex.UnityResourceNotFoundError:
            LOG.warning("Share %s is not found when deleting the share",
                        share_name)
            return

        # Share created by the API create_share_from_snapshot()
        if self._is_share_from_snapshot(backend_share):
            filesystem = backend_share.snap.filesystem
            self.client.delete_snapshot(backend_share.snap)
        else:
            filesystem = backend_share.filesystem
            self.client.delete_share(backend_share)

        if self._is_isolated_filesystem(filesystem):
            self.client.delete_filesystem(filesystem)
示例#10
0
    def shrink_share(self, share, new_size, share_server=None):
        """Shrinks a share to new size.

        :param share: Share that will be shrunk.
        :param new_size: New size of share.
        :param share_server: Data structure with share server information.
            Not used by this driver.
        """
        share_id = unity_utils.get_share_backend_id(share)
        backend_share = self.client.get_share(share_id, share['share_proto'])
        if self._is_share_from_snapshot(backend_share):
            reason = ("Driver does not support shrinking a "
                      "snapshot based share.")
            raise exception.ShareShrinkingError(share_id=share_id,
                                                reason=reason)
        self.client.shrink_filesystem(share_id, backend_share.filesystem,
                                      new_size)
        LOG.info("Share %(shr_id)s successfully shrunk to "
                 "%(shr_size)sG.", {
                     'shr_id': share_id,
                     'shr_size': new_size
                 })
示例#11
0
    def manage_existing(self, share, driver_options, share_server=None):
        """Manages a share that exists on backend.

        :param share: Share that will be managed.
        :param driver_options: Driver-specific options provided by admin.
        :param share_server: Share server name provided by admin in DHSS=True.
        :returns: Returns a dict with share size and export location.
        """
        export_locations = share['export_locations']
        if not export_locations:
            message = ("Failed to manage existing share: %s, missing "
                       "export locations." % share['id'])
            raise exception.ManageInvalidShare(reason=message)

        try:
            share_size = int(driver_options.get("size", 0))
        except (ValueError, TypeError):
            msg = _("The driver options' size to manage the share "
                    "%(share_id)s, should be an integer, in format "
                    "driver-options size=<SIZE>. Value specified: "
                    "%(size)s.") % {
                        'share_id': share['id'],
                        'size': driver_options.get("size")
                    }
            raise exception.ManageInvalidShare(reason=msg)

        if not share_size:
            msg = _("Share %(share_id)s has no specified size. "
                    "Using default value 1, set size in driver options if you "
                    "want.") % {
                        'share_id': share['id']
                    }
            LOG.warning(msg)
            share_size = 1

        share_id = unity_utils.get_share_backend_id(share)
        backend_share = self.client.get_share(share_id, share['share_proto'])
        if not backend_share:
            message = ("Could not find the share in backend, please make sure "
                       "the export location is right.")
            raise exception.ManageInvalidShare(reason=message)

        # Check the share server when in DHSS=true mode
        if share_server:
            backend_share_server = self._get_server_name(share_server)
            if not backend_share_server:
                message = ("Could not find the backend share server: %s, "
                           "please make sure that share server with the "
                           "specified name exists in the backend.",
                           share_server)
                raise exception.BadConfigurationException(message)
        LOG.info(
            "Share %(shr_path)s is being managed with ID "
            "%(shr_id)s.", {
                'shr_path': share['export_locations'][0]['path'],
                'shr_id': share['id']
            })
        # export_locations was not changed, return original value
        return {
            "size": share_size,
            'export_locations': {
                'path': share['export_locations'][0]['path']
            }
        }