def _can_destroy_instance(instance): if instance.state == models.Instance.States.ERRED: return if (instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.SHUTOFF): return if (instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.ACTIVE): raise core_exceptions.IncorrectStateException(_('Please stop the instance before its removal.')) raise core_exceptions.IncorrectStateException(_('Instance should be shutoff and OK or erred. ' 'Please contact support.'))
def attach_to_port(self, request, uuid=None): floating_ip: models.FloatingIP = self.get_object() serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) port: models.Port = serializer.validated_data['port'] if port.state != models.Port.States.OK: raise core_exceptions.IncorrectStateException( _('The port [%(port)s] is expected to have [OK] state, but actual one is [%(state)s]' ) % { 'port': port, 'state': port.get_state_display() }) if port.tenant != floating_ip.tenant: raise exceptions.ValidationError({ 'detail': _('The port [%(port)s] is expected to belong to the same tenant [%(tenant)s] , but actual one is [%(actual_tenant)s]' ) % { 'port': port, 'tenant': floating_ip.tenant, 'actual_tenant': port.tenant, } }) executors.FloatingIPAttachExecutor().execute( floating_ip, port=core_utils.serialize_instance(port)) return response.Response({'status': _('attaching was scheduled')}, status=status.HTTP_202_ACCEPTED)
def external_network_is_defined(tenant): if not tenant.external_network_id: raise core_exceptions.IncorrectStateException( _( 'Cannot create floating IP if tenant external network is not defined.' ) )
def check_all_related_resource_are_stable(job): States = structure_models.NewResource.States stable_states = (States.OK, States.ERRED) if not all(resource.state in stable_states for resource in job.get_related_resources()): raise core_exceptions.IncorrectStateException( _('Related resources are not stable yet. ' 'Please wait until provisioning is completed.'))
def _can_restart_instance(instance): if ( instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.SHUTOFF ): raise core_exceptions.IncorrectStateException( _('Please start instance first.') )
def _can_stop_instance(instance): if ( instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.SHUTOFF ): raise core_exceptions.IncorrectStateException( _('Instance is already stopped.') )
def _can_start_instance(instance): if ( instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.ACTIVE ): raise core_exceptions.IncorrectStateException( _('Instance is already active.') )
def _can_change_flavor(instance): if ( instance.state == models.Instance.States.OK and instance.runtime_state == models.Instance.RuntimeStates.ACTIVE ): raise core_exceptions.IncorrectStateException( _('Please stop the instance before changing its flavor.') )
def _is_volume_instance_shutoff(volume): if ( volume.instance and volume.instance.runtime_state != models.Instance.RuntimeStates.SHUTOFF ): raise core_exceptions.IncorrectStateException( _('Volume instance should be in shutoff state.') )
def _can_destroy_volume(volume): if volume.state == models.Volume.States.ERRED: return if volume.state != models.Volume.States.OK: raise core_exceptions.IncorrectStateException( _('Volume should be in OK state.')) core_validators.RuntimeStateValidator('available', 'error', 'error_restoring', 'error_extending', '')(volume)
def __call__(self, resource): if resource.state not in self.valid_states: states_names = dict(resource.States.CHOICES) valid_states_names = [ str(states_names[state]) for state in self.valid_states ] raise exceptions.IncorrectStateException( _('Valid states for operation: %s.') % ', '.join(valid_states_names))
def _is_schedule_deactived(resource_schedule): if not resource_schedule.is_active: raise core_exceptions.IncorrectStateException( _('A schedule is already deactivated.'))
def _is_schedule_active(resource_schedule): if resource_schedule.is_active: raise core_exceptions.IncorrectStateException( _('Resource schedule is already activated.'))
def _has_backups(instance): if instance.backups.exists(): raise core_exceptions.IncorrectStateException( _('Cannot delete instance that has backups.'))
def _is_volume_instance_ok(volume): if volume.instance and volume.instance.state != models.Instance.States.OK: raise core_exceptions.IncorrectStateException( _('Volume instance should be in OK state.'))
def _is_volume_bootable(volume): if volume.bootable: raise core_exceptions.IncorrectStateException( _('Volume cannot be bootable.'))
def _volume_snapshots_exist(volume): if volume.snapshots.exists(): raise core_exceptions.IncorrectStateException( _('Volume has dependent snapshots.'))
def __call__(self, resource): if resource.runtime_state not in self.valid_states: raise exceptions.IncorrectStateException( _('Valid runtime states for operation: %s.') % ', '.join(self.valid_states))
def _has_instance(volume): if not volume.instance: raise core_exceptions.IncorrectStateException(_('Volume is already detached.'))
def _is_volume_attached(volume): if not volume.instance: raise core_exceptions.IncorrectStateException( _('Volume is not attached to an instance.') )