nova notification


1 compute.instance.update类型的消息

需要配置notify_on_state_change参数,可以为空,或者vm_state,或者vm_and_task_state,

当虚拟机的状态或者task状态发送变化时发送消息:
    cfg.StrOpt('notify_on_state_change',
        help='If set, send compute.instance.update notifications on instance '
             'state changes.  Valid values are None for no notifications, '
             '"vm_state" for notifications on VM state changes, or '
             '"vm_and_task_state" for notifications on VM and task state '
             'changes.'),

默认为空,即不发送。

发送函数为:notification.send_update:

def send_update(context, old_instance, new_instance, service="compute",host=None):

    """Send compute.instance.update notification to report any changes occurred

    in that instance

"""

主要用在nova/object/instance.py的save函数中,当instance发送改变需要写入DB时调用。

在nova/compute/api.py 的_provision_instances中在创建instance时也会调用send_update_with_states发送。

  • 发送函数最后都是调用
    def _send_instance_update_notification中的
        rpc.get_notifier(service, host).info(context,
                                             'compute.instance.update', payload)

消息格式:

tenant_id: Tenant ID that owns the this instance (string)

user_id: User ID that owns this instance (string)
instance_id: Nova instance ID of this instance (string)
instance_type: Name of the instance type ('flavor') of this instance. (string)
instance_type_id: Nova ID for instance type ('flavor') of this instance. (string)
display_name: User selected display name for instance.
created_at: Timestamp for when this instance's record was created in Nova (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
launched_at: Timestamp for when this instance was last launched by hypervisor. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
image_ref_url: Image URL (from Glance) that this instance was created from. (string)
image_metadata: array of key-value pairs representing the metadata from the image from which the instance was built (array)
audit_period_begining: Timestamp of beginning of audit period. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
audit_period_ending: Timestamp of end of audit period. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
band Hash listing bandwidth used for each network this instance is connected to. Keys will be network labels, values will be hashes containing the keys 'bw_in', and 'bw_out', listing the incoming, and outgoing bandwith, respectively, used by that instance, on that network, for that audit period. Bandwith is reported in bytes.
old_state: Prior state of instance. (string, such as 'active' or 'deleted')
state: Current state of instance. (string, such as 'active' or 'deleted')
state_description: Additional human readable description of current state of instance.
fixed_ips: list of ip addresses formatted like [{"floating_ips": [], "meta": {}, "type": "fixed", "version": 4, "address": "10.0.0.9", "label": "public"}] assigned to instance.
memory_mb: memory allocation for this instance (in mb)
disk_gb: disk allocation for this instance (in gb)

2. api_faults

需要配置notify_api_faults,默认为False。

cfg.BoolOpt('notify_api_faults', default=False,
        help='If set, send api.fault notifications on caught exceptions '
             'in the API service.'),

当api调用失败,在异常处理中发送。
用在send_api_fault
    rpc.get_notifier('api').error(common_context.get_current() or
                                  nova.context.get_admin_context(),
                                  'api.fault',
                                  payload)
publish ID:'api'
类型:'api.fault'

用在nova/api/openstack/__init__.py:作为一个FaultWrapper的中间件
配置在etc/nova/api-paste.ini:paste.filter_factory = nova.api.openstack:FaultWrapper.factory
3. compute.instance*

nova/compute/utils.py
发送函数:def notify_about_instance_usage
method(context, 'compute.instance.%s' % event_suffix, usage_info)
param event_suffix: Event type like "delete.start" or "exists

被waper在:    
def _notify_about_instance_usage(self, context, instance, event_suffix,
                                     network_info=None, system_metadata=None,
                                     extra_usage_info=None, fault=None):
        compute_utils.notify_about_instance_usage(
            self.notifier, context, instance, event_suffix,
            network_info=network_info,
            system_metadata=system_metadata,
            extra_usage_info=extra_usage_info, fault=fault)
主要用在nova/compute/manager.py,还有def _build_and_run_instance:
self._notify_about_instance_usage(context, instance, 'create.start',
比如:event_type': u'compute.instance.reboot.start
compute.instance.create.start
compute.instance.exists
compute.instance.create.end

格式为:

compute.instance.rebuild.start/.end:

Usage notification upon rebuild of instance.
tenant_id: Tenant ID that owns the this instance (string)
user_id: User ID that owns this instance (string)
instance_id: Nova instance ID of this instance (string)
instance_type: Name of the instance type ('flavor') of this instance. (string)
instance_type_id: Nova ID for instance type ('flavor') of this instance. (string)
display_name: User selected display name for instance.
created_at: Timestamp for when this instance's record was created in Nova (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
launched_at: Timestamp for when this instance was last launched by hypervisor. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
image_ref_url: Image URL (from Glance) that this instance is being rebuilt from. (string)
state: Current state of instance. (string, such as 'active' or 'deleted')
state_description: Additional human readable description of current state of instance.
fixed_ips: list of ip addresses formatted like [{"floating_ips": [], "meta": {}, "type": "fixed", "version": 4, "address": "10.0.0.9", "label": "public"}] assigned to instance.
memory_mb: memory allocation for this instance (in mb)
disk_gb: disk allocation for this instance (in gb)

其中compute.instance.exists用来做audit

https://wiki.openstack.org/wiki/NotificationEventExamples

格式为:

compute.instance.exists:

There is no .start/.end event for this activity ... just the 'compute.instance.exists' event.

Periodic usage notification generated by the instance-usage-audit cron job. These usages are generated for each instance that was active during the specified audit period.
tenant_id: Tenant ID that owns the this instance (string)
user_id: User ID that owns this instance (string)
instance_id: Nova instance ID of this instance (string)
instance_type: Name of the instance type ('flavor') of this instance. (string)
instance_type_id: Nova ID for instance type ('flavor') of this instance. (string)
display_name: User selected display name for instance.
created_at: Timestamp for when this instance's record was created in Nova (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
launched_at: Timestamp for when this instance was last launched by hypervisor. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
image_ref_url: Image URL (from Glance) that this instance was created from. (string)
image_meta: Dictionary of key-value pairs representing metadata from the image the instance was built from.
audit_period_begining: Timestamp of beginning of audit period. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
audit_period_ending: Timestamp of end of audit period. (string, formatted "YYYY-MM-DD hh:mm:ss.ssssss")
band Hash listing bandwidth used for each network this instance is connected to. Keys will be network labels, values will be hashes containing the keys 'bw_in', and 'bw_out', listing the incoming, and outgoing bandwith, respectively, used by that instance, on that network, for that audit period. Bandwith is reported in bytes.
state: Current state of instance. (string, such as 'active' or 'deleted')
state_description: Additional human readable description of current state of instance.
fixed_ips: list of ip addresses formatted like [{"floating_ips": [], "meta": {}, "type": "fixed", "version": 4, "address": "10.0.0.9", "label": "public"}] assigned to instance.
memory_mb: memory allocation for this instance (in mb)
disk_gb: disk allocation for this instance (in gb) 

https://wiki.openstack.org/wiki/SystemUsageData

https://review.openstack.org/#/c/224755/

原文地址:https://www.cnblogs.com/allcloud/p/4972163.html