Exemple #1
0
 def _validate_segment_update_supported(self):
     # TODO(hjensas): Validation to ensure the subnet-segmentid-writable
     # extension is available.
     # https://storyboard.openstack.org/#!/story/2002189
     # Current segment id must be None
     if self.properties[self.SEGMENT] is not None:
         msg = _('Updating the subnet segment assciation only allowed '
                 'when the current segment_id is None. The subnet is '
                 'currently associated with segment. In this state update')
         raise exception.ResourceActionNotSupported(action=msg)
     else:
         return True
Exemple #2
0
 def handle_delete(self):
     """Perform specified delete policy."""
     if self.resource_id is None:
         return
     try:
         self.client().delete_container(self.resource_id)
     except Exception as ex:
         if self.client_plugin().is_conflict(ex):
             container, objects = self.client().get_container(
                 self.resource_id)
             if objects:
                 msg = _("The bucket you tried to delete is not empty (%s)."
                         ) % self.resource_id
                 raise exception.ResourceActionNotSupported(action=msg)
         self.client_plugin().ignore_not_found(ex)
Exemple #3
0
    def handle_delete(self):
        if self.resource_id is None:
            return

        objects = self._get_objects()

        if objects:
            if self.properties[self.PURGE_ON_DELETE]:
                self._deleter(objects.pop())  # save first container refresh
            else:
                msg = _("Deleting non-empty container (%(id)s) "
                        "when %(prop)s is False") % {
                            'id': self.resource_id,
                            'prop': self.PURGE_ON_DELETE}
                raise exception.ResourceActionNotSupported(action=msg)
        return objects
Exemple #4
0
    def signal(self, details=None):
        '''
        signal the resource. Subclasses should provide a handle_signal() method
        to implement the signal, the base-class raise an exception if no
        handler is implemented.
        '''
        def get_string_details():
            if details is None:
                return 'No signal details provided'
            if isinstance(details, basestring):
                return details
            if isinstance(details, dict):
                if all(k in details
                       for k in ('previous', 'current', 'reason')):
                    # this is from Ceilometer.
                    auto = '%(previous)s to %(current)s (%(reason)s)' % details
                    return 'alarm state changed from %s' % auto
                elif 'state' in details:
                    # this is from watchrule
                    return 'alarm state changed to %(state)s' % details

            return 'Unknown'

        if not callable(getattr(self, 'handle_signal', None)):
            raise exception.ResourceActionNotSupported(action='signal')

        try:
            signal_result = self.handle_signal(details)
            if signal_result:
                reason_string = "Signal: %s" % signal_result
            else:
                reason_string = get_string_details()
            self._add_event('signal', self.status, reason_string)
        except Exception as ex:
            LOG.exception(
                _('signal %(name)s : %(msg)s') % {
                    'name': str(self),
                    'msg': ex
                })
            failure = exception.ResourceFailure(ex, self)
            raise failure
Exemple #5
0
    def signal(self, details=None):
        '''
        signal the resource. Subclasses should provide a handle_signal() method
        to implement the signal, the base-class raise an exception if no
        handler is implemented.
        '''
        if self.action in (self.SUSPEND, self.DELETE):
            self._add_event(self.action, self.status,
                            'Cannot signal resource during %s' % self.action)
            ex = Exception(_('Cannot signal resource during %s') % self.action)
            raise exception.ResourceFailure(ex, self)

        def get_string_details():
            if details is None:
                return 'No signal details provided'
            if isinstance(details, six.string_types):
                return details
            if isinstance(details, dict):
                if all(k in details
                       for k in ('previous', 'current', 'reason')):
                    # this is from Ceilometer.
                    auto = '%(previous)s to %(current)s (%(reason)s)' % details
                    return 'alarm state changed from %s' % auto
                elif 'state' in details:
                    # this is from watchrule
                    return 'alarm state changed to %(state)s' % details

            return 'Unknown'

        # Clear the hook without interfering with resources'
        # `handle_signal` callbacks:
        if (details and 'unset_hook' in details
                and environment.valid_hook_type(details.get('unset_hook'))):
            hook = details['unset_hook']
            if self.has_hook(hook):
                self.clear_hook(hook)
                LOG.info(_LI('Clearing %(hook)s hook on %(resource)s'), {
                    'hook': hook,
                    'resource': six.text_type(self)
                })
                self._add_event(self.action, self.status,
                                "Hook %s is cleared" % hook)
                return

        if not callable(getattr(self, 'handle_signal', None)):
            raise exception.ResourceActionNotSupported(action='signal')

        try:
            signal_result = self.handle_signal(details)
            if signal_result:
                reason_string = "Signal: %s" % signal_result
            else:
                reason_string = get_string_details()
            self._add_event('SIGNAL', self.status, reason_string)
        except Exception as ex:
            LOG.exception(
                _LE('signal %(name)s : %(msg)s') % {
                    'name': six.text_type(self),
                    'msg': ex
                })
            failure = exception.ResourceFailure(ex, self)
            raise failure