summaryrefslogtreecommitdiff
path: root/nova/notifications/objects/volume.py
blob: 41ad6acb35185c33a5b582e1d36224c05ed72854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#    Copyright 2018 NTT Corporation
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from nova.notifications.objects import base
from nova.objects import base as nova_base
from nova.objects import fields


@base.notification_sample('volume-usage.json')
@nova_base.NovaObjectRegistry.register_notification
class VolumeUsageNotification(base.NotificationBase):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'payload': fields.ObjectField('VolumeUsagePayload')
    }


@nova_base.NovaObjectRegistry.register_notification
class VolumeUsagePayload(base.NotificationPayloadBase):
    # Version 1.0: Initial version
    VERSION = '1.0'

    SCHEMA = {
        'volume_id': ('vol_usage', 'volume_id'),
        'project_id': ('vol_usage', 'project_id'),
        'user_id': ('vol_usage', 'user_id'),
        'availability_zone': ('vol_usage', 'availability_zone'),
        'instance_uuid': ('vol_usage', 'instance_uuid'),
        'last_refreshed': ('vol_usage', 'last_refreshed'),
        'reads': ('vol_usage', 'reads'),
        'read_bytes': ('vol_usage', 'read_bytes'),
        'writes': ('vol_usage', 'writes'),
        'write_bytes': ('vol_usage', 'write_bytes')
    }

    fields = {
        'volume_id': fields.UUIDField(),
        'project_id': fields.StringField(nullable=True),
        'user_id': fields.StringField(nullable=True),
        'availability_zone': fields.StringField(nullable=True),
        'instance_uuid': fields.UUIDField(nullable=True),
        'last_refreshed': fields.DateTimeField(nullable=True),
        'reads': fields.IntegerField(),
        'read_bytes': fields.IntegerField(),
        'writes': fields.IntegerField(),
        'write_bytes': fields.IntegerField()
    }

    def __init__(self, vol_usage):
        super(VolumeUsagePayload, self).__init__()
        self.populate_schema(vol_usage=vol_usage)