Exemple #1
0
    def manage_existing_snapshot(self, snapshot, driver_options):
        share = snapshot['share']
        share_name = self._get_zadara_share_template_name(share['id'])

        vpsa_volume = self.vpsa._get_vpsa_volume(share_name)
        if not vpsa_volume:
            msg = (_('Volume %(name)s could not be found. '
                     'It might be already deleted') % {
                         'name': share_name
                     })
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        # Check if the provider_location is specified
        if not snapshot['provider_location']:
            msg = (_('Provider location as snap id of the VPSA backend '
                     'should be provided'))
            LOG.error(msg)
            raise manila_exception.ManilaException(msg)

        new_name = (self.configuration.zadara_share_snap_name_template %
                    snapshot['id'])
        new_snap_id = self.vpsa._get_snap_id(vpsa_volume['cg_name'], new_name)
        if new_snap_id:
            msg = (_('Snapshot with name %s already exists') % new_name)
            LOG.debug(msg)
            return

        data = self.vpsa_send_cmd('rename_snapshot',
                                  snap_id=snapshot['provider_location'],
                                  new_name=new_name)
        if data['status'] != 0:
            raise manila_exception.ZadaraVPSASnapshotManageFailed(
                snap_id=snapshot['provider_location'], error=data['status'])
Exemple #2
0
    def _get_share_export_location(self, share):
        export_location = ''
        share_proto = share['share_proto'].upper()

        share_name = self._get_zadara_share_template_name(share['id'])
        vpsa_volume = self.vpsa._get_vpsa_volume(share_name)
        if not vpsa_volume:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        if share_proto == 'NFS':
            export_location = vpsa_volume['nfs_export_path']
        if share_proto == 'CIFS':
            export_location = vpsa_volume['smb_export_path']
        return export_location
Exemple #3
0
    def create_share_from_snapshot(self,
                                   context,
                                   share,
                                   snapshot,
                                   share_server=None,
                                   parent_share=None):
        """Creates a share from a snapshot.

        """
        LOG.debug('Creating share from snapshot: %s', snapshot['id'])

        # Retrieve the CG name for the base volume
        volume_name = (self._get_zadara_share_template_name(
            snapshot['share_instance_id']))
        cg_name = self.vpsa._get_volume_cg_name(volume_name)
        if not cg_name:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        snap_name = (self.configuration.zadara_share_snap_name_template %
                     snapshot['id'])
        snap_id = self.vpsa._get_snap_id(cg_name, snap_name)
        if not snap_id:
            msg = _('Snapshot %(name)s not found') % {'name': snap_name}
            LOG.error(msg)
            raise manila_exception.ShareSnapshotNotFound(snapshot_id=snap_name)

        self._check_share_protocol(share)

        share_name = self._get_zadara_share_template_name(share['id'])
        self.vpsa_send_cmd('create_clone_from_snap',
                           cg_name=cg_name,
                           name=share_name,
                           snap_id=snap_id)

        if share['size'] > snapshot['size']:
            self.extend_share(share, share['size'])

        export_location = self._get_share_export_location(share)
        return [{'path': export_location}]
Exemple #4
0
    def extend_share(self, share, new_size, share_server=None):
        """Extend an existing share.

        """
        # Get the backend volume name for the share
        share_name = self._get_zadara_share_template_name(share['id'])
        vpsa_volume = self.vpsa._get_vpsa_volume(share_name)
        if not vpsa_volume:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        size = vpsa_volume['virtual_capacity']
        expand_size = new_size - size
        data = self.vpsa_send_cmd('expand_volume',
                                  vpsa_vol=vpsa_volume['name'],
                                  size=expand_size)
        if data['status'] != 0:
            raise manila_exception.ZadaraExtendShareFailed(
                error=data['status'])
Exemple #5
0
    def create_snapshot(self, context, snapshot, share_server=None):
        """Creates a snapshot."""
        LOG.debug('Create snapshot: %s', snapshot['id'])

        # Retrieve the CG name for the base volume
        share = snapshot['share']
        volume_name = self._get_zadara_share_template_name(share['id'])
        cg_name = self.vpsa._get_volume_cg_name(volume_name)
        if not cg_name:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        snap_name = (self.configuration.zadara_share_snap_name_template %
                     snapshot['id'])
        data = self.vpsa_send_cmd('create_snapshot',
                                  cg_name=cg_name,
                                  snap_name=snap_name)
        if data['status'] != 0:
            raise manila_exception.ZadaraVPSASnapshotCreateFailed(
                name=share['id'], error=data['status'])

        return {'provider_location': data['snapshot_name']}
Exemple #6
0
    def _ensure_share(self, context, share, share_server=None):
        """Ensure that the share has a backend volume and it is exported.

        """
        # Get the backend volume name for the share
        share_name = self._get_zadara_share_template_name(share['id'])
        vpsa_volume = self.vpsa._get_vpsa_volume(share_name)
        if not vpsa_volume:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        export_locations = share['export_locations']
        if export_locations:
            return export_locations
        else:
            servers_list = (
                self.vpsa._get_servers_attached_to_volume(vpsa_volume))
            if len(servers_list) != 0:
                msg = (_('Servers attached to the VPSA volume %s without '
                         'any locations exported.') % vpsa_volume['name'])
                LOG.error(msg)
                raise manila_exception.ZadaraShareNotValid(name=share['id'])
Exemple #7
0
    def _allow_access(self, context, share, access):
        """Allow access to the share."""
        access_type = access['access_type']
        share_proto = share['share_proto'].upper()
        if share_proto == 'CIFS':
            share_proto = 'SMB'

        if access_type != 'ip':
            raise manila_exception.ZadaraInvalidShareAccessType()
        access_ip = access['access_to']
        access_level = 'YES'
        if access['access_level'] == 'rw':
            access_level = 'NO'

        # First: Check Active controller: if not valid, raise exception
        ctrl = self.vpsa._get_active_controller_details()
        if not ctrl:
            raise manila_exception.ZadaraVPSANoActiveController()

        # Get volume name
        vol_name = self._get_zadara_share_template_name(share['id'])
        vpsa_volume = self.vpsa._get_vpsa_volume(vol_name)

        if not vpsa_volume:
            msg = (_('VPSA volume for share %s '
                     'could not be found.') % share['id'])
            LOG.error(msg)
            raise manila_exception.ZadaraShareNotFound(name=share['id'])

        # Get/Create server name for given IP
        vpsa_srv = self.vpsa._create_vpsa_server(iscsi_ip=access_ip)
        if not vpsa_srv:
            raise manila_exception.ZadaraServerCreateFailure(name=access_ip)

        servers = self.vpsa._get_servers_attached_to_volume(vpsa_volume)
        attach = None
        for server in servers:
            if server == vpsa_srv:
                attach = server
                break
        # Attach volume to server
        if attach is None:
            self.vpsa_send_cmd('attach_volume',
                               vpsa_srv=vpsa_srv,
                               vpsa_vol=vpsa_volume['name'],
                               share_proto=share_proto,
                               read_only=access_level)

        data = self.vpsa_send_cmd('list_vol_attachments',
                                  vpsa_vol=vpsa_volume['name'])
        server = None
        servers = data.get('servers', [])
        for srv in servers:
            if srv['iscsi_ip'] == access_ip:
                server = srv
                break

        if server is None:
            raise manila_exception.ZadaraAttachmentsNotFound(
                name=vpsa_volume['name'])

        ctrl_ip = self.vpsa._get_target_host(ctrl['ip'])
        properties = {
            'target_discovered': False,
            'target_portal': (('%s:%s') % (ctrl_ip, '3260')),
            'target_ip': server['iscsi_ip'],
            'id': share['id'],
            'auth_method': 'CHAP',
            'auth_username': ctrl['chap_user'],
            'auth_password': ctrl['chap_passwd']
        }

        LOG.debug('Attach properties: %(properties)s',
                  {'properties': strutils.mask_password(properties)})
        return {'driver_volume_type': share['share_proto'], 'data': properties}