def execute(self, instance_uuid): def _wait_for_active(): new_instance = self.novaclient.get_server(self.context, instance_uuid) vm_state = getattr(new_instance, 'OS-EXT-STS:vm_state') if vm_state == 'active': raise loopingcall.LoopingCallDone() periodic_call = loopingcall.FixedIntervalLoopingCall( _wait_for_active) try: msg = "Confirming instance '%s' vm_state is ACTIVE" % instance_uuid self.update_details(msg) # add a timeout to the periodic call. periodic_call.start(interval=CONF.verify_interval) etimeout.with_timeout(CONF.wait_period_after_power_on, periodic_call.wait) msg = "Confirmed instance '%s' vm_state is ACTIVE" % instance_uuid self.update_details(msg, 1.0) except etimeout.Timeout: msg = "Failed to start instance %(instance)s" % { 'instance': instance_uuid } self.update_details(msg, 1.0) raise exception.InstanceRecoveryFailureException( message=msg) finally: # stop the periodic call, in case of exceptions or Timeout. periodic_call.stop()
def execute(self, context, instance_uuid): """Stop the instance for recovery.""" instance = self.novaclient.get_server(context, instance_uuid) # If an instance is not HA_Enabled and "process_all_instances" config # option is also disabled, then there is no need to take any recovery # action. if not CONF.instance_failure.process_all_instances and not ( strutils.bool_from_string( instance.metadata.get('HA_Enabled', False))): LOG.info( "Skipping recovery for instance: %s as it is " "not Ha_Enabled.", instance_uuid) raise exception.SkipInstanceRecoveryException() vm_state = getattr(instance, 'OS-EXT-STS:vm_state') if vm_state in ['paused', 'rescued']: msg = _("Recovery of instance '%(instance_uuid)s' is ignored as" " it is in '%(vm_state)s' state.") % { 'instance_uuid': instance_uuid, 'vm_state': vm_state } LOG.warning(msg) raise exception.IgnoreInstanceRecoveryException(msg) if vm_state != 'stopped': if vm_state == 'resized': self.novaclient.reset_instance_state(context, instance.id, 'active') self.novaclient.stop_server(context, instance.id) def _wait_for_power_off(): new_instance = self.novaclient.get_server(context, instance_uuid) vm_state = getattr(new_instance, 'OS-EXT-STS:vm_state') if vm_state == 'stopped': raise loopingcall.LoopingCallDone() periodic_call = loopingcall.FixedIntervalLoopingCall( _wait_for_power_off) try: # add a timeout to the periodic call. periodic_call.start(interval=CONF.verify_interval) etimeout.with_timeout(CONF.wait_period_after_power_off, periodic_call.wait) except etimeout.Timeout: msg = _("Failed to stop instance %(instance)s") % { 'instance': instance.id } raise exception.InstanceRecoveryFailureException(message=msg) finally: # stop the periodic call, in case of exceptions or Timeout. periodic_call.stop()
def execute(self, context, instance_uuid): """Start the instance.""" instance = self.novaclient.get_server(context, instance_uuid) vm_state = getattr(instance, 'OS-EXT-STS:vm_state') if vm_state == 'stopped': self.novaclient.start_server(context, instance.id) else: msg = _("Invalid state for Instance %(instance)s. Expected state: " "'STOPPED', Actual state: '%(actual_state)s'") % { 'instance': instance_uuid, 'actual_state': vm_state } raise exception.InstanceRecoveryFailureException(message=msg)
def execute(self, instance_uuid): """Start the instance.""" msg = "Starting instance: '%s'" % instance_uuid self.update_details(msg) instance = self.novaclient.get_server(self.context, instance_uuid) vm_state = getattr(instance, 'OS-EXT-STS:vm_state') if vm_state == 'stopped': self.novaclient.start_server(self.context, instance.id) msg = "Instance started: '%s'" % instance_uuid self.update_details(msg, 1.0) else: msg = ("Invalid state for Instance %(instance)s. Expected state: " "'STOPPED', Actual state: '%(actual_state)s'") % { 'instance': instance_uuid, 'actual_state': vm_state } self.update_details(msg, 1.0) raise exception.InstanceRecoveryFailureException(message=msg)