Created
May 7, 2024 20:47
-
-
Save hemna/103db2a32983400b95be3190f4072e90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialize_connection(self, volume, connector, initiator_data=None): | |
"""Allow connection to connector and return connection info. | |
:param volume: The volume to be attached. | |
:param connector: Dictionary containing information about what is being | |
connected to. | |
:param initiator_data: (Optional) A dictionary of driver_initiator_data | |
objects with key-value pairs that have been | |
saved for this initiator by a driver in previous | |
initialize_connection calls. | |
:returns: A dictionary of connection information. | |
""" | |
# Check that connection_capabilities match | |
# This ensures the connector is bound to the same vCenter service | |
if 'connection_capabilities' in connector: | |
missing = set(self._get_connection_capabilities()) -\ | |
set(connector['connection_capabilities']) | |
if missing: | |
raise exception.ConnectorRejected( | |
reason="Connector is missing %s" % ', '.join(missing)) | |
fcd_loc = vops.FcdLocation.from_provider_location( | |
self._provider_location_to_moref_location( | |
volume.provider_location | |
) | |
) | |
connection_info = {'driver_volume_type': self.STORAGE_TYPE} | |
# If this is a temporary volume as defined in the admin metadata | |
# then this is for a backup/restore operation and we need to | |
# create a temporary backing for the volume and then pass the | |
# moref location of the backing in the connection_info volume field. | |
backing_moref = None | |
if self._is_temp_volume(volume): | |
backing = self._create_backing(volume) | |
self.volumeops.attach_fcd(backing, fcd_loc) | |
backing_obj = self.volumeops.get_backing_moref(backing) | |
backing_moref = backing_obj.value | |
connection_info['data'] = { | |
'id': fcd_loc.fcd_id, | |
'ds_ref_val': fcd_loc.ds_ref_val, | |
'ds_name': volume_utils.extract_host(volume.host, level='pool'), | |
'adapter_type': self._get_adapter_type(volume), | |
'profile_id': self._get_storage_profile_id(volume), | |
'volume': backing_moref | |
} | |
LOG.debug("Connection info for volume %(name)s: %(connection_info)s.", | |
{'name': volume.name, 'connection_info': connection_info}) | |
return connection_info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment