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 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 _run_locked_restore(volume, snapshot_id): try: snapshot = self.db.snapshot_get(self.ctxt, snapshot_id) except cinder_exception.SnapshotNotFound: with excutils.save_and_reraise_exception(): utils.output_log( 656, volume_id=volume['id'], reason='Invalid input: %s' % snapshot_id) pvol = utils.get_ldev(volume) svol = utils.get_ldev(snapshot) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is None'. if svol is None or not self.has_thin_copy_pair(pvol, svol): msg = utils.output_log( 656, volume_id=volume['id'], reason='Invalid input: %s' % snapshot_id) raise exception.HPXPError(data=msg) if volume['status'] != 'available': msg = utils.output_log( 656, volume_id=volume['id'], reason='Status of target volume %(volume_id)s ' 'is not available: %(status)s' % { 'volume_id': volume['id'], 'status': volume['status']}) raise exception.HPXPError(data=msg) if snapshot['status'] != 'available': msg = utils.output_log( 656, volume_id=volume['id'], reason='Status of source snapshot %(snapshot_id)s ' 'is not available: %(status)s' % { 'snapshot_id': snapshot_id, 'status': snapshot['status']}) raise exception.HPXPError(data=msg) self.restore_ldev(pvol, svol)
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 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.HPXPError: 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.HPXPError: utils.output_log(314, ldev=ldev, port=port, id=gid, lun=lun) return lun
def _start_horcmgr(self, horcmgr): inst = self.conf.hpxp_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 get_copy_method(self, metadata): method = metadata.get( 'copy_method', self.conf.hpxp_default_copy_method) if method not in _COPY_METHOD: msg = utils.output_log(602, meta='copy_method') raise exception.HPXPError(data=msg) if method == 'THIN' and not self.conf.hpxp_thin_pool: msg = utils.output_log(601, param='hpxp_thin_pool') raise exception.HPXPError(data=msg) return method
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.hpxp_horcm_user) return False return True
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 _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.HPXPError: utils.output_log(313, ldev=dest_ldev) return dest_ldev, utils.NORMAL_LDEV_TYPE
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.HPXPBusy: raise exception.HPXPVolumeIsBusy(volume_name=volume['name'])
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.HPXPError: utils.output_log(314, ldev=ldev, port=port, id=gid, lun=None) msg = utils.output_log(639, ldev=ldev) raise exception.HPXPError(msg)
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 = utils.get_volume_metadata(volume) 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.HPXPBusy: raise exception.HPXPSnapshotIsBusy(snapshot_name=snapshot['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.HPXPError(data=msg) if self.check_vvol(ldev): msg = utils.output_log(618, volume_id=volume['id']) raise exception.HPXPError(data=msg) self.delete_pair(ldev) self.extend_ldev(ldev, volume['size'], new_size)
def delete_snapshot(self, snapshot): ldev = utils.get_ldev(snapshot) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is not None'. if (ldev is not None and self.check_vvol(ldev) and 'ro_vol' in _get_snapshot_metadata(snapshot)): utils.output_log(606, snapshot_id=snapshot['id']) raise exception.HPXPSnapshotIsBusy( snapshot_name=snapshot['name']) super(HPXPCommonExtension, self).delete_snapshot(snapshot)
def manage_existing_get_size(self, dummy_volume, existing_ref): if existing_ref.get('storage_id') != self.conf.hpxp_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 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.HPXPError: utils.output_log(313, ldev=svol) return svol, ldev_type
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.HPXPError: 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.HPXPError(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.HPXPError: 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.HPXPVolumeIsBusy(volume_name=volume['name']) try: self.delete_pair(ldev) except exception.HPXPBusy: raise exception.HPXPVolumeIsBusy(volume_name=volume['name'])
def create_volume_from_snapshot(self, volume, snapshot): ldev = utils.get_ldev(snapshot) # When 'ldev' is 0, it should be true. # Therefore, it cannot remove 'is not None'. if (ldev is not None and self.check_vvol(ldev) and _get_access_mode(volume) == 'ro'): if 'ro_vol' in _get_snapshot_metadata(snapshot): msg = utils.output_log(657, snapshot_id=snapshot['id']) raise exception.HPXPError(data=msg) self.db.snapshot_metadata_update( self.ctxt, snapshot['id'], dict(ro_vol=volume['id']), False) metadata = utils.get_volume_metadata(volume) return { 'provider_location': six.text_type(ldev), 'metadata': dict( metadata, ldev=ldev, type=utils.VVOL_LDEV_TYPE, snapshot=snapshot['id']), } return super( HPXPCommonExtension, self).create_volume_from_snapshot( volume, snapshot)
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.hpxp_default_copy_method not in _COPY_METHOD: msg = utils.output_log( 601, param='hpxp_default_copy_method') raise exception.HPXPError(data=msg) if (self.conf.hpxp_default_copy_method == 'THIN' and not self.conf.hpxp_thin_pool): msg = utils.output_log(601, param='hpxp_thin_pool') raise exception.HPXPError(data=msg) if self.conf.hpxp_ldev_range: self.storage_info['ldev_range'] = self._range2list( 'hpxp_ldev_range')
def _create_horcm_conf(self, horcmgr=_HORCMGR): inst = self.conf.hpxp_horcm_numbers[horcmgr] inst = int(inst) serial = self.conf.hpxp_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.HPXPError(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.HPXPBusy(message=msg)
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.HPXPError(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.hpxp_pool) raise exception.HPXPError(data=msg) LOG.debug('Setting pool id: %s', self.storage_info['pool_id'])