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
This commit is contained in:
liyingjun 2016-12-30 09:09:13 +08:00 committed by Matt Riedemann
parent a74d3ae4e8
commit 6817d22826
4 changed files with 46 additions and 29 deletions

View File

@ -34,6 +34,7 @@ from nova.network import model as network_model
from nova import notifications from nova import notifications
from nova.notifications.objects import base as notification_base from nova.notifications.objects import base as notification_base
from nova.notifications.objects import exception as notification_exception 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.notifications.objects import instance as instance_notification
from nova import objects from nova import objects
from nova.objects import fields 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) 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) fault, priority = _get_fault_and_priority_from_exc(exception)
payload = instance_notification.InstanceActionPayload( payload = instance_notification.InstanceActionPayload(
instance=instance, instance=instance,
@ -399,7 +400,7 @@ def notify_about_volume_swap(context, instance, host, action, phase,
""" """
ips = _get_instance_ips(instance) 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) fault, priority = _get_fault_and_priority_from_exc(exception)
payload = instance_notification.InstanceActionVolumeSwapPayload( payload = instance_notification.InstanceActionVolumeSwapPayload(

View File

@ -34,6 +34,7 @@ from nova.image import glance
from nova import network from nova import network
from nova.network import model as network_model from nova.network import model as network_model
from nova.notifications.objects import base as notification_base 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.notifications.objects import instance as instance_notification
from nova import objects from nova import objects
from nova.objects import base as obj_base 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()] for label, bw in payload['bandwidth'].items()]
network_info = instance.info_cache.network_info network_info = instance.info_cache.network_info
flavor = instance_notification.FlavorPayload(instance=instance) flavor = flavor_notification.FlavorPayload(instance=instance)
versioned_payload = instance_notification.InstanceUpdatePayload( versioned_payload = instance_notification.InstanceUpdatePayload(
instance=instance, instance=instance,

View File

@ -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)

View File

@ -184,32 +184,6 @@ class IpPayload(base.NotificationPayloadBase):
return ips 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 @nova_base.NovaObjectRegistry.register_notification
class BandwidthPayload(base.NotificationPayloadBase): class BandwidthPayload(base.NotificationPayloadBase):
# Version 1.0: Initial version # Version 1.0: Initial version