def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: start = timeutils.utcnow() self.f(*self.args, **self.kw) end = timeutils.utcnow() if not self._running: break delay = interval - timeutils.delta_seconds(start, end) if delay <= 0: LOG.warn(_LW('task run outlasted interval by %s sec'), -delay) greenthread.sleep(delay if delay > 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE('in fixed duration looping call')) done.send_exception(*sys.exc_info()) return else: done.send(True)
def _func(*args, **kwargs): func_name = f.__name__ result = None try: if self._retry_count: LOG.debug( "Invoking %(func_name)s; retry count is " "%(retry_count)d.", { 'func_name': func_name, 'retry_count': self._retry_count }) result = f(*args, **kwargs) except self._exceptions: with excutils.save_and_reraise_exception() as ctxt: LOG.warn(_LW("Exception which is in the suggested list of " "exceptions occurred while invoking function:" " %s."), func_name, exc_info=True) if (self._max_retry_count != -1 and self._retry_count >= self._max_retry_count): LOG.error( _LE("Cannot retry upon suggested exception " "since retry count (%(retry_count)d) " "reached max retry count " "(%(max_retry_count)d)."), { 'retry_count': self._retry_count, 'max_retry_count': self._max_retry_count }) else: ctxt.reraise = False self._retry_count += 1 self._sleep_time += self._inc_sleep_time return self._sleep_time raise loopingcall.LoopingCallDone(result)
def _func(*args, **kwargs): func_name = f.__name__ result = None try: if self._retry_count: LOG.debug("Invoking %(func_name)s; retry count is " "%(retry_count)d.", {'func_name': func_name, 'retry_count': self._retry_count}) result = f(*args, **kwargs) except self._exceptions: with excutils.save_and_reraise_exception() as ctxt: LOG.warn(_LW("Exception which is in the suggested list of " "exceptions occurred while invoking function:" " %s."), func_name, exc_info=True) if (self._max_retry_count != -1 and self._retry_count >= self._max_retry_count): LOG.error(_LE("Cannot retry upon suggested exception " "since retry count (%(retry_count)d) " "reached max retry count " "(%(max_retry_count)d)."), {'retry_count': self._retry_count, 'max_retry_count': self._max_retry_count}) else: ctxt.reraise = False self._retry_count += 1 self._sleep_time += self._inc_sleep_time return self._sleep_time raise loopingcall.LoopingCallDone(result)
def _poll_task(self, task): """Poll the given task until completion. If the task completes successfully, the method returns the task info using the input event (param done). In case of any error, appropriate exception is set in the event. :param task: managed object reference of the task """ LOG.debug("Invoking VIM API to read info of task: %s.", task) try: task_info = self.invoke_api(vim_util, 'get_object_property', self.vim, task, 'info') except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception( _LE("Error occurred while reading info of " "task: %s."), task) else: if task_info.state in ['queued', 'running']: if hasattr(task_info, 'progress'): LOG.debug("Task: %(task)s progress is %(progress)s%%.", { 'task': task, 'progress': task_info.progress }) elif task_info.state == 'success': LOG.debug("Task: %s status is success.", task) raise loopingcall.LoopingCallDone(task_info) else: error_msg = six.text_type(task_info.error.localizedMessage) error = task_info.error name = error.fault.__class__.__name__ task_ex = exceptions.get_fault_class(name)(error_msg) raise task_ex
def __init__(self, message=None, details=None, **kwargs): self.kwargs = kwargs self.details = details if not message: try: message = self.msg_fmt % kwargs except Exception: # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception(_LE('Exception in string format operation')) for name, value in six.iteritems(kwargs): LOG.error(_LE("%(name)s: %(value)s"), {'name': name, 'value': value}) # at least get the core message out if something happened message = self.msg_fmt super(VMwareDriverException, self).__init__(message)
def logout(self): """Log out and terminate the current session.""" if self._session_id: LOG.info(_LI("Logging out and terminating the current session " "with ID = %s."), _trunc_id(self._session_id)) try: self.vim.Logout(self.vim.service_content.sessionManager) self._session_id = None except Exception: LOG.exception(_LE("Error occurred while logging out and " "terminating the current session with " "ID = %s."), _trunc_id(self._session_id)) else: LOG.debug("No session exists to log out.")
def logout(self): """Log out and terminate the current session.""" if self._session_id: LOG.info( _LI("Logging out and terminating the current session " "with ID = %s."), _trunc_id(self._session_id)) try: self.vim.Logout(self.vim.service_content.sessionManager) self._session_id = None except Exception: LOG.exception( _LE("Error occurred while logging out and " "terminating the current session with " "ID = %s."), _trunc_id(self._session_id)) else: LOG.debug("No session exists to log out.")
def _poll_lease(self, lease): """Poll the state of the given lease. When the lease is ready, the event (param done) is notified. In case of any error, appropriate exception is set in the event. :param lease: lease whose state is to be polled """ LOG.debug("Invoking VIM API to read state of lease: %s.", lease) try: state = self.invoke_api(vim_util, 'get_object_property', self.vim, lease, 'state') except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Error occurred while checking " "state of lease: %s."), lease) else: if state == 'ready': LOG.debug("Lease: %s is ready.", lease) raise loopingcall.LoopingCallDone() elif state == 'initializing': LOG.debug("Lease: %s is initializing.", lease) elif state == 'error': LOG.debug("Invoking VIM API to read lease: %s error.", lease) error_msg = self._get_error_message(lease) excep_msg = _("Lease: %(lease)s is in error state. Details: " "%(error_msg)s.") % {'lease': lease, 'error_msg': error_msg} LOG.error(excep_msg) raise exceptions.VimException(excep_msg) else: # unknown state excep_msg = _("Unknown state: %(state)s for lease: " "%(lease)s.") % {'state': state, 'lease': lease} LOG.error(excep_msg) raise exceptions.VimException(excep_msg)
def _poll_lease(self, lease): """Poll the state of the given lease. When the lease is ready, the event (param done) is notified. In case of any error, appropriate exception is set in the event. :param lease: lease whose state is to be polled """ LOG.debug("Invoking VIM API to read state of lease: %s.", lease) try: state = self.invoke_api(vim_util, 'get_object_property', self.vim, lease, 'state') except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception( _LE("Error occurred while checking " "state of lease: %s."), lease) else: if state == 'ready': LOG.debug("Lease: %s is ready.", lease) raise loopingcall.LoopingCallDone() elif state == 'initializing': LOG.debug("Lease: %s is initializing.", lease) elif state == 'error': LOG.debug("Invoking VIM API to read lease: %s error.", lease) error_msg = self._get_error_message(lease) excep_msg = _("Lease: %(lease)s is in error state. Details: " "%(error_msg)s.") % { 'lease': lease, 'error_msg': error_msg } LOG.error(excep_msg) raise exceptions.VimException(excep_msg) else: # unknown state excep_msg = _("Unknown state: %(state)s for lease: " "%(lease)s.") % { 'state': state, 'lease': lease } LOG.error(excep_msg) raise exceptions.VimException(excep_msg)
def _poll_task(self, task): """Poll the given task until completion. If the task completes successfully, the method returns the task info using the input event (param done). In case of any error, appropriate exception is set in the event. :param task: managed object reference of the task """ LOG.debug("Invoking VIM API to read info of task: %s.", task) try: task_info = self.invoke_api(vim_util, 'get_object_property', self.vim, task, 'info') except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Error occurred while reading info of " "task: %s."), task) else: if task_info.state in ['queued', 'running']: if hasattr(task_info, 'progress'): LOG.debug("Task: %(task)s progress is %(progress)s%%.", {'task': task, 'progress': task_info.progress}) elif task_info.state == 'success': LOG.debug("Task: %s status is success.", task) raise loopingcall.LoopingCallDone(task_info) else: error_msg = six.text_type(task_info.error.localizedMessage) excep_msg = _("Task: %(task)s failed with error: " "%(error)s.") % {'task': task, 'error': error_msg} LOG.error(excep_msg) error = task_info.error name = error.fault.__class__.__name__ task_ex = exceptions.get_fault_class(name)(error_msg) raise task_ex
def update_progress(self): """Updates progress to lease. This call back to the lease is essential to keep the lease alive across long running read operations. :raises: VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException """ progress = int(float(self._bytes_read) / self._vmdk_size * 100) self._log_progress(progress) try: self._session.invoke_api(self._session.vim, 'HttpNfcLeaseProgress', self._lease, percent=progress) except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Error occurred while updating the " "read progress of VMDK file with URL = %s."), self._url)
def update_progress(self): """Updates progress to lease. This call back to the lease is essential to keep the lease alive across long running read operations. :raises: VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException """ progress = int(float(self._bytes_read) / self._vmdk_size * 100) self._log_progress(progress) try: self._session.invoke_api(self._session.vim, 'HttpNfcLeaseProgress', self._lease, percent=progress) except exceptions.VimException: with excutils.save_and_reraise_exception(): LOG.exception( _LE("Error occurred while updating the " "read progress of VMDK file with URL = %s."), self._url)