cinder 之driver 的实现

来源:互联网 发布:photoshop盖印图层 mac 编辑:程序博客网 时间:2024/05/21 23:33

自定义driver 首先按照类型实现实现接口:如下是iSCSI的驱动实现接口

class NECISCSIDriver(ISCSIDriver):    """Any initialization the volume driver does while starting."""    def check_for_setup_error(self):        raise NotImplementedError()    def create_volume(self, volume):        """Creates a volume. Can optionally return a Dictionary of        changes to the volume object to be persisted.        """        raise NotImplementedError()    def create_volume_from_snapshot(self, volume, snapshot):        """Creates a volume from a snapshot."""        raise NotImplementedError()    def create_cloned_volume(self, volume, src_vref):        """Creates a clone of the specified volume."""        raise NotImplementedError()    def delete_volume(self, volume):        """Deletes a volume."""        raise NotImplementedError()    def create_snapshot(self, snapshot):        """Creates a snapshot."""        raise NotImplementedError()    def delete_snapshot(self, snapshot):        """Deletes a snapshot."""        raise NotImplementedError()X    def local_path(self, volume):"""Return the local path for the specified volume."""        raise NotImplementedError()    def ensure_export(self, context, volume):        """Synchronously recreates an export for a volume."""        raise NotImplementedError()    def create_export(self, context, volume):        """Exports the volume. Can optionally return a Dictionary of changes        to the volume object to be persisted.        """        raise NotImplementedError()    def remove_export(self, context, volume):        """Removes an export for a volume."""        raise NotImplementedError()X    def initialize_connection(self, volume, connector):        """Allow connection to connector and return connection info."""#iscsi has defult handler        raise NotImplementedError()    def terminate_connection(self, volume, connector, **kwargs):        """Disallow connection from connector"""#iscsi has defult handler        raise NotImplementedError()        def validate_connector(self, connector):        """Fail if connector doesn't contain all the data needed by driver."""#iscsi has defult handler        pass    X    def attach_volume(self, context, volume, instance_uuid, host_name,                      mountpoint):        """Callback for volume attached to instance or host."""        passX    def detach_volume(self, context, volume):        """Callback for volume detached."""        pass    def get_volume_stats(self, refresh=False):        """Return the current state of the volume service. If 'refresh' is           True, run the update first.        """#iscsi has default handler        return None    def do_setup(self, context):        """Any initialization the volume driver does while starting."""        pass    def copy_volume_data(self, context, src_vol, dest_vol, remote=None):        """Copy data from src_vol to dest_vol."""    pass#has default handler    def copy_image_to_volume(self, context, volume, image_service, image_id):"""Fetch the image from image_service and write it to the volume."""pass#has default handler        def copy_volume_to_image(self, context, volume, image_service, image_meta):"""Copy the volume to the specified image."""    pass#has default handler    def clone_image(self, volume, image_location, image_id, image_meta):        """Create a volume efficiently from an existing image.        image_location is a string whose format depends on the        image service backend in use. The driver should use it        to determine whether cloning is possible.        image_id is a string which represents id of the image.        It can be used by the driver to introspect internal        stores or registry to do an efficient image clone.        image_meta is a dictionary that includes 'disk_format' (e.g.        raw, qcow2) and other image attributes that allow drivers to        decide whether they can clone the image without first requiring        conversion.        Returns a dict of volume properties eg. provider_location,        boolean indicating whether cloning occurred        """        return None, False    def backup_volume(self, context, backup, backup_service):        """Create a new backup from an existing volume."""pass#has default handler    def restore_backup(self, context, backup, volume, backup_service):        """Restore an existing backup to a new or existing volume."""pass#has default handler    def clear_download(self, context, volume):        """Clean up after an interrupted image copy."""        pass    def extend_volume(self, volume, new_size):        msg = _("Extend volume not implemented")        raise NotImplementedError(msg)    def migrate_volume(self, context, volume, host):        """Migrate the volume to the specified host.        Returns a boolean indicating whether the migration occurred, as well as        model_update.        :param ctxt: Context        :param volume: A dictionary describing the volume to migrate        :param host: A dictionary describing the host to migrate to, where                     host['host'] is its name, and host['capabilities'] is a                     dictionary of its reported capabilities.        """        return (False, None)    def retype(self, context, volume, new_type, diff, host):        """Convert the volume to be of the new type.        Returns a boolean indicating whether the retype occurred.        :param ctxt: Context        :param volume: A dictionary describing the volume to migrate        :param new_type: A dictionary describing the volume type to convert to        :param diff: A dictionary with the difference between the two types        :param host: A dictionary describing the host to migrate to, where                     host['host'] is its name, and host['capabilities'] is a                     dictionary of its reported capabilities.        """        return False    def accept_transfer(self, context, volume, new_user, new_project):        """Accept the transfer of a volume for a new user/project."""        pass    def manage_existing(self, volume, existing_ref):        """Brings an existing backend storage object under Cinder management.        existing_ref is passed straight through from the API request's        manage_existing_ref value, and it is up to the driver how this should        be interpreted.  It should be sufficient to identify a storage object        that the driver should somehow associate with the newly-created cinder        volume structure.        There are two ways to do this:        1. Rename the backend storage object so that it matches the,           volume['name'] which is how drivers traditionally map between a           cinder volume and the associated backend storage object.        2. Place some metadata on the volume, or somewhere in the backend, that           allows other driver requests (e.g. delete, clone, attach, detach...)           to locate the backend storage object when required.        If the existing_ref doesn't make sense, or doesn't refer to an existing        backend storage object, raise a ManageExistingInvalidReference        exception.        The volume may have a volume_type, and the driver can inspect that and        compare against the properties of the referenced backend storage        object.  If they are incompatible, raise a        ManageExistingVolumeTypeMismatch, specifying a reason for the failure.        """        msg = _("Manage existing volume not implemented.")        raise NotImplementedError(msg)    def manage_existing_get_size(self, volume, existing_ref):        """Return size of volume to be managed by manage_existing.        When calculating the size, round up to the next GB.        """        msg = _("Manage existing volume not implemented.")        raise NotImplementedError(msg)    def unmanage(self, volume):"""Removes the specified volume from Cinder management.Does not delete the underlying backend storage object.For most drivers, this will not need to do anything.  However, somedrivers might use this call as an opportunity to clean up anyCinder-specific configuration that they have associated with thebackend storage object."""pass    ##############################################################################    def _do_iscsi_discovery(self, volume):pass #has default handler        def _get_iscsi_properties(self, volume):"""Gets iscsi configurationWe ideally get saved information in the volume entity, but fall backto discovery if need be. Discovery may be completely removed in futureThe properties are:    :target_discovered:    boolean indicating whether discovery was used     :target_iqn:    the IQN of the iSCSI target    :target_portal:    the portal of the iSCSI target    :target_lun:    the lun of the iSCSI target    :volume_id:    the id of the volume (currently used by xen)    :auth_method:, :auth_username:, :auth_password:       the authentication details. Right now, either auth_method is notpresent meaning no authentication, or auth_method == `CHAP`meaning use CHAP with the specified credentials.           :access_mode:    the volume access mode allow client used('rw' or 'ro' currently supported)"""    pass #has default handler        def get_target_helper(self, db):pass #has default handler

这些接口调用参考VolumeManager,

选择所需要的接口重载

 

 

 

0 0
原创粉丝点击