def volume_path(self, with_no_wait=False): """ Return the device path pf a volume which is the actual location of the device such as /dev/scinia, or dev/scinix. :param with_no_wait: Whether wait for the volume occures in host device list :return: Device path of volume """ if self.full_device_path and os.path.exists(self.full_device_path): return self.full_device_path tries = 1 disk_device = '' if with_no_wait: disk_device = self._find_volume_device(LOCAL_DEVICES_PATH) if disk_device: LOG.debug('Found ScaleIO device path %s', disk_device) return os.path.join(LOCAL_DEVICES_PATH, disk_device) else: LOG.debug('No ScaleIO device path for volume %s', self.id) return None while not disk_device and tries <= MAX_HOST_DEVICE_RENEWAL_CHECKS: disk_device = self._find_volume_device(LOCAL_DEVICES_PATH) if not disk_device: tries += 1 time.sleep(HOST_DEVICE_RENEWAL_CHECK_INTERVAL) if not disk_device: LOG.warn('Could not find ScaleIO device path for volume %s', self.id) raise exceptions.VolumeNotMapped( "Device path is not found for volume '%s'" % self.id) LOG.debug('Found ScaleIO device path %s', disk_device) self.full_device_path = os.path.join(LOCAL_DEVICES_PATH, disk_device) return self.full_device_path
def _unmap_volume(self, volume_id, sdc_guid=None, unmap_all=False): """ Private method unmaps a volume from one or all SDCs. :param volume_id: ScaleIO volume ID :param sdc_guid: Unique SDC identifier :param unmap_all: True, unmap from all SDCs, False only unmap from local SDC :return: Nothing """ if not unmap_all: if not sdc_guid: raise ValueError( 'sdc_guid must be specified or unmap_all must be True') else: LOG.debug('Using ScaleIO SDC client GUID %s for ' 'unmap operation.' % sdc_guid) if unmap_all: # unmap from all sdcs params = {'allSdcs': ''} else: # only unmap from local sdc params = {'guid': sdc_guid} r_uri = '/api/instances/Volume::' + \ volume_id + '/action/removeMappedSdc' req = self._post(r_uri, params=params) if req.status_code == 200: # success LOG.debug('Unmapped volume %s successfully', volume_id) elif req.json().get('errorCode') == VOLUME_NOT_MAPPED_ERROR: LOG.warn('Volume %s cannot be unmapped: %s', volume_id, req.json().get('message')) raise exceptions.VolumeNotMapped("Volume '%s' is not mapped" % volume_id) else: raise exceptions.Error("Error unmapping volume '%s': %s" % (volume_id, req.json().get('message')))