def _is_share_in_use(self, conn, dr): """Checks if share is cinder mounted and returns it.""" try: if conn: host = conn.split(':')[0] ip = utils.resolve_hostname(host) for sh in self._mounted_shares + self._mounted_image_shares: sh_ip = utils.resolve_hostname(sh.split(':')[0]) sh_exp = sh.split(':')[1] if sh_ip == ip and sh_exp == dr: LOG.debug('Found share match %s', sh) return sh except Exception: LOG.warning('Unexpected exception while listing used share.')
def _convert_vol_ref_share_name_to_share_ip(self, vol_ref): """Converts the share point name to an IP address. The volume reference may have a DNS name portion in the share name. Convert that to an IP address and then restore the entire path. :param vol_ref: driver-specific information used to identify a volume :return: a volume reference where share is in IP format """ # First strip out share and convert to IP format. share_split = vol_ref.split(':') try: vol_ref_share_ip = cutils.resolve_hostname(share_split[0]) except socket.gaierror as e: LOG.error(_LE('Invalid hostname %(host)s'), {'host': share_split[0]}) LOG.debug('error: %s', e.strerror) raise # Now place back into volume reference. vol_ref_share = vol_ref_share_ip + ':' + share_split[1] return vol_ref_share
def _convert_vol_ref_share_name_to_share_ip(self, vol_ref): """Converts the share point name to an IP address. The volume reference may have a DNS name portion in the share name. Convert that to an IP address and then restore the entire path. :param vol_ref: driver-specific information used to identify a volume :returns: a volume reference where share is in IP format or raises error :raises e.strerror: """ # First strip out share and convert to IP format. share_split = vol_ref.split(':') try: vol_ref_share_ip = cutils.resolve_hostname(share_split[0]) except socket.gaierror as e: LOG.exception('Invalid hostname %(host)s', {'host': share_split[0]}) LOG.debug('error: %(err)s', {'err': e.strerror}) raise # Now place back into volume reference. vol_ref_share = vol_ref_share_ip + ':' + share_split[1] return vol_ref_share
def _get_flexvol_to_pool_map(self): """Get the flexvols that back all mounted shares. The map is of the format suitable for seeding the storage service catalog: {<flexvol_name> : {'pool_name': <share_path>}} """ pools = {} vserver_addresses = self.zapi_client.get_operational_lif_addresses() for share in self._mounted_shares: host, junction_path = na_utils.get_export_host_junction_path(share) address = utils.resolve_hostname(host) if address not in vserver_addresses: LOG.warning('Address not found for NFS share %s.', share) continue try: flexvol = self.zapi_client.get_flexvol( flexvol_path=junction_path) pools[flexvol['name']] = {'pool_name': share} except exception.VolumeBackendAPIException: LOG.exception('Flexvol not found for NFS share %s.', share) return pools
def _get_ip_verify_on_cluster(self, host): """Verifies if host on same cluster and returns ip.""" ip = utils.resolve_hostname(host) vserver = self._get_vserver_for_ip(ip) if not vserver: raise exception.NotFound(_("Unable to locate an SVM that is " "managing the IP address '%s'") % ip) return ip
def _convert_vol_ref_share_name_to_share_ip(self, vol_ref): """Converts the share point name to an IP address The volume reference may have a DNS name portion in the share name. Convert that to an IP address and then restore the entire path. :param vol_ref: Driver-specific information used to identify a volume :return: A volume reference where share is in IP format. """ # First strip out share and convert to IP format. share_split = vol_ref.rsplit(':', 1) vol_ref_share_ip = utils.resolve_hostname(share_split[0]) # Now place back into volume reference. vol_ref_share = vol_ref_share_ip + ':' + share_split[1] return vol_ref_share
def _check_share_in_use(self, conn, dir): """Checks if share is cinder mounted and returns it.""" try: if conn: host = conn.split(':')[0] ip = utils.resolve_hostname(host) share_candidates = [] for sh in self._mounted_shares: sh_exp = sh.split(':')[-1] if sh_exp == dir: share_candidates.append(sh) if share_candidates: LOG.debug('Found possible share matches %s', share_candidates) return self._share_match_for_ip(ip, share_candidates) except Exception: LOG.warning("Unexpected exception while " "short listing used share.") return None
def _convert_volume_share(self, volume_share): """Converts the share name to IP address.""" share_split = volume_share.rsplit(':', 1) return utils.resolve_hostname(share_split[0]) + ':' + share_split[1]
def do_setup(self, context): """Setup - create multiple elements. Project, initiators, initiatorgroup, target and targetgroup. """ lcfg = self.configuration LOG.info(_LI("Connecting to host: %s."), lcfg.san_ip) self.zfssa = factory_zfssa() self.tgt_zfssa = factory_zfssa() self.zfssa.set_host(lcfg.san_ip, timeout=lcfg.zfssa_rest_timeout) auth_str = "%s:%s" % (lcfg.san_login, lcfg.san_password) auth_str = base64.encode_as_text(auth_str) self.zfssa.login(auth_str) self.zfssa.create_project( lcfg.zfssa_pool, lcfg.zfssa_project, compression=lcfg.zfssa_lun_compression, logbias=lcfg.zfssa_lun_logbias ) schemas = [{"property": "cinder_managed", "description": "Managed by Cinder", "type": "Boolean"}] if lcfg.zfssa_enable_local_cache: self.zfssa.create_project( lcfg.zfssa_pool, lcfg.zfssa_cache_project, compression=lcfg.zfssa_lun_compression, logbias=lcfg.zfssa_lun_logbias, ) schemas.extend( [ {"property": "image_id", "description": "OpenStack image ID", "type": "String"}, {"property": "updated_at", "description": "Most recent updated time of image", "type": "String"}, ] ) self.zfssa.create_schemas(schemas) if lcfg.zfssa_initiator_config != "": initiator_config = ast.literal_eval(lcfg.zfssa_initiator_config) for initiator_group in initiator_config: zfssa_initiator_group = initiator_group for zfssa_initiator in initiator_config[zfssa_initiator_group]: self.zfssa.create_initiator( zfssa_initiator["iqn"], zfssa_initiator_group + "-" + zfssa_initiator["iqn"], chapuser=zfssa_initiator["user"], chapsecret=zfssa_initiator["password"], ) if zfssa_initiator_group != "default": self.zfssa.add_to_initiatorgroup(zfssa_initiator["iqn"], zfssa_initiator_group) else: LOG.warning(_LW("zfssa_initiator_config not found. " "Using deprecated configuration options.")) if not lcfg.zfssa_initiator and ( not lcfg.zfssa_initiator_group and lcfg.zfssa_initiator_group != "default" ): LOG.error(_LE("zfssa_initiator cannot be empty when " "creating a zfssa_initiator_group.")) raise exception.InvalidConfigurationValue(value="", option="zfssa_initiator") if lcfg.zfssa_initiator != "" and ( lcfg.zfssa_initiator_group == "" or lcfg.zfssa_initiator_group == "default" ): LOG.warning( _LW("zfssa_initiator: %(ini)s" " wont be used on " "zfssa_initiator_group= %(inigrp)s."), {"ini": lcfg.zfssa_initiator, "inigrp": lcfg.zfssa_initiator_group}, ) # Setup initiator and initiator group if ( lcfg.zfssa_initiator != "" and lcfg.zfssa_initiator_group != "" and lcfg.zfssa_initiator_group != "default" ): for initiator in lcfg.zfssa_initiator.split(","): initiator = initiator.strip() self.zfssa.create_initiator( initiator, lcfg.zfssa_initiator_group + "-" + initiator, chapuser=lcfg.zfssa_initiator_user, chapsecret=lcfg.zfssa_initiator_password, ) self.zfssa.add_to_initiatorgroup(initiator, lcfg.zfssa_initiator_group) # Parse interfaces interfaces = [] for intrface in lcfg.zfssa_target_interfaces.split(","): if intrface == "": continue interfaces.append(intrface) # Setup target and target group iqn = self.zfssa.create_target( self._get_target_alias(), interfaces, tchapuser=lcfg.zfssa_target_user, tchapsecret=lcfg.zfssa_target_password, ) self.zfssa.add_to_targetgroup(iqn, lcfg.zfssa_target_group) if lcfg.zfssa_manage_policy not in ("loose", "strict"): err_msg = ( _("zfssa_manage_policy property needs to be set to" " 'strict' or 'loose'. Current value is: %s.") % lcfg.zfssa_manage_policy ) LOG.error(err_msg) raise exception.InvalidInput(reason=err_msg) # Lookup the zfssa_target_portal DNS name to an IP address host, port = lcfg.zfssa_target_portal.split(":") host_ip_addr = utils.resolve_hostname(host) self.zfssa_target_portal = host_ip_addr + ":" + port