Coverage for nova/notifications/objects/volume.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Copyright 2018 NTT Corporation 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15from nova.notifications.objects import base 

16from nova.objects import base as nova_base 

17from nova.objects import fields 

18 

19 

20@base.notification_sample('volume-usage.json') 

21@nova_base.NovaObjectRegistry.register_notification 

22class VolumeUsageNotification(base.NotificationBase): 

23 # Version 1.0: Initial version 

24 VERSION = '1.0' 

25 

26 fields = { 

27 'payload': fields.ObjectField('VolumeUsagePayload') 

28 } 

29 

30 

31@nova_base.NovaObjectRegistry.register_notification 

32class VolumeUsagePayload(base.NotificationPayloadBase): 

33 # Version 1.0: Initial version 

34 VERSION = '1.0' 

35 

36 SCHEMA = { 

37 'volume_id': ('vol_usage', 'volume_id'), 

38 'project_id': ('vol_usage', 'project_id'), 

39 'user_id': ('vol_usage', 'user_id'), 

40 'availability_zone': ('vol_usage', 'availability_zone'), 

41 'instance_uuid': ('vol_usage', 'instance_uuid'), 

42 'last_refreshed': ('vol_usage', 'last_refreshed'), 

43 'reads': ('vol_usage', 'reads'), 

44 'read_bytes': ('vol_usage', 'read_bytes'), 

45 'writes': ('vol_usage', 'writes'), 

46 'write_bytes': ('vol_usage', 'write_bytes') 

47 } 

48 

49 fields = { 

50 'volume_id': fields.UUIDField(), 

51 'project_id': fields.StringField(nullable=True), 

52 'user_id': fields.StringField(nullable=True), 

53 'availability_zone': fields.StringField(nullable=True), 

54 'instance_uuid': fields.UUIDField(nullable=True), 

55 'last_refreshed': fields.DateTimeField(nullable=True), 

56 'reads': fields.IntegerField(), 

57 'read_bytes': fields.IntegerField(), 

58 'writes': fields.IntegerField(), 

59 'write_bytes': fields.IntegerField() 

60 } 

61 

62 def __init__(self, vol_usage): 

63 super(VolumeUsagePayload, self).__init__() 

64 self.populate_schema(vol_usage=vol_usage)