コード例 #1
0
ファイル: snapshots.py プロジェクト: j-griffith/cinder
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ['cinder.context']
        snapshot_body = body['snapshot']
        self.validate_name_and_description(snapshot_body, check_length=False)

        if 'name' in snapshot_body:
            snapshot_body['display_name'] = snapshot_body.pop('name')

        if 'description' in snapshot_body:
            snapshot_body['display_description'] = snapshot_body.pop(
                'description')

        # Not found exception will be handled at the wsgi level
        snapshot = self.volume_api.get_snapshot(context, id)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.start')
        self.volume_api.update_snapshot(context, snapshot, snapshot_body)

        snapshot.update(snapshot_body)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.end')

        return self._view_builder.detail(req, snapshot)
コード例 #2
0
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ['cinder.context']
        snapshot_body = body['snapshot']
        self.validate_name_and_description(snapshot_body, check_length=False)

        if 'name' in snapshot_body:
            snapshot_body['display_name'] = snapshot_body.pop('name')

        if 'description' in snapshot_body:
            snapshot_body['display_description'] = snapshot_body.pop(
                'description')

        # Not found exception will be handled at the wsgi level
        snapshot = self.volume_api.get_snapshot(context, id)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.start')
        self.volume_api.update_snapshot(context, snapshot, snapshot_body)

        snapshot.update(snapshot_body)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.end')

        return self._view_builder.detail(req, snapshot)
コード例 #3
0
ファイル: manager.py プロジェクト: afliu/cinder
 def _notify_about_snapshot_usage(self,
                                  context,
                                  snapshot,
                                  event_suffix,
                                  extra_usage_info=None):
     volume_utils.notify_about_snapshot_usage(
         context, snapshot, event_suffix,
         extra_usage_info=extra_usage_info, host=self.host)
コード例 #4
0
 def _notify_about_snapshot_usage(self,
                                  context,
                                  snapshot,
                                  event_suffix,
                                  extra_usage_info=None):
     volume_utils.notify_about_snapshot_usage(
         context, snapshot, event_suffix,
         extra_usage_info=extra_usage_info, host=self.host)
コード例 #5
0
ファイル: snapshots.py プロジェクト: oleksii-shyman/cinder
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ['cinder.context']

        if not body:
            msg = _("Missing request body")
            raise exc.HTTPBadRequest(explanation=msg)

        if 'snapshot' not in body:
            msg = (_("Missing required element '%s' in request body") %
                   'snapshot')
            raise exc.HTTPBadRequest(explanation=msg)

        snapshot = body['snapshot']
        update_dict = {}

        valid_update_keys = (
            'name',
            'description',
            'display_name',
            'display_description',
        )

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot['name']
            del snapshot['name']

        # NOTE(thingee): v2 API allows description instead of
        # display_description
        if 'description' in snapshot:
            snapshot['display_description'] = snapshot['description']
            del snapshot['description']

        for key in valid_update_keys:
            if key in snapshot:
                update_dict[key] = snapshot[key]

        try:
            snapshot = self.volume_api.get_snapshot(context, id)
            volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                     'update.start')
            self.volume_api.update_snapshot(context, snapshot, update_dict)
        except exception.NotFound:
            msg = _("Snapshot could not be found")
            raise exc.HTTPNotFound(explanation=msg)

        snapshot.update(update_dict)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.end')

        return {'snapshot': _translate_snapshot_detail_view(context, snapshot)}
コード例 #6
0
ファイル: snapshots.py プロジェクト: EricChen2013/cinder
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ['cinder.context']

        if not body:
            msg = _("Missing request body")
            raise exc.HTTPBadRequest(explanation=msg)

        if 'snapshot' not in body:
            msg = (_("Missing required element '%s' in request body") %
                   'snapshot')
            raise exc.HTTPBadRequest(explanation=msg)

        snapshot = body['snapshot']
        update_dict = {}

        valid_update_keys = (
            'name',
            'description',
            'display_name',
            'display_description',
        )

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot['name']
            del snapshot['name']

        # NOTE(thingee): v2 API allows description instead of
        # display_description
        if 'description' in snapshot:
            snapshot['display_description'] = snapshot['description']
            del snapshot['description']

        for key in valid_update_keys:
            if key in snapshot:
                update_dict[key] = snapshot[key]

        try:
            snapshot = self.volume_api.get_snapshot(context, id)
            volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                     'update.start')
            self.volume_api.update_snapshot(context, snapshot, update_dict)
        except exception.SnapshotNotFound as error:
            raise exc.HTTPNotFound(explanation=error.msg)

        snapshot.update(update_dict)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.end')

        return {'snapshot': _translate_snapshot_detail_view(context, snapshot)}
コード例 #7
0
 def execute(self, context, snapshot_ref):
     snapshot_id = snapshot_ref['id']
     try:
         volume_utils.notify_about_snapshot_usage(context, snapshot_ref,
                                                  self.event_suffix,
                                                  host=self.host)
     except exception.CinderException:
         # If notification sending of snapshot database entry reading fails
         # then we shouldn't error out the whole workflow since this is
         # not always information that must be sent for snapshots to operate
         LOG.exception(_LE("Failed notifying about the snapshot "
                           "action %(event)s for snapshot %(snp_id)s."),
                       {'event': self.event_suffix,
                        'snp_id': snapshot_id})
コード例 #8
0
 def execute(self, context, snapshot_ref):
     snapshot_id = snapshot_ref['id']
     try:
         volume_utils.notify_about_snapshot_usage(context, snapshot_ref,
                                                  self.event_suffix,
                                                  host=self.host)
     except exception.CinderException:
         # If notification sending of snapshot database entry reading fails
         # then we shouldn't error out the whole workflow since this is
         # not always information that must be sent for snapshots to operate
         LOG.exception("Failed notifying about the snapshot "
                       "action %(event)s for snapshot %(snp_id)s.",
                       {'event': self.event_suffix,
                        'snp_id': snapshot_id})
コード例 #9
0
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ['cinder.context']

        if not body:
            msg = _("Missing request body")
            raise exc.HTTPBadRequest(explanation=msg)

        if 'snapshot' not in body:
            msg = (_("Missing required element '%s' in request body") %
                   'snapshot')
            raise exc.HTTPBadRequest(explanation=msg)

        snapshot = body['snapshot']
        update_dict = {}

        valid_update_keys = (
            'name',
            'description',
            'display_name',
            'display_description',
        )
        self.validate_name_and_description(snapshot)

        # NOTE(thingee): v2 API allows name instead of display_name
        if 'name' in snapshot:
            snapshot['display_name'] = snapshot.pop('name')

        # NOTE(thingee): v2 API allows description instead of
        # display_description
        if 'description' in snapshot:
            snapshot['display_description'] = snapshot.pop('description')

        for key in valid_update_keys:
            if key in snapshot:
                update_dict[key] = snapshot[key]

        # Not found exception will be handled at the wsgi level
        snapshot = self.volume_api.get_snapshot(context, id)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.start')
        self.volume_api.update_snapshot(context, snapshot, update_dict)

        snapshot.update(update_dict)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot,
                                                 'update.end')

        return self._view_builder.detail(req, snapshot)
コード例 #10
0
 def test_notify_about_snapshot_usage(self, mock_rpc, mock_conf, mock_usage):
     mock_conf.host = "host1"
     output = volume_utils.notify_about_snapshot_usage(mock.sentinel.context, mock.sentinel.snapshot, "test_suffix")
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot)
     mock_rpc.get_notifier.assert_called_once_with("snapshot", "host1")
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context, "snapshot.test_suffix", mock_usage.return_value
     )
コード例 #11
0
ファイル: snapshots.py プロジェクト: dims/cinder
    def update(self, req, id, body):
        """Update a snapshot."""
        context = req.environ["cinder.context"]

        if not body:
            msg = _("Missing request body")
            raise exc.HTTPBadRequest(explanation=msg)

        if "snapshot" not in body:
            msg = _("Missing required element '%s' in request body") % "snapshot"
            raise exc.HTTPBadRequest(explanation=msg)

        snapshot = body["snapshot"]
        update_dict = {}

        valid_update_keys = ("name", "description", "display_name", "display_description")
        self.validate_name_and_description(snapshot)

        # NOTE(thingee): v2 API allows name instead of display_name
        if "name" in snapshot:
            snapshot["display_name"] = snapshot.pop("name")

        # NOTE(thingee): v2 API allows description instead of
        # display_description
        if "description" in snapshot:
            snapshot["display_description"] = snapshot.pop("description")

        for key in valid_update_keys:
            if key in snapshot:
                update_dict[key] = snapshot[key]

        try:
            snapshot = self.volume_api.get_snapshot(context, id)
            volume_utils.notify_about_snapshot_usage(context, snapshot, "update.start")
            self.volume_api.update_snapshot(context, snapshot, update_dict)
        except exception.SnapshotNotFound as error:
            raise exc.HTTPNotFound(explanation=error.msg)

        snapshot.update(update_dict)
        req.cache_db_snapshot(snapshot)
        volume_utils.notify_about_snapshot_usage(context, snapshot, "update.end")

        return self._view_builder.detail(req, snapshot)
コード例 #12
0
 def test_notify_about_snapshot_usage(self, mock_rpc, mock_conf,
                                      mock_usage):
     mock_conf.host = 'host1'
     output = volume_utils.notify_about_snapshot_usage(
         mock.sentinel.context, mock.sentinel.snapshot, 'test_suffix')
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot)
     mock_rpc.get_notifier.assert_called_once_with('snapshot', 'host1')
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context, 'snapshot.test_suffix',
         mock_usage.return_value)
コード例 #13
0
 def test_notify_about_snapshot_usage(self, mock_rpc,
                                      mock_conf, mock_usage):
     mock_conf.host = 'host1'
     output = volume_utils.notify_about_snapshot_usage(
         mock.sentinel.context,
         mock.sentinel.snapshot,
         'test_suffix')
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot)
     mock_rpc.get_notifier.assert_called_once_with('snapshot', 'host1')
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context,
         'snapshot.test_suffix',
         mock_usage.return_value)
コード例 #14
0
 def test_notify_about_snapshot_usage_with_kwargs(self, mock_rpc, mock_conf, mock_usage):
     mock_conf.host = "host1"
     output = volume_utils.notify_about_snapshot_usage(
         mock.sentinel.context,
         mock.sentinel.snapshot,
         "test_suffix",
         extra_usage_info={"a": "b", "c": "d"},
         host="host2",
     )
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot, a="b", c="d")
     mock_rpc.get_notifier.assert_called_once_with("snapshot", "host2")
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context, "snapshot.test_suffix", mock_usage.return_value
     )
コード例 #15
0
 def test_notify_about_snapshot_usage_with_kwargs(self, mock_rpc, mock_conf,
                                                  mock_usage):
     mock_conf.host = 'host1'
     output = volume_utils.notify_about_snapshot_usage(
         mock.sentinel.context,
         mock.sentinel.snapshot,
         'test_suffix',
         extra_usage_info={'a': 'b', 'c': 'd'},
         host='host2')
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot,
                                        a='b', c='d')
     mock_rpc.get_notifier.assert_called_once_with('snapshot', 'host2')
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context,
         'snapshot.test_suffix',
         mock_usage.return_value)
コード例 #16
0
ファイル: test_volume_utils.py プロジェクト: zhangzz2/cinder
 def test_notify_about_snapshot_usage_with_kwargs(self, mock_rpc, mock_conf,
                                                  mock_usage):
     mock_conf.host = 'host1'
     output = volume_utils.notify_about_snapshot_usage(
         mock.sentinel.context,
         mock.sentinel.snapshot,
         'test_suffix',
         extra_usage_info={'a': 'b', 'c': 'd'},
         host='host2')
     self.assertIsNone(output)
     mock_usage.assert_called_once_with(mock.sentinel.snapshot,
                                        a='b', c='d')
     mock_rpc.get_notifier.assert_called_once_with('snapshot', 'host2')
     mock_rpc.get_notifier.return_value.info.assert_called_once_with(
         mock.sentinel.context,
         'snapshot.test_suffix',
         mock_usage.return_value)