def test_check_share_in_use_incorrect_host(self): drv = self._driver mox = self.mox mox.StubOutWithMock(utils, 'resolve_hostname') utils.resolve_hostname(IgnoreArg()).AndRaise(Exception()) mox.ReplayAll() share = drv._check_share_in_use('incorrect:8989', '/dir') mox.VerifyAll() if share: self.fail('Unexpected share detected.')
def test_check_share_in_use_incorrect_host(self): drv = self._driver mox = self.mox mox.StubOutWithMock(utils, 'resolve_hostname') utils.resolve_hostname(IgnoreArg()).AndRaise(Exception()) mox.ReplayAll() share = drv._check_share_in_use('incorrect:8989', '/dir') mox.VerifyAll() if share: self.fail('Unexpected share detected.')
def test_check_share_in_use_success(self): drv = self._driver mox = self.mox drv._mounted_shares = ['127.0.0.1:/dir/share'] mox.StubOutWithMock(utils, 'resolve_hostname') mox.StubOutWithMock(drv, '_share_match_for_ip') utils.resolve_hostname(IgnoreArg()).AndReturn('10.22.33.44') drv._share_match_for_ip('10.22.33.44', ['127.0.0.1:/dir/share']).AndReturn('share') mox.ReplayAll() share = drv._check_share_in_use('127.0.0.1:8989', '/dir/share') mox.VerifyAll() if not share: self.fail('Expected share not detected')
def test_check_share_in_use_success(self): drv = self._driver mox = self.mox drv._mounted_shares = ['127.0.0.1:/dir/share'] mox.StubOutWithMock(utils, 'resolve_hostname') mox.StubOutWithMock(drv, '_share_match_for_ip') utils.resolve_hostname(IgnoreArg()).AndReturn('10.22.33.44') drv._share_match_for_ip( '10.22.33.44', ['127.0.0.1:/dir/share']).AndReturn('share') mox.ReplayAll() share = drv._check_share_in_use('127.0.0.1:8989', '/dir/share') mox.VerifyAll() if not share: self.fail('Expected share not detected')
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 = share.split(':')[0] junction_path = share.split(':')[1] address = na_utils.resolve_hostname(host) if address not in vserver_addresses: msg = _LW('Address not found for NFS share %s.') LOG.warning(msg, share) continue try: flexvol = self.zapi_client.get_flexvol( flexvol_path=junction_path) pools[flexvol['name']] = {'pool_name': share} except exception.VolumeBackendAPIException: msg = _LE('Flexvol not found for NFS share %s.') LOG.exception(msg, share) return pools
def _check_mode_get_or_register_storage_system(self): """Does validity checks for storage system registry and health.""" def _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error( _('Error resolving host %(host)s. Error - %(e)s.') % { 'host': host, 'e': e }) return None ips = self.configuration.netapp_controller_ips ips = [i.strip() for i in ips.split(",")] ips = [x for x in ips if _resolve_host(x)] host = utils.resolve_hostname( self.configuration.netapp_server_hostname) if not ips: msg = _('Controller ips not valid after resolution.') raise exception.NoValidHost(reason=msg) if host in ips: LOG.info(_('Embedded mode detected.')) system = self._client.list_storage_systems()[0] else: LOG.info(_('Proxy mode detected.')) system = self._client.register_storage_system( ips, password=self.configuration.netapp_sa_password) self._client.set_system_id(system.get('id'))
def _check_mode_get_or_register_storage_system(self): """Does validity checks for storage system registry and health.""" def _resolve_host(host): try: ip = na_utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_LE('Error resolving host %(host)s. Error - %(e)s.') % {'host': host, 'e': e}) raise exception.NoValidHost( _("Controller IP '%(host)s' could not be resolved: %(e)s.") % {'host': host, 'e': e}) ips = self.configuration.netapp_controller_ips ips = [i.strip() for i in ips.split(",")] ips = [x for x in ips if _resolve_host(x)] host = na_utils.resolve_hostname( self.configuration.netapp_server_hostname) if host in ips: LOG.info(_LI('Embedded mode detected.')) system = self._client.list_storage_systems()[0] else: LOG.info(_LI('Proxy mode detected.')) system = self._client.register_storage_system( ips, password=self.configuration.netapp_sa_password) self._client.set_system_id(system.get('id'))
def _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_("Error resolving host %(host)s. Error - %(e)s.") % {"host": host, "e": e}) return None
def _check_mode_get_or_register_storage_system(self): """Does validity checks for storage system registry and health.""" def _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_("Error resolving host %(host)s. Error - %(e)s.") % {"host": host, "e": e}) return None ips = self.configuration.netapp_controller_ips ips = [i.strip() for i in ips.split(",")] ips = [x for x in ips if _resolve_host(x)] host = utils.resolve_hostname(self.configuration.netapp_server_hostname) if not ips: msg = _("Controller ips not valid after resolution.") raise exception.NoValidHost(reason=msg) if host in ips: LOG.info(_("Embedded mode detected.")) system = self._client.list_storage_systems()[0] else: LOG.info(_("Proxy mode detected.")) system = self._client.register_storage_system(ips, password=self.configuration.netapp_sa_password) self._client.set_system_id(system.get("id"))
def _get_ip_verify_on_cluster(self, host): """Verifies if host on same cluster and returns ip.""" ip = na_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 _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_('Error resolving host %(host)s. Error - %(e)s.') % {'host': host, 'e': e}) return None
def _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_('Error resolving host %(host)s. Error - %(e)s.') % {'host': host, 'e': e}) return None
def _get_ip_verify_on_cluster(self, host): """Verifies if host on same cluster and returns ip.""" ip = na_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 _resolve_host(host): try: ip = na_utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_LE("Error resolving host %(host)s. Error - %(e)s."), {"host": host, "e": e}) raise exception.NoValidHost( _("Controller IP '%(host)s' could not be resolved: %(e)s.") % {"host": host, "e": e} )
def _resolve_host(host): try: ip = na_utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_LE('Error resolving host %(host)s. Error - %(e)s.'), {'host': host, 'e': e}) raise exception.NoValidHost( _("Controller IP '%(host)s' could not be resolved: %(e)s.") % {'host': host, 'e': e})
def _resolve_host(host): try: ip = utils.resolve_hostname(host) return ip except socket.gaierror as e: LOG.error(_('Error resolving host %(host)s. Error - %(e)s.') % {'host': host, 'e': e}) raise exception.NoValidHost( _("Controller IP '%(host)s' could not be resolved: %(e)s.") % {'host': host, 'e': e})
def get_if_info_by_ip(self, ip): """Gets the network interface info by ip.""" net_if_iter = netapp_api.NaElement('net-interface-get-iter') net_if_iter.add_new_child('max-records', '10') query = netapp_api.NaElement('query') net_if_iter.add_child_elem(query) query.add_node_with_children( 'net-interface-info', **{'address': na_utils.resolve_hostname(ip)}) result = self.connection.invoke_successfully(net_if_iter, True) num_records = result.get_child_content('num-records') if num_records and int(num_records) >= 1: attr_list = result.get_child_by_name('attributes-list') return attr_list.get_children() raise exception.NotFound( _('No interface found on cluster for ip %s') % ip)
def get_if_info_by_ip(self, ip): """Gets the network interface info by ip.""" net_if_iter = netapp_api.NaElement('net-interface-get-iter') net_if_iter.add_new_child('max-records', '10') query = netapp_api.NaElement('query') net_if_iter.add_child_elem(query) query.add_node_with_children( 'net-interface-info', **{'address': na_utils.resolve_hostname(ip)}) result = self.connection.invoke_successfully(net_if_iter, True) num_records = result.get_child_content('num-records') if num_records and int(num_records) >= 1: attr_list = result.get_child_by_name('attributes-list') return attr_list.get_children() raise exception.NotFound( _('No interface found on cluster for ip %s') % ip)
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 = na_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(_LW("Unexpected exception while " "short listing used share.")) return None
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 = na_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 _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 = na_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 refresh_ssc_vols(self, vols): """Refreshes ssc_vols with latest entries.""" if not self._mounted_shares: LOG.warning(_LW("No shares found hence skipping ssc refresh.")) return mnt_share_vols = set() vs_ifs = self.zapi_client.get_vserver_ips(self.vserver) for vol in vols["all"]: for sh in self._mounted_shares: host = sh.split(":")[0] junction = sh.split(":")[1] ip = na_utils.resolve_hostname(host) if self._ip_in_ifs(ip, vs_ifs) and junction == vol.id["junction_path"]: mnt_share_vols.add(vol) vol.export["path"] = sh break for key in vols.keys(): vols[key] = vols[key] & mnt_share_vols self.ssc_vols = vols
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 = na_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(_LW("Unexpected exception while " "short listing used share.")) return None
def refresh_ssc_vols(self, vols): """Refreshes ssc_vols with latest entries.""" if not self._mounted_shares: LOG.warning(_LW("No shares found hence skipping ssc refresh.")) return mnt_share_vols = set() vs_ifs = self.zapi_client.get_vserver_ips(self.vserver) for vol in vols['all']: for sh in self._mounted_shares: host = sh.split(':')[0] junction = sh.split(':')[1] ip = na_utils.resolve_hostname(host) if (self._ip_in_ifs(ip, vs_ifs) and junction == vol.id['junction_path']): mnt_share_vols.add(vol) vol.export['path'] = sh break for key in vols.keys(): vols[key] = vols[key] & mnt_share_vols self.ssc_vols = vols
def _share_match_for_ip(self, ip, shares): """Returns the share that is served by ip. Multiple shares can have same dir path but can be served using different ips. It finds the share which is served by ip on same nfs server. """ raise NotImplementedError() 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 = na_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(_LW("Unexpected exception while " "short listing used share.")) return None def _construct_image_nfs_url(self, image_location):