def create_volume_from_snapshot(self, volume, snapshot): """Create a volume from a snapshot. We use LUNcopy to copy a new volume from snapshot. The time needed increases as volume size does. """ snapshotname = huawei_utils.encode_name(snapshot['id']) snapshot_id = snapshot.get('provider_location', None) if snapshot_id is None: snapshot_id = self.restclient.get_snapshotid_by_name(snapshotname) if snapshot_id is None: err_msg = (_( 'create_volume_from_snapshot: Snapshot %(name)s ' 'does not exist.') % {'name': snapshotname}) LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) lun_info = self.create_volume(volume) tgt_lun_id = lun_info['ID'] luncopy_name = huawei_utils.encode_name(volume['id']) LOG.info(_LI( 'create_volume_from_snapshot: src_lun_id: %(src_lun_id)s, ' 'tgt_lun_id: %(tgt_lun_id)s, copy_name: %(copy_name)s.'), {'src_lun_id': snapshot_id, 'tgt_lun_id': tgt_lun_id, 'copy_name': luncopy_name}) event_type = 'LUNReadyWaitInterval' wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) def _volume_ready(): result = self.restclient.get_lun_info(tgt_lun_id) if (result['HEALTHSTATUS'] == constants.STATUS_HEALTH and result['RUNNINGSTATUS'] == constants.STATUS_VOLUME_READY): return True return False huawei_utils.wait_for_condition(self.xml_file_path, _volume_ready, wait_interval, wait_interval * 10) self._copy_volume(volume, luncopy_name, snapshot_id, tgt_lun_id) return {'ID': lun_info['ID'], 'lun_info': lun_info}
def _wait_volume_ready(self, lun_id): event_type = 'LUNReadyWaitInterval' wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) def _volume_ready(): result = self.restclient.get_lun_info(lun_id) if (result['HEALTHSTATUS'] == constants.STATUS_HEALTH and result['RUNNINGSTATUS'] == constants.STATUS_VOLUME_READY): return True return False huawei_utils.wait_for_condition(self.xml_file_path, _volume_ready, wait_interval, wait_interval * 10)
def _wait_volume_ready(self, lun_id): event_type = "LUNReadyWaitInterval" wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) def _volume_ready(): result = self.rmt_client.get_lun_info(lun_id) if ( result["HEALTHSTATUS"] == constants.STATUS_HEALTH and result["RUNNINGSTATUS"] == constants.STATUS_VOLUME_READY ): return True return False huawei_utils.wait_for_condition(self.xml_file_path, _volume_ready, wait_interval, wait_interval * 10)
def create_volume_from_snapshot(self, volume, snapshot): """Create a volume from a snapshot. We use LUNcopy to copy a new volume from snapshot. The time needed increases as volume size does. """ snapshotname = huawei_utils.encode_name(snapshot["id"]) snapshot_id = snapshot.get("provider_location", None) if snapshot_id is None: snapshot_id = self.restclient.get_snapshotid_by_name(snapshotname) if snapshot_id is None: err_msg = _("create_volume_from_snapshot: Snapshot %(name)s " "does not exist.") % { "name": snapshotname } LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) lun_info = self.create_volume(volume) tgt_lun_id = lun_info["ID"] luncopy_name = huawei_utils.encode_name(volume["id"]) LOG.info( _LI( "create_volume_from_snapshot: src_lun_id: %(src_lun_id)s, " "tgt_lun_id: %(tgt_lun_id)s, copy_name: %(copy_name)s." ), {"src_lun_id": snapshot_id, "tgt_lun_id": tgt_lun_id, "copy_name": luncopy_name}, ) event_type = "LUNReadyWaitInterval" wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) def _volume_ready(): result = self.restclient.get_lun_info(tgt_lun_id) if ( result["HEALTHSTATUS"] == constants.STATUS_HEALTH and result["RUNNINGSTATUS"] == constants.STATUS_VOLUME_READY ): return True return False huawei_utils.wait_for_condition(self.xml_file_path, _volume_ready, wait_interval, wait_interval * 10) self._copy_volume(volume, luncopy_name, snapshot_id, tgt_lun_id) return {"ID": lun_info["ID"], "lun_info": lun_info}
def _copy_volume(self, volume, copy_name, src_lun, tgt_lun): luncopy_id = self.restclient.create_luncopy(copy_name, src_lun, tgt_lun) event_type = "LUNcopyWaitInterval" wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) try: self.restclient.start_luncopy(luncopy_id) def _luncopy_complete(): luncopy_info = self.restclient.get_luncopy_info(luncopy_id) if luncopy_info["status"] == constants.STATUS_LUNCOPY_READY: # luncopy_info['status'] means for the running status of # the luncopy. If luncopy_info['status'] is equal to '40', # this luncopy is completely ready. return True elif luncopy_info["state"] != constants.STATUS_HEALTH: # luncopy_info['state'] means for the healthy status of the # luncopy. If luncopy_info['state'] is not equal to '1', # this means that an error occurred during the LUNcopy # operation and we should abort it. err_msg = ( _( "An error occurred during the LUNcopy operation. " "LUNcopy name: %(luncopyname)s. " "LUNcopy status: %(luncopystatus)s. " "LUNcopy state: %(luncopystate)s." ) % { "luncopyname": luncopy_id, "luncopystatus": luncopy_info["status"], "luncopystate": luncopy_info["state"], }, ) LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) huawei_utils.wait_for_condition(self.xml_file_path, _luncopy_complete, wait_interval) except Exception: with excutils.save_and_reraise_exception(): self.restclient.delete_luncopy(luncopy_id) self.delete_volume(volume) self.restclient.delete_luncopy(luncopy_id)
def _copy_volume(self, volume, copy_name, src_lun, tgt_lun): luncopy_id = self.restclient.create_luncopy(copy_name, src_lun, tgt_lun) event_type = 'LUNcopyWaitInterval' wait_interval = huawei_utils.get_wait_interval(self.xml_file_path, event_type) try: self.restclient.start_luncopy(luncopy_id) def _luncopy_complete(): luncopy_info = self.restclient.get_luncopy_info(luncopy_id) if luncopy_info['status'] == constants.STATUS_LUNCOPY_READY: # luncopy_info['status'] means for the running status of # the luncopy. If luncopy_info['status'] is equal to '40', # this luncopy is completely ready. return True elif luncopy_info['state'] != constants.STATUS_HEALTH: # luncopy_info['state'] means for the healthy status of the # luncopy. If luncopy_info['state'] is not equal to '1', # this means that an error occurred during the LUNcopy # operation and we should abort it. err_msg = ( _('An error occurred during the LUNcopy operation. ' 'LUNcopy name: %(luncopyname)s. ' 'LUNcopy status: %(luncopystatus)s. ' 'LUNcopy state: %(luncopystate)s.') % { 'luncopyname': luncopy_id, 'luncopystatus': luncopy_info['status'], 'luncopystate': luncopy_info['state'] }, ) LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) huawei_utils.wait_for_condition(self.xml_file_path, _luncopy_complete, wait_interval) except Exception: with excutils.save_and_reraise_exception(): self.restclient.delete_luncopy(luncopy_id) self.delete_volume(volume) self.restclient.delete_luncopy(luncopy_id)
def test_get_wait_interval(self): result = huawei_utils.get_wait_interval(self.xml_file_path, 'LUNReadyWaitInterval') self.assertEqual(2, result)