Пример #1
0
def notify_about_volume_swap(context, instance, host, action, phase,
                             old_volume_id, new_volume_id):
    """Send versioned notification about the volume swap action
       on the instance

    :param context: the request context
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param old_volume_id: the ID of the volume that is copied from and detached
    :param new_volume_id: the ID of the volume that is copied to and attached
    """
    ips = _get_instance_ips(instance)

    flavor = instance_notification.FlavorPayload(instance=instance)
    payload = instance_notification.InstanceActionVolumeSwapPayload(
        instance=instance,
        fault=None,
        ip_addresses=ips,
        flavor=flavor,
        old_volume_id=old_volume_id,
        new_volume_id=new_volume_id)

    instance_notification.InstanceActionVolumeSwapNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            context=context, host=host, binary='nova-compute'),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload).emit(context)
Пример #2
0
def notify_about_compute_task_error(context, action, instance_uuid,
                                    request_spec, state, exception, tb):
    """Send a versioned notification about compute task error.

    :param context: the request context
    :param action: the name of the action
    :param instance_uuid: the UUID of the instance
    :param request_spec: the request spec object or
                         the dict includes request spec information
    :param state: the vm state of the instance
    :param exception: the thrown exception
    :param tb: the traceback
    """
    if (request_spec is not None and
            not isinstance(request_spec, objects.RequestSpec)):
        request_spec = objects.RequestSpec.from_primitives(
            context, request_spec, {})

    fault, _ = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = task_notification.ComputeTaskPayload(
        instance_uuid=instance_uuid, request_spec=request_spec, state=state,
        reason=fault)
    notification = task_notification.ComputeTaskNotification(
        priority=fields.NotificationPriority.ERROR,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.CONDUCTOR),
        event_type=notification_base.EventType(
            object='compute_task',
            action=action,
            phase=fields.NotificationPhase.ERROR),
        payload=payload)
    notification.emit(context)
Пример #3
0
def _send_versioned_instance_update(context, instance, payload, host, service):

    def _map_legacy_service_to_source(legacy_service):
        if not legacy_service.startswith('nova-'):
            return 'nova-' + service
        else:
            return service

    state_update = instance_notification.InstanceStateUpdatePayload(
        old_state=payload.get('old_state'),
        state=payload.get('state'),
        old_task_state=payload.get('old_task_state'),
        new_task_state=payload.get('new_task_state'))

    audit_period = instance_notification.AuditPeriodPayload(
        audit_period_beginning=payload.get('audit_period_beginning'),
        audit_period_ending=payload.get('audit_period_ending'))

    versioned_payload = instance_notification.InstanceUpdatePayload(
        context=context,
        instance=instance,
        state_update=state_update,
        audit_period=audit_period,
        old_display_name=payload.get('old_display_name'))

    notification = instance_notification.InstanceUpdateNotification(
        priority=fields.NotificationPriority.INFO,
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.UPDATE),
        publisher=notification_base.NotificationPublisher(
                host=host or CONF.host,
                source=_map_legacy_service_to_source(service)),
        payload=versioned_payload)
    notification.emit(context)
Пример #4
0
def notify_about_instance_action(context,
                                 instance,
                                 host,
                                 action,
                                 phase=None,
                                 binary='nova-compute',
                                 exception=None):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    :param exception: the thrown exception (used in error notifications)
    """
    ips = _get_instance_ips(instance)

    flavor = instance_notification.FlavorPayload(instance=instance)
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceActionPayload(instance=instance,
                                                          fault=fault,
                                                          ip_addresses=ips,
                                                          flavor=flavor)
    notification = instance_notification.InstanceActionNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(context=context,
                                                          host=host,
                                                          binary=binary),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #5
0
def notify_about_instance_rebuild(context, instance, host, phase=None,
                                  exception=None, bdms=None, tb=None):
    """Send versioned notification about instance rebuild

    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param phase: the phase of the action
    :param exception: the thrown exception (used in error notifications)
    :param bdms: BlockDeviceMappingList object for the instance. If it is not
                provided then we will load it from the db if so configured
    :param tb: the traceback (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = instance_notification.InstanceActionRebuildPayload(
            context=context,
            instance=instance,
            fault=fault,
            bdms=bdms)
    notification = instance_notification.InstanceActionRebuildNotification(
            context=context,
            priority=priority,
            publisher=notification_base.NotificationPublisher(
                host=host, source=fields.NotificationSource.COMPUTE),
            event_type=notification_base.EventType(
                    object='instance',
                    action=fields.NotificationAction.REBUILD,
                    phase=phase),
            payload=payload)
    notification.emit(context)
Пример #6
0
def _send_versioned_instance_update(context, instance, payload, host, service):

    state_update = instance_notification.InstanceStateUpdatePayload(
        old_state=payload.get('old_state'),
        state=payload.get('state'),
        old_task_state=payload.get('old_task_state'),
        new_task_state=payload.get('new_task_state'))

    audit_period = instance_notification.AuditPeriodPayload(
        audit_period_beginning=payload.get('audit_period_beginning'),
        audit_period_ending=payload.get('audit_period_ending'))

    bandwidth = [
        instance_notification.BandwidthPayload(network_name=label,
                                               in_bytes=bw['bw_in'],
                                               out_bytes=bw['bw_out'])
        for label, bw in payload['bandwidth'].items()
    ]

    versioned_payload = instance_notification.InstanceUpdatePayload(
        instance=instance,
        state_update=state_update,
        audit_period=audit_period,
        bandwidth=bandwidth,
        old_display_name=payload.get('old_display_name'))

    notification = instance_notification.InstanceUpdateNotification(
        priority=fields.NotificationPriority.INFO,
        event_type=notification_base.EventType(
            object='instance', action=fields.NotificationAction.UPDATE),
        publisher=notification_base.NotificationPublisher(
            host=host or CONF.host, binary=_map_service_to_binary(service)),
        payload=versioned_payload)
    notification.emit(context)
Пример #7
0
def notify_about_instance_create(context,
                                 instance,
                                 host,
                                 phase=None,
                                 source=fields.NotificationSource.COMPUTE,
                                 exception=None,
                                 bdms=None):
    """Send versioned notification about instance creation

    :param context: the request context
    :param instance: the instance being created
    :param host: the host emitting the notification
    :param phase: the phase of the creation
    :param source: the source of the notification
    :param exception: the thrown exception (used in error notifications)
    :param bdms: BlockDeviceMappingList object for the instance. If it is not
                provided then we will load it from the db if so configured
    """
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceCreatePayload(instance=instance,
                                                          fault=fault,
                                                          bdms=bdms)
    notification = instance_notification.InstanceCreateNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(host=host,
                                                          source=source),
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.CREATE,
            phase=phase),
        payload=payload)
    notification.emit(context)
Пример #8
0
def notify_about_metrics_update(context, host, host_ip, nodename,
                                monitor_metric_list):
    """Send versioned notification about updating metrics

    :param context: the request context
    :param host: the host emitting the notification
    :param host_ip: the IP address of the host
    :param nodename: the node name
    :param monitor_metric_list: the MonitorMetricList object
    """
    payload = metrics_notification.MetricsPayload(
            host=host,
            host_ip=host_ip,
            nodename=nodename,
            monitor_metric_list=monitor_metric_list)
    notification = metrics_notification.MetricsNotification(
            context=context,
            priority=fields.NotificationPriority.INFO,
            publisher=notification_base.NotificationPublisher(
                host=host, source=fields.NotificationSource.COMPUTE),
            event_type=notification_base.EventType(
                object='metrics',
                action=fields.NotificationAction.UPDATE),
            payload=payload)
    notification.emit(context)
Пример #9
0
def notify_about_instance_action(context,
                                 instance,
                                 host,
                                 action,
                                 phase=None,
                                 source=fields.NotificationSource.COMPUTE,
                                 exception=None):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param source: the source of the notification
    :param exception: the thrown exception (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceActionPayload(instance=instance,
                                                          fault=fault)
    notification = instance_notification.InstanceActionNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(host=host,
                                                          source=source),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #10
0
def notify_about_volume_swap(context, instance, host, phase,
                             old_volume_id, new_volume_id, exception=None,
                             tb=None):
    """Send versioned notification about the volume swap action
       on the instance

    :param context: the request context
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param phase: the phase of the action
    :param old_volume_id: the ID of the volume that is copied from and detached
    :param new_volume_id: the ID of the volume that is copied to and attached
    :param exception: an exception
    :param tb: the traceback (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = instance_notification.InstanceActionVolumeSwapPayload(
        context=context,
        instance=instance,
        fault=fault,
        old_volume_id=old_volume_id,
        new_volume_id=new_volume_id)

    instance_notification.InstanceActionVolumeSwapNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(
            host=host, source=fields.NotificationSource.COMPUTE),
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.VOLUME_SWAP,
            phase=phase),
        payload=payload).emit(context)
Пример #11
0
def notify_about_instance_rescue_action(context, instance, host,
                                        rescue_image_ref, phase=None,
                                        exception=None, tb=None):
    """Send versioned notification about the action made on the instance

    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param rescue_image_ref: the rescue image ref
    :param phase: the phase of the action
    :param exception: the thrown exception (used in error notifications)
    :param tb: the traceback (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = instance_notification.InstanceActionRescuePayload(
            context=context,
            instance=instance,
            fault=fault,
            rescue_image_ref=rescue_image_ref)

    notification = instance_notification.InstanceActionRescueNotification(
            context=context,
            priority=priority,
            publisher=notification_base.NotificationPublisher(
                host=host, source=fields.NotificationSource.COMPUTE),
            event_type=notification_base.EventType(
                    object='instance',
                    action=fields.NotificationAction.RESCUE,
                    phase=phase),
            payload=payload)
    notification.emit(context)
Пример #12
0
def notify_about_instance_create(context,
                                 instance,
                                 host,
                                 phase=None,
                                 binary='nova-compute',
                                 exception=None):
    """Send versioned notification about instance creation

    :param context: the request context
    :param instance: the instance being created
    :param host: the host emitting the notification
    :param phase: the phase of the creation
    :param binary: the binary emitting the notification
    :param exception: the thrown exception (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceCreatePayload(instance=instance,
                                                          fault=fault)
    notification = instance_notification.InstanceCreateNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(host=host,
                                                          binary=binary),
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.CREATE,
            phase=phase),
        payload=payload)
    notification.emit(context)
Пример #13
0
def notify_about_instance_snapshot(context, instance, host, phase,
                                   snapshot_image_id):
    """Send versioned notification about the snapshot action executed on the
       instance

    :param context: the request context
    :param instance: the instance from which a snapshot image is being created
    :param host: the host emitting the notification
    :param phase: the phase of the action
    :param snapshot_image_id: the ID of the snapshot
    """
    payload = instance_notification.InstanceActionSnapshotPayload(
        context=context,
        instance=instance,
        fault=None,
        snapshot_image_id=snapshot_image_id)

    instance_notification.InstanceActionSnapshotNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=host, source=fields.NotificationSource.COMPUTE),
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.SNAPSHOT,
            phase=phase),
        payload=payload).emit(context)
Пример #14
0
def notify_about_instance_action(context,
                                 instance,
                                 host,
                                 action,
                                 phase=None,
                                 binary='nova-compute'):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    """
    ips = _get_instance_ips(instance)

    flavor = instance_notification.FlavorPayload(instance=instance)
    # TODO(gibi): handle fault during the transformation of the first error
    # notifications
    payload = instance_notification.InstanceActionPayload(instance=instance,
                                                          fault=None,
                                                          ip_addresses=ips,
                                                          flavor=flavor)
    notification = instance_notification.InstanceActionNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(context=context,
                                                          host=host,
                                                          binary=binary),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #15
0
def notify_about_resize_prep_instance(context, instance, host, phase,
                                      new_flavor):
    """Send versioned notification about the instance resize action
       on the instance

    :param context: the request context
    :param instance: the instance which the resize action performed on
    :param host: the host emitting the notification
    :param phase: the phase of the action
    :param new_flavor: new flavor
    """

    payload = instance_notification.InstanceActionResizePrepPayload(
        context=context,
        instance=instance,
        fault=None,
        new_flavor=flavor_notification.FlavorPayload(flavor=new_flavor))

    instance_notification.InstanceActionResizePrepNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=host, source=fields.NotificationSource.COMPUTE),
        event_type=notification_base.EventType(
            object='instance',
            action=fields.NotificationAction.RESIZE_PREP,
            phase=phase),
        payload=payload).emit(context)
Пример #16
0
def notify_about_volume_swap(context, instance, host, action, phase,
                             old_volume_id, new_volume_id, exception=None):
    """Send versioned notification about the volume swap action
       on the instance

    :param context: the request context
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param old_volume_id: the ID of the volume that is copied from and detached
    :param new_volume_id: the ID of the volume that is copied to and attached
    :param exception: an exception
    """
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceActionVolumeSwapPayload(
        instance=instance,
        fault=fault,
        old_volume_id=old_volume_id,
        new_volume_id=new_volume_id)

    instance_notification.InstanceActionVolumeSwapNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(
            host=host, binary='nova-compute'),
        event_type=notification_base.EventType(
            object='instance', action=action, phase=phase),
        payload=payload).emit(context)
Пример #17
0
def notify_about_volume_attach_detach(context, instance, host, action, phase,
                                      volume_id=None, exception=None, tb=None):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param volume_id: id of the volume will be attached
    :param exception: the thrown exception (used in error notifications)
    :param tb: the traceback (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = instance_notification.InstanceActionVolumePayload(
            context=context,
            instance=instance,
            fault=fault,
            volume_id=volume_id)
    notification = instance_notification.InstanceActionVolumeNotification(
            context=context,
            priority=priority,
            publisher=notification_base.NotificationPublisher(
                    host=host, source=fields.NotificationSource.COMPUTE),
            event_type=notification_base.EventType(
                    object='instance',
                    action=action,
                    phase=phase),
            payload=payload)
    notification.emit(context)
Пример #18
0
def notify_about_volume_attach_detach(context,
                                      instance,
                                      host,
                                      action,
                                      phase,
                                      binary='nova-compute',
                                      volume_id=None,
                                      exception=None):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    :param volume_id: id of the volume will be attached
    :param exception: the thrown exception (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceActionVolumePayload(
        instance=instance, fault=fault, volume_id=volume_id)
    notification = instance_notification.InstanceActionVolumeNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(context=context,
                                                          host=host,
                                                          binary=binary),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #19
0
def notify_about_server_group_action(context, group, action):
    payload = sg_notification.ServerGroupPayload(group)
    notification = sg_notification.ServerGroupNotification(
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.API),
        event_type=notification_base.EventType(object='server_group',
                                               action=action),
        payload=payload)
    notification.emit(context)
Пример #20
0
def notify_about_aggregate_action(context, aggregate, action, phase):
    payload = aggregate_notification.AggregatePayload(aggregate)
    notification = aggregate_notification.AggregateNotification(
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.API),
        event_type=notification_base.EventType(object='aggregate',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #21
0
def _emit_versioned_exception_notification(context, ex, source):
    versioned_exception_payload = exception.ExceptionPayload.from_exception(ex)
    publisher = base.NotificationPublisher(host=CONF.host, source=source)
    event_type = base.EventType(object='compute',
                                action=fields.NotificationAction.EXCEPTION)
    notification = exception.ExceptionNotification(
        publisher=publisher,
        event_type=event_type,
        priority=fields.NotificationPriority.ERROR,
        payload=versioned_exception_payload)
    notification.emit(context)
Пример #22
0
    def _send_notification(self, action):
        notification_type = flavor_notification.FlavorNotification
        payload_type = flavor_notification.FlavorPayload

        payload = payload_type(self)
        notification_type(publisher=notification.NotificationPublisher(
            host=CONF.host, binary="nova-api"),
                          event_type=notification.EventType(object="flavor",
                                                            action=action),
                          priority=fields.NotificationPriority.INFO,
                          payload=payload).emit(self._context)
Пример #23
0
def notify_about_server_group_add_member(context, group_id):
    group = objects.InstanceGroup.get_by_uuid(context, group_id)
    payload = sg_notification.ServerGroupPayload(group)
    notification = sg_notification.ServerGroupNotification(
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.API),
        event_type=notification_base.EventType(
            object='server_group',
            action=fields.NotificationAction.ADD_MEMBER),
        payload=payload)
    notification.emit(context)
Пример #24
0
    def _send_notification(self, action):
        # NOTE(danms): Instead of making the below notification
        # lazy-load projects (which is a problem for instance-bound
        # flavors and compute-cell operations), just load them here.
        if 'projects' not in self:
            self._load_projects()
        notification_type = flavor_notification.FlavorNotification
        payload_type = flavor_notification.FlavorPayload

        payload = payload_type(self)
        notification_type(publisher=notification.NotificationPublisher(
            host=CONF.host, binary="nova-api"),
                          event_type=notification.EventType(object="flavor",
                                                            action=action),
                          priority=fields.NotificationPriority.INFO,
                          payload=payload).emit(self._context)
Пример #25
0
def notify_about_volume_usage(context, vol_usage, host):
    """Send versioned notification about the volume usage

    :param context: the request context
    :param vol_usage: the volume usage object
    :param host: the host emitting the notification
    """
    payload = volume_notification.VolumeUsagePayload(vol_usage=vol_usage)
    notification = volume_notification.VolumeUsageNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=host, source=fields.NotificationSource.COMPUTE),
        event_type=notification_base.EventType(
            object='volume', action=fields.NotificationAction.USAGE),
        payload=payload)
    notification.emit(context)
Пример #26
0
    def test_emit_with_host_and_binary_as_publisher(self, mock_notifier):
        noti = self.TestNotification(
            event_type=notification.EventType(
                object='test_object', action=fields.NotificationAction.UPDATE),
            publisher=notification.NotificationPublisher(
                host='fake-host', source='nova-compute'),
            priority=fields.NotificationPriority.INFO,
            payload=self.payload)

        mock_context = mock.Mock()
        mock_context.to_dict.return_value = {}
        noti.emit(mock_context)

        self._verify_notification(mock_notifier,
                                  mock_context,
                                  expected_event_type='test_object.update',
                                  expected_payload=self.expected_payload)
Пример #27
0
def notify_about_instance_action(context,
                                 instance,
                                 host,
                                 action,
                                 phase=None,
                                 binary='nova-compute'):
    """Send versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    """
    network_info = get_nw_info_for_instance(instance)
    ips = []
    if network_info is not None:
        for vif in network_info:
            for ip in vif.fixed_ips():
                ips.append(
                    instance_notification.IpPayload(
                        label=vif["network"]["label"],
                        mac=vif["address"],
                        meta=vif["meta"],
                        port_uuid=vif["id"],
                        version=ip["version"],
                        address=ip["address"],
                        device_name=vif["devname"]))
    flavor = instance_notification.FlavorPayload(instance=instance)
    # TODO(gibi): handle fault during the transformation of the first error
    # notifications
    payload = instance_notification.InstanceActionPayload(instance=instance,
                                                          fault=None,
                                                          ip_addresses=ips,
                                                          flavor=flavor)
    notification = instance_notification.InstanceActionNotification(
        context=context,
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(context=context,
                                                          host=host,
                                                          binary=binary),
        event_type=notification_base.EventType(object='instance',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #28
0
def notify_about_keypair_action(context, keypair, action, phase):
    """Send versioned notification about the keypair action on the instance

    :param context: the request context
    :param keypair: the keypair which the action performed on
    :param action: the name of the action
    :param phase: the phase of the action
    """
    payload = keypair_notification.KeypairPayload(keypair=keypair)
    notification = keypair_notification.KeypairNotification(
        priority=fields.NotificationPriority.INFO,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.API),
        event_type=notification_base.EventType(object='keypair',
                                               action=action,
                                               phase=phase),
        payload=payload)
    notification.emit(context)
Пример #29
0
def notify_about_libvirt_connect_error(context, ip, exception, tb):
    """Send a versioned notification about libvirt connect error.

    :param context: the request context
    :param ip: the IP address of the host
    :param exception: the thrown exception
    :param tb: the traceback
    """
    fault, _ = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = libvirt_notification.LibvirtErrorPayload(ip=ip, reason=fault)
    notification = libvirt_notification.LibvirtErrorNotification(
        priority=fields.NotificationPriority.ERROR,
        publisher=notification_base.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.COMPUTE),
        event_type=notification_base.EventType(
            object='libvirt',
            action=fields.NotificationAction.CONNECT,
            phase=fields.NotificationPhase.ERROR),
        payload=payload)
    notification.emit(context)
Пример #30
0
    def _send_notification(self, action):
        # NOTE(danms): Instead of making the below notification
        # lazy-load projects (which is a problem for instance-bound
        # flavors and compute-cell operations), just load them here.
        if 'projects' not in self:
            # If the flavor is deleted we can't lazy-load projects.
            # FlavorPayload will orphan the flavor which will make the
            # NotificationPayloadBase set projects=None in the notification
            # payload.
            if action != fields.NotificationAction.DELETE:
                self._load_projects()
        notification_type = flavor_notification.FlavorNotification
        payload_type = flavor_notification.FlavorPayload

        payload = payload_type(self)
        notification_type(publisher=notification.NotificationPublisher(
            host=CONF.host, source=fields.NotificationSource.API),
                          event_type=notification.EventType(object="flavor",
                                                            action=action),
                          priority=fields.NotificationPriority.INFO,
                          payload=payload).emit(self._context)