From 6817d22826860d7cf02be7296b5b87e319f4e08f Mon Sep 17 00:00:00 2001 From: liyingjun Date: Fri, 30 Dec 2016 09:09:13 +0800 Subject: [PATCH] Move FlavorPayload to a seperate file Seperate FlavorPayload from notifications.objects.instance to notifications.objects.flavor for later flavor notifications use. Partial blueprint: flavor-notifications Change-Id: I953b97c5a0d1e74c1f21db5a57a59f8547a554fb --- nova/compute/utils.py | 5 ++-- nova/notifications/base.py | 3 +- nova/notifications/objects/flavor.py | 41 ++++++++++++++++++++++++++ nova/notifications/objects/instance.py | 26 ---------------- 4 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 nova/notifications/objects/flavor.py diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 76744f07165e..bc91014ea235 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -34,6 +34,7 @@ from nova.network import model as network_model from nova import notifications from nova.notifications.objects import base as notification_base from nova.notifications.objects import exception as notification_exception +from nova.notifications.objects import flavor as flavor_notification from nova.notifications.objects import instance as instance_notification from nova import objects from nova.objects import fields @@ -363,7 +364,7 @@ def notify_about_instance_action(context, instance, host, action, phase=None, """ ips = _get_instance_ips(instance) - flavor = instance_notification.FlavorPayload(instance=instance) + flavor = flavor_notification.FlavorPayload(instance=instance) fault, priority = _get_fault_and_priority_from_exc(exception) payload = instance_notification.InstanceActionPayload( instance=instance, @@ -399,7 +400,7 @@ def notify_about_volume_swap(context, instance, host, action, phase, """ ips = _get_instance_ips(instance) - flavor = instance_notification.FlavorPayload(instance=instance) + flavor = flavor_notification.FlavorPayload(instance=instance) fault, priority = _get_fault_and_priority_from_exc(exception) payload = instance_notification.InstanceActionVolumeSwapPayload( diff --git a/nova/notifications/base.py b/nova/notifications/base.py index d22b98604982..69716f573859 100644 --- a/nova/notifications/base.py +++ b/nova/notifications/base.py @@ -34,6 +34,7 @@ from nova.image import glance from nova import network from nova.network import model as network_model from nova.notifications.objects import base as notification_base +from nova.notifications.objects import flavor as flavor_notification from nova.notifications.objects import instance as instance_notification from nova import objects from nova.objects import base as obj_base @@ -280,7 +281,7 @@ def _send_versioned_instance_update(context, instance, payload, host, service): for label, bw in payload['bandwidth'].items()] network_info = instance.info_cache.network_info - flavor = instance_notification.FlavorPayload(instance=instance) + flavor = flavor_notification.FlavorPayload(instance=instance) versioned_payload = instance_notification.InstanceUpdatePayload( instance=instance, diff --git a/nova/notifications/objects/flavor.py b/nova/notifications/objects/flavor.py new file mode 100644 index 000000000000..a06cc0bb97ef --- /dev/null +++ b/nova/notifications/objects/flavor.py @@ -0,0 +1,41 @@ +# 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 + + +@nova_base.NovaObjectRegistry.register_notification +class FlavorPayload(base.NotificationPayloadBase): + # Version 1.0: Initial version + VERSION = '1.0' + + SCHEMA = { + 'flavorid': ('flavor', 'flavorid'), + 'memory_mb': ('flavor', 'memory_mb'), + 'vcpus': ('flavor', 'vcpus'), + 'root_gb': ('flavor', 'root_gb'), + 'ephemeral_gb': ('flavor', 'ephemeral_gb'), + } + + fields = { + 'flavorid': fields.StringField(nullable=True), + 'memory_mb': fields.IntegerField(nullable=True), + 'vcpus': fields.IntegerField(nullable=True), + 'root_gb': fields.IntegerField(nullable=True), + 'ephemeral_gb': fields.IntegerField(nullable=True), + } + + def __init__(self, instance, **kwargs): + super(FlavorPayload, self).__init__(**kwargs) + self.populate_schema(instance=instance, flavor=instance.flavor) diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index 3f495b00451d..b2d65273f9a4 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -184,32 +184,6 @@ class IpPayload(base.NotificationPayloadBase): return ips -@nova_base.NovaObjectRegistry.register_notification -class FlavorPayload(base.NotificationPayloadBase): - # Version 1.0: Initial version - VERSION = '1.0' - - SCHEMA = { - 'flavorid': ('flavor', 'flavorid'), - 'memory_mb': ('flavor', 'memory_mb'), - 'vcpus': ('flavor', 'vcpus'), - 'root_gb': ('flavor', 'root_gb'), - 'ephemeral_gb': ('flavor', 'ephemeral_gb'), - } - - fields = { - 'flavorid': fields.StringField(nullable=True), - 'memory_mb': fields.IntegerField(nullable=True), - 'vcpus': fields.IntegerField(nullable=True), - 'root_gb': fields.IntegerField(nullable=True), - 'ephemeral_gb': fields.IntegerField(nullable=True), - } - - def __init__(self, instance, **kwargs): - super(FlavorPayload, self).__init__(**kwargs) - self.populate_schema(instance=instance, flavor=instance.flavor) - - @nova_base.NovaObjectRegistry.register_notification class BandwidthPayload(base.NotificationPayloadBase): # Version 1.0: Initial version