def get_volume_stats(self, refresh=False): if refresh: if self.storage_info['output_first']: self.storage_info['output_first'] = False utils.output_log(3, config_group=self.conf.config_group) self._update_volume_stats() return self._stats
def _run_add_lun(self, ldev, port, gid, lun=None): args = ['add', 'lun', '-port', '-'.join([port, gid]), '-ldev_id', ldev] ignore_error = [_LU_PATH_DEFINED] if lun: args.extend(['-lun_id', lun]) ignore_error = [_ANOTHER_LDEV_MAPPED] result = self.run_raidcom( *args, ignore_error=ignore_error, interval=_LUN_RETRY_INTERVAL, timeout=_LUN_MAX_WAITTIME) if not lun: if result[0] == EX_CMDRJE: lun = self._find_lun(ldev, port, gid) LOG.debug( 'An logical unit path has already defined in the ' 'specified logical device. (LDEV: %s, port: %s, gid: %s, ' 'lun: %s)', ldev, port, gid, lun) else: lun = find_value(result[1], 'lun') elif _ANOTHER_LDEV_MAPPED in result[2]: utils.output_log(314, ldev=ldev, port=port, id=gid, lun=lun) return None LOG.debug( 'Created logical unit path to the specified logical device. ' '(LDEV: %s, port: %s, gid: %s, lun: %s)', ldev, port, gid, lun) return lun
def output_param_to_log(self): utils.output_log(1, config_group=self.conf.config_group) name, version = self.get_storage_cli_info() utils.output_storage_cli_info(name, version) utils.output_opt_info(self.conf, _INHERITED_VOLUME_OPTS) utils.output_opts(self.conf, opts.COMMON_VOLUME_OPTS) utils.output_opts(self.conf, self.driver_info['volume_opts'])
def _delete_ldev_from_storage(self, ldev): result = self.run_raidcom( 'get', 'ldev', '-ldev_id', ldev, *_LDEV_DELETED, do_raise=False) if not result[0]: utils.output_log(319, ldev=ldev) return self.run_raidcom('delete', 'ldev', '-ldev_id', ldev)
def discard_zero_page(self, volume): ldev = utils.get_ldev(volume) try: self.run_raidcom( 'modify', 'ldev', '-ldev_id', ldev, '-status', 'discard_zero_page') except exception.HPEXPError: utils.output_log(315, ldev=ldev)
def copy_dest_vol_meta_to_src_vol(self, src_vol, dest_vol): metadata = utils.get_volume_metadata(dest_vol) try: self.db.volume_metadata_update( self.ctxt, src_vol['id'], metadata, True) except Exception as ex: utils.output_log( 318, src_vol_id=src_vol['id'], dest_vol_id=dest_vol['id'], reason=six.text_type(ex))
def map_ldev(self, targets, ldev): port, gid = targets['list'][0] lun = self._run_add_lun(ldev, port, gid) for port, gid in targets['list'][1:]: try: self._run_add_lun(ldev, port, gid, lun=lun) except exception.HPEXPError: utils.output_log(314, ldev=ldev, port=port, id=gid, lun=lun) return lun
def _start_horcmgr(self, horcmgr): inst = self.conf.hpexp_horcm_numbers[horcmgr] ret = 0 if _run_horcmgr(inst) != _HORCM_RUNNING: ret = _run_horcmstart(inst) if ret and ret != _HORCM_RUNNING: utils.output_log(320, inst=inst) return False return True
def _retry_login(self, ignore_enauth, do_login): if not ignore_enauth: if not do_login: result = self._run_raidcom_login(do_raise=False) if do_login or result[0]: utils.output_log(323, user=self.conf.hpexp_horcm_user) return False return True
def get_copy_method(self, metadata): method = metadata.get( 'copy_method', self.conf.hpexp_default_copy_method) if method not in _COPY_METHOD: msg = utils.output_log(602, meta='copy_method') raise exception.HPEXPError(data=msg) if method == 'THIN' and not self.conf.hpexp_thin_pool: msg = utils.output_log(601, param='hpexp_thin_pool') raise exception.HPEXPError(data=msg) return method
def _copy_on_host(self, src_ldev, size): dest_ldev = self.create_ldev(size) try: self._copy_with_dd(src_ldev, dest_ldev, size) except Exception: with excutils.save_and_reraise_exception(): try: self._delete_ldev(dest_ldev) except exception.HPEXPError: utils.output_log(313, ldev=dest_ldev) return dest_ldev, utils.NORMAL_LDEV_TYPE
def _initialize_pair_connection(self, ldev): port, gid = None, None for port, gid in self._pair_targets: try: return self.map_ldev({'list': [(port, gid)]}, ldev) except exception.HPEXPError: utils.output_log(314, ldev=ldev, port=port, id=gid, lun=None) msg = utils.output_log(639, ldev=ldev) raise exception.HPEXPError(msg)
def _detach_ldev(self, attach_info, ldev, properties): volume = { 'provider_location': six.text_type(ldev), } connector = attach_info['connector'] try: connector.disconnect_volume( attach_info['conn']['data'], attach_info['device']) except Exception as ex: utils.output_log(329, ldev=ldev, reason=six.text_type(ex)) self._terminate_connection(volume, properties)
def delete_volume(self, volume): ldev = utils.get_ldev(volume) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is not None'. if ldev is None: utils.output_log(304, method='delete_volume', id=volume['id']) return try: self._delete_ldev(ldev) except exception.HPEXPBusy: raise exception.HPEXPVolumeIsBusy(volume_name=volume['name'])
def extend_volume(self, volume, new_size): ldev = utils.get_ldev(volume) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is None'. if ldev is None: msg = utils.output_log(613, volume_id=volume['id']) raise exception.HPEXPError(data=msg) if self.check_vvol(ldev): msg = utils.output_log(618, volume_id=volume['id']) raise exception.HPEXPError(data=msg) self.delete_pair(ldev) self.extend_ldev(ldev, volume['size'], new_size)
def create_volume(self, volume): try: ldev = self.create_ldev(volume['size']) except Exception: with excutils.save_and_reraise_exception(): utils.output_log(636) metadata = volume.get('metadata', {}) return { 'provider_location': six.text_type(ldev), 'metadata': dict( metadata, ldev=ldev, type=utils.NORMAL_LDEV_TYPE), }
def delete_snapshot(self, snapshot): ldev = utils.get_ldev(snapshot) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is None'. if ldev is None: utils.output_log( 304, method='delete_snapshot', id=snapshot['id']) return try: self._delete_ldev(ldev) except exception.HPEXPBusy: raise exception.HPEXPSnapshotIsBusy(snapshot_name=snapshot['name'])
def copy_on_storage(self, pvol, size, metadata): is_thin = self.get_copy_method(metadata) == "THIN" ldev_type = utils.VVOL_LDEV_TYPE if is_thin else utils.NORMAL_LDEV_TYPE svol = self.create_ldev(size, is_vvol=is_thin) try: self.create_pair_on_storage(pvol, svol, is_thin) except Exception: with excutils.save_and_reraise_exception(): try: self._delete_ldev(svol) except exception.HPEXPError: utils.output_log(313, ldev=svol) return svol, ldev_type
def manage_existing_get_size(self, dummy_volume, existing_ref): if existing_ref.get('storage_id') != self.conf.hpexp_storage_id: msg = utils.output_log(700, param='storage_id') raise exception.ManageExistingInvalidReference( existing_ref=existing_ref, reason=msg) ldev = _str2int(existing_ref.get('ldev')) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is None'. if ldev is None: msg = utils.output_log(701) raise exception.ManageExistingInvalidReference( existing_ref=existing_ref, reason=msg) return self.get_ldev_size_in_gigabyte(ldev, existing_ref)
def set_hba_ids(self, port, gid, hba_ids): registered_wwns = [] for wwn in hba_ids: try: self.run_raidcom( 'add', 'hba_wwn', '-port', '-'.join([port, gid]), '-hba_wwn', wwn) registered_wwns.append(wwn) except exception.HPEXPError: utils.output_log(317, port=port, gid=gid, wwn=wwn) if not registered_wwns: msg = utils.output_log(614, port=port, gid=gid) raise exception.HPEXPError(msg)
def create_mapping_targets(self, targets, connector): hba_ids = self.get_hba_ids_from_connector(connector) for port in targets['info'].keys(): if targets['info'][port]: continue try: self._create_target(targets, port, connector['ip'], hba_ids) except exception.HPEXPError: utils.output_log( self.driver_info['msg_id']['target'], port=port) if not targets['list']: self.find_targets_from_storage( targets, connector, targets['info'].keys())
def unmanage(self, volume): ldev = utils.get_ldev(volume) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is None'. if ldev is None: utils.output_log(304, method='unmanage', id=volume['id']) return if self.check_vvol(ldev): utils.output_log( 706, volume_id=volume['id'], volume_type=utils.NORMAL_LDEV_TYPE) raise exception.HPEXPVolumeIsBusy(volume_name=volume['name']) try: self.delete_pair(ldev) except exception.HPEXPBusy: raise exception.HPEXPVolumeIsBusy(volume_name=volume['name'])
def _create_horcm_conf(self, horcmgr=_HORCMGR): inst = self.conf.hpexp_horcm_numbers[horcmgr] inst = int(inst) serial = self.conf.hpexp_storage_id filename = '/etc/horcm%s.conf' % inst port = _DEFAULT_PORT_BASE + inst found = False if not os.path.exists(filename): file_str = """ HORCM_MON #ip_address service poll(10ms) timeout(10ms) 127.0.0.1 %16d 6000 3000 HORCM_CMD """ % port else: file_str = cinder_utils.read_file_as_root(filename) if re.search(r'^\\\\.\\CMD-%s:/dev/sd$' % serial, file_str, re.M): found = True if not found: repl_str = r'\1\\\\.\\CMD-%s:/dev/sd\n' % serial file_str = CMD_PATTERN.sub(repl_str, file_str) result = utils.execute('tee', filename, process_input=file_str) if result[0]: msg = utils.output_log( 632, file=filename, ret=result[0], err=result[2]) raise exception.HPEXPError(data=msg)
def delete_pair_based_on_pvol(self, pair_info, all_split): svols = [] restart = False try: for svol_info in pair_info['svol_info']: if svol_info['is_thin'] or not svol_info['is_psus']: svols.append(six.text_type(svol_info['ldev'])) continue self.delete_pair_from_storage( pair_info['pvol'], svol_info['ldev'], False) restart = True self._terminate_pair_connection(svol_info['ldev']) if not svols: self._terminate_pair_connection(pair_info['pvol']) finally: if restart: self._restart_horcmgr(_PAIR_HORCMGR) if all_split and svols: msg = utils.output_log( 616, pvol=pair_info['pvol'], svol=', '.join(svols)) raise exception.HPEXPBusy(message=msg)
def check_param(self): utils.check_opt_value(self.conf, _INHERITED_VOLUME_OPTS) utils.check_opts(self.conf, opts.COMMON_VOLUME_OPTS) utils.check_opts(self.conf, _COMMON_VOLUME_OPTS) utils.check_opts(self.conf, self.driver_info['volume_opts']) if self.conf.hpexp_default_copy_method not in _COPY_METHOD: msg = utils.output_log( 601, param='hpexp_default_copy_method') raise exception.HPEXPError(data=msg) if (self.conf.hpexp_default_copy_method == 'THIN' and not self.conf.hpexp_thin_pool): msg = utils.output_log(601, param='hpexp_thin_pool') raise exception.HPEXPError(data=msg) if self.conf.hpexp_ldev_range: self.storage_info['ldev_range'] = self._range2list( 'hpexp_ldev_range')
def _range2list(self, param): values = [_str2int(x) for x in self.conf.safe_get(param).split('-')] if (len(values) != 2 or values[0] is None or values[1] is None or values[0] > values[1]): msg = utils.output_log(601, param=param) raise exception.HPEXPError(data=msg) return values
def connect_storage(self): self.storage_info['pool_id'] = self.get_pool_id() # When 'pool_id' is 0, it should be true. # Therefore, it cannot remove 'is None'. if self.storage_info['pool_id'] is None: msg = utils.output_log(640, pool=self.conf.hpexp_pool) raise exception.HPEXPError(data=msg) LOG.debug('Setting pool id: %s', self.storage_info['pool_id'])
def copy_on_storage(self, pvol, size, metadata): ldev_info = self.get_ldev_info(['sts', 'vol_attr'], '-ldev_id', pvol) if ldev_info['sts'] != NORMAL_STS: msg = utils.output_log(612, ldev=pvol) raise exception.HPEXPError(data=msg) if VVOL_ATTR in ldev_info['vol_attr']: raise exception.HPEXPNotImplementedError() return super(HPEXPHORCM, self).copy_on_storage(pvol, size, metadata)
def check_param(self): super(HPEXPHORCM, self).check_param() utils.check_opts(self.conf, opts.HORCM_VOLUME_OPTS) utils.check_opts(self.conf, _HORCM_VOLUME_OPTS) utils.check_opt_value(CONF, _HORCM_OPT_NAMES) insts = self.conf.hpexp_horcm_numbers if len(insts) != 2 or insts[_HORCMGR] == insts[_PAIR_HORCMGR]: msg = utils.output_log(601, param='hpexp_horcm_numbers') raise exception.HPEXPError(data=msg) LOG.debug('Setting ldev_range: %s', self.storage_info['ldev_range'])
def _create_thin_copy_pair(self, pvol, svol, dummy_vol_type): snapshot_name = _SNAP_NAME + six.text_type(svol % _SNAP_HASH_SIZE) self.run_raidcom( 'add', 'snapshot', '-ldev_id', pvol, svol, '-pool', self.conf.hpexp_thin_pool, '-snapshot_name', snapshot_name, '-copy_size', self.conf.hpexp_copy_speed) try: self.wait_thin_copy(svol, PAIR) self.run_raidcom( 'modify', 'snapshot', '-ldev_id', svol, '-snapshot_data', 'create') self.wait_thin_copy(svol, PSUS) except Exception: with excutils.save_and_reraise_exception(): interval = self.conf.hpexp_async_copy_check_interval try: self._delete_thin_copy_pair(pvol, svol, interval) except exception.HPEXPError: utils.output_log(325, pvol=pvol, svol=svol)