def _get_vlun(self, volume_name, hostname, lun_id=None, nsp=None): """find a VLUN on a 3PAR host.""" vluns = self.client.getHostVLUNs(hostname) found_vlun = None for vlun in vluns: if volume_name in vlun['volumeName']: if lun_id is not None: if vlun['lun'] == lun_id: if nsp: port = self.build_portPos(nsp) if vlun['portPos'] == port: found_vlun = vlun break else: found_vlun = vlun break else: found_vlun = vlun break if found_vlun is None: LOG.info(_LI("3PAR vlun %(name)s not found on host %(host)s"), { 'name': volume_name, 'host': hostname }) return found_vlun
def has_filesystem(path): try: blkid("-p", "-u", "filesystem", path) except Exception as ex: msg = (_LI('exception is : %s'), six.text_type(ex)) LOG.info(msg) if ex.stdout == '': return False return True
def has_filesystem(path): try: if blkid("-p", "-u", "filesystem", path) == '': return False except Exception as ex: msg = (_LI('exception is : %s'), six.text_type(ex)) LOG.info(msg) if ex.stdout == '': return False return True
def _set_flash_cache_policy_in_vvs(self, flash_cache, vvs_name): # Update virtual volume set if flash_cache: try: self.client.modifyVolumeSet(vvs_name, flashCachePolicy=flash_cache) LOG.info(_LI("Flash Cache policy set to %s"), flash_cache) except Exception as ex: LOG.error(_LE("Error setting Flash Cache policy " "to %s - exception"), flash_cache) exception.PluginException(ex)
def _set_flash_cache_policy_in_vvs(self, flash_cache, vvs_name): # Update virtual volume set if flash_cache: try: self.client.modifyVolumeSet(vvs_name, flashCachePolicy=flash_cache) LOG.info(_LI("Flash Cache policy set to %s"), flash_cache) except Exception as ex: LOG.error( _LE("Error setting Flash Cache policy " "to %s - exception"), flash_cache) exception.PluginException(ex)
def check_for_setup_error(self): LOG.info(_LI("HPE3PARCommon %(common_ver)s," "hpe3parclient %(rest_ver)s"), {"common_ver": self.VERSION, "rest_ver": hpe3parclient.get_version_string()}) self.client_login() try: cpg_names = self.config.hpe3par_cpg for cpg_name in cpg_names: self.validate_cpg(cpg_name) finally: self.client_logout()
def check_for_setup_error(self): """Checks for incorrect LeftHand API being used on backend.""" client = self._login() try: self.api_version = client.getApiVersion() LOG.info(_LI("HPELeftHand API version %s"), self.api_version) if self.api_version < MIN_API_VERSION: LOG.warning(_LW("HPELeftHand API is version %(current)s. " "A minimum version of %(min)s is needed for " "manage/unmanage support."), {'current': self.api_version, 'min': MIN_API_VERSION}) finally: self._logout(client)
def check_for_setup_error(self): LOG.info( _LI("HPE3PARCommon %(common_ver)s," "hpe3parclient %(rest_ver)s"), { "common_ver": self.VERSION, "rest_ver": hpe3parclient.get_version_string() }) self.client_login() try: cpg_names = self.config.hpe3par_cpg for cpg_name in cpg_names: self.validate_cpg(cpg_name) finally: self.client_logout()
def _get_vlun(self, volume_name, hostname, lun_id=None, nsp=None): """find a VLUN on a 3PAR host.""" vluns = self.client.getHostVLUNs(hostname) found_vlun = None for vlun in vluns: if volume_name in vlun['volumeName']: if lun_id is not None: if vlun['lun'] == lun_id: if nsp: port = self.build_portPos(nsp) if vlun['portPos'] == port: found_vlun = vlun break else: found_vlun = vlun break else: found_vlun = vlun break if found_vlun is None: LOG.info(_LI("3PAR vlun %(name)s not found on host %(host)s"), {'name': volume_name, 'host': hostname}) return found_vlun
def delete_vlun(self, volume, hostname): volume_name = self._get_3par_vol_name(volume['id']) vluns = self.client.getHostVLUNs(hostname) # Find all the VLUNs associated with the volume. The VLUNs will then # be split into groups based on the active status of the VLUN. If there # are active VLUNs detected a delete will be attempted on them. If # there are no active VLUNs but there are inactive VLUNs, then the # inactive VLUNs will be deleted. The inactive VLUNs are the templates # on the 3PAR backend. active_volume_vluns = [] inactive_volume_vluns = [] volume_vluns = [] for vlun in vluns: if volume_name in vlun['volumeName']: if vlun['active']: active_volume_vluns.append(vlun) else: inactive_volume_vluns.append(vlun) if active_volume_vluns: volume_vluns = active_volume_vluns elif inactive_volume_vluns: volume_vluns = inactive_volume_vluns if not volume_vluns: msg = ( _LW("3PAR vlun for volume %(name)s not found on " "host %(host)s"), {'name': volume_name, 'host': hostname}) LOG.warning(msg) return # VLUN Type of MATCHED_SET 4 requires the port to be provided removed_luns = [] for vlun in volume_vluns: if self.VLUN_TYPE_MATCHED_SET == vlun['type']: self.client.deleteVLUN(volume_name, vlun['lun'], hostname, vlun['portPos']) else: # This is HOST_SEES or a type that is not MATCHED_SET. # By deleting one VLUN, all the others should be deleted, too. if vlun['lun'] not in removed_luns: self.client.deleteVLUN(volume_name, vlun['lun'], hostname) removed_luns.append(vlun['lun']) # Determine if there are other volumes attached to the host. # This will determine whether we should try removing host from host set # and deleting the host. vluns = [] try: vluns = self.client.getHostVLUNs(hostname) except hpeexceptions.HTTPNotFound: LOG.debug("All VLUNs removed from host %s", hostname) pass for vlun in vluns: if volume_name not in vlun['volumeName']: # Found another volume break else: # We deleted the last vlun, so try to delete the host too. # This check avoids the old unnecessary try/fail when vluns exist # but adds a minor race condition if a vlun is manually deleted # externally at precisely the wrong time. Worst case is leftover # host, so it is worth the unlikely risk. try: self._delete_3par_host(hostname) except Exception as ex: # Any exception down here is only logged. The vlun is deleted. # If the host is in a host set, the delete host will fail and # the host will remain in the host set. This is desired # because docker was not responsible for the host set # assignment. The host set could be used outside of docker # for future needs (e.g. export volume to host set). # The log info explains why the host was left alone. LOG.info(_LI("3PAR vlun for volume '%(name)s' was deleted, " "but the host '%(host)s' was not deleted " "because: %(reason)s"), {'name': volume_name, 'host': hostname, 'reason': ex.get_description()})
def delete_vlun(self, volume, hostname): volume_name = self._get_3par_vol_name(volume['id']) vluns = self.client.getHostVLUNs(hostname) # Find all the VLUNs associated with the volume. The VLUNs will then # be split into groups based on the active status of the VLUN. If there # are active VLUNs detected a delete will be attempted on them. If # there are no active VLUNs but there are inactive VLUNs, then the # inactive VLUNs will be deleted. The inactive VLUNs are the templates # on the 3PAR backend. active_volume_vluns = [] inactive_volume_vluns = [] volume_vluns = [] for vlun in vluns: if volume_name in vlun['volumeName']: if vlun['active']: active_volume_vluns.append(vlun) else: inactive_volume_vluns.append(vlun) if active_volume_vluns: volume_vluns = active_volume_vluns elif inactive_volume_vluns: volume_vluns = inactive_volume_vluns if not volume_vluns: msg = (_LW("3PAR vlun for volume %(name)s not found on " "host %(host)s"), { 'name': volume_name, 'host': hostname }) LOG.warning(msg) return # VLUN Type of MATCHED_SET 4 requires the port to be provided removed_luns = [] for vlun in volume_vluns: if self.VLUN_TYPE_MATCHED_SET == vlun['type']: self.client.deleteVLUN(volume_name, vlun['lun'], hostname, vlun['portPos']) else: # This is HOST_SEES or a type that is not MATCHED_SET. # By deleting one VLUN, all the others should be deleted, too. if vlun['lun'] not in removed_luns: self.client.deleteVLUN(volume_name, vlun['lun'], hostname) removed_luns.append(vlun['lun']) # Determine if there are other volumes attached to the host. # This will determine whether we should try removing host from host set # and deleting the host. vluns = [] try: vluns = self.client.getHostVLUNs(hostname) except hpeexceptions.HTTPNotFound: LOG.debug("All VLUNs removed from host %s", hostname) pass for vlun in vluns: if volume_name not in vlun['volumeName']: # Found another volume break else: # We deleted the last vlun, so try to delete the host too. # This check avoids the old unnecessary try/fail when vluns exist # but adds a minor race condition if a vlun is manually deleted # externally at precisely the wrong time. Worst case is leftover # host, so it is worth the unlikely risk. try: self._delete_3par_host(hostname) except Exception as ex: # Any exception down here is only logged. The vlun is deleted. # If the host is in a host set, the delete host will fail and # the host will remain in the host set. This is desired # because docker was not responsible for the host set # assignment. The host set could be used outside of docker # for future needs (e.g. export volume to host set). # The log info explains why the host was left alone. LOG.info( _LI("3PAR vlun for volume '%(name)s' was deleted, " "but the host '%(host)s' was not deleted " "because: %(reason)s"), { 'name': volume_name, 'host': hostname, 'reason': ex.get_description() })