示例#1
0
 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.'))
示例#2
0
    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)
示例#3
0
 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.'
             )
         )
示例#4
0
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.'))
示例#5
0
 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.')
         )
示例#6
0
 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.')
         )
示例#7
0
 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.')
         )
示例#8
0
 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.')
         )
示例#9
0
 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.')
         )
示例#10
0
 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)
示例#11
0
 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))
示例#12
0
 def _is_schedule_deactived(resource_schedule):
     if not resource_schedule.is_active:
         raise core_exceptions.IncorrectStateException(
             _('A schedule is already deactivated.'))
示例#13
0
 def _is_schedule_active(resource_schedule):
     if resource_schedule.is_active:
         raise core_exceptions.IncorrectStateException(
             _('Resource schedule is already activated.'))
示例#14
0
 def _has_backups(instance):
     if instance.backups.exists():
         raise core_exceptions.IncorrectStateException(
             _('Cannot delete instance that has backups.'))
示例#15
0
 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.'))
示例#16
0
 def _is_volume_bootable(volume):
     if volume.bootable:
         raise core_exceptions.IncorrectStateException(
             _('Volume cannot be bootable.'))
示例#17
0
 def _volume_snapshots_exist(volume):
     if volume.snapshots.exists():
         raise core_exceptions.IncorrectStateException(
             _('Volume has dependent snapshots.'))
示例#18
0
 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))
示例#19
0
 def _has_instance(volume):
     if not volume.instance:
         raise core_exceptions.IncorrectStateException(_('Volume is already detached.'))
示例#20
0
 def _is_volume_attached(volume):
     if not volume.instance:
         raise core_exceptions.IncorrectStateException(
             _('Volume is not attached to an instance.')
         )