Ejemplo n.º 1
0
    def __init__(self, instance):
        super(InstancePayload, self).__init__()
        network_info = instance.get_network_info()
        self.ip_addresses = IpPayload.from_network_info(network_info)
        self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)

        self.populate_schema(instance=instance)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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 = flavor_notification.FlavorPayload(instance.flavor)
    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)
Ejemplo n.º 4
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
    """
    ips = _get_instance_ips(instance)

    flavor = flavor_notification.FlavorPayload(instance.flavor)

    fault, priority = _get_fault_and_priority_from_exc(exception)
    payload = instance_notification.InstanceActionVolumeSwapPayload(
        instance=instance,
        fault=fault,
        ip_addresses=ips,
        flavor=flavor,
        old_volume_id=old_volume_id,
        new_volume_id=new_volume_id)

    instance_notification.InstanceActionVolumeSwapNotification(
        context=context,
        priority=priority,
        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)
Ejemplo n.º 5
0
    def __init__(self, instance):
        super(InstancePayload, self).__init__()
        network_info = instance.get_network_info()
        self.ip_addresses = IpPayload.from_network_info(network_info)
        self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)
        # TODO(gibi): investigate the possibility to use already in scope bdm
        # when available like in instance.create
        self.block_devices = BlockDevicePayload.from_instance(instance)

        self.populate_schema(instance=instance)
Ejemplo n.º 6
0
    def __init__(self, instance):
        super(InstancePayload, self).__init__()
        # Note(gibi): ugly but needed to avoid cyclic import
        from nova.compute import utils

        self.ip_addresses = IpPayload.from_network_info(
            utils.get_nw_info_for_instance(instance))
        self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)

        self.populate_schema(instance=instance)
Ejemplo n.º 7
0
    def __init__(self, instance, bdms=None):
        super(InstancePayload, self).__init__()
        network_info = instance.get_network_info()
        self.ip_addresses = IpPayload.from_network_info(network_info)
        self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)
        if bdms is not None:
            self.block_devices = BlockDevicePayload.from_bdms(bdms)
        else:
            self.block_devices = BlockDevicePayload.from_instance(instance)

        self.populate_schema(instance=instance)
Ejemplo n.º 8
0
 def __init__(self, request_spec):
     super(RequestSpecPayload, self).__init__()
     self.flavor = flavor_payload.FlavorPayload(
         request_spec.flavor) if request_spec.obj_attr_is_set(
             'flavor') else None
     self.image = image_payload.ImageMetaPayload(
         request_spec.image) if request_spec.image else None
     if request_spec.numa_topology is not None:
         if not request_spec.numa_topology.obj_attr_is_set('instance_uuid'):
             request_spec.numa_topology.instance_uuid = (
                 request_spec.instance_uuid)
         self.numa_topology = InstanceNUMATopologyPayload(
             request_spec.numa_topology)
     else:
         self.numa_topology = None
     if request_spec.pci_requests is not None:
         if not request_spec.pci_requests.obj_attr_is_set('instance_uuid'):
             request_spec.pci_requests.instance_uuid = (
                 request_spec.instance_uuid)
         self.pci_requests = InstancePCIRequestsPayload(
             request_spec.pci_requests)
     else:
         self.pci_requests = None
     if 'requested_destination' in request_spec \
             and request_spec.requested_destination:
         self.requested_destination = DestinationPayload(
             destination=request_spec.requested_destination)
     else:
         self.requested_destination = None
     if 'retry' in request_spec and request_spec.retry:
         self.retry = SchedulerRetriesPayload(retry=request_spec.retry)
     else:
         self.retry = None
     self.security_groups = [
         sec_group.identifier for sec_group in request_spec.security_groups
     ]
     if 'instance_group' in request_spec and request_spec.instance_group:
         self.instance_group = server_group_payload.ServerGroupPayload(
             group=request_spec.instance_group)
     else:
         self.instance_group = None
     if 'force_hosts' in request_spec and request_spec.force_hosts:
         self.force_hosts = request_spec.force_hosts[0]
     else:
         self.force_hosts = None
     if 'force_nodes' in request_spec and request_spec.force_nodes:
         self.force_nodes = request_spec.force_nodes[0]
     else:
         self.force_nodes = None
     self.populate_schema(request_spec=request_spec)
Ejemplo n.º 9
0
    def __init__(self, context, instance, bdms=None):
        super(InstancePayload, self).__init__()
        network_info = instance.get_network_info()
        self.ip_addresses = IpPayload.from_network_info(network_info)
        self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)
        if bdms is not None:
            self.block_devices = BlockDevicePayload.from_bdms(bdms)
        else:
            self.block_devices = BlockDevicePayload.from_instance(instance)
        # NOTE(Kevin_Zheng): Don't include request_id for periodic tasks,
        # RequestContext for periodic tasks does not include project_id
        # and user_id. Consider modify this once periodic tasks got a
        # consistent request_id.
        self.request_id = context.request_id if (context.project_id
                                                 and context.user_id) else None

        self.populate_schema(instance=instance)
Ejemplo n.º 10
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()
    ]

    network_info = instance.info_cache.network_info
    flavor = flavor_notification.FlavorPayload(instance.flavor)

    versioned_payload = instance_notification.InstanceUpdatePayload(
        instance=instance,
        state_update=state_update,
        audit_period=audit_period,
        bandwidth=bandwidth,
        ip_addresses=instance_notification.IpPayload.from_network_info(
            network_info),
        flavor=flavor,
        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)
Ejemplo n.º 11
0
 def test_obj_make_compatible(self):
     flavor = copy.deepcopy(fake_flavor)
     flavorid = '1'
     flavor['flavorid'] = flavorid
     flavor['id'] = flavorid
     flavor_obj = objects.Flavor(context=self.ctxt, **flavor)
     flavor_payload = flavor_notification.FlavorPayload(flavor_obj)
     primitive = flavor_payload.obj_to_primitive()
     self.assertIn('name', primitive['nova_object.data'])
     self.assertIn('swap', primitive['nova_object.data'])
     self.assertIn('rxtx_factor', primitive['nova_object.data'])
     self.assertIn('vcpu_weight', primitive['nova_object.data'])
     self.assertIn('disabled', primitive['nova_object.data'])
     self.assertIn('is_public', primitive['nova_object.data'])
     flavor_payload.obj_make_compatible(primitive['nova_object.data'],
                                        '1.0')
     self.assertNotIn('name', primitive['nova_object.data'])
     self.assertNotIn('swap', primitive['nova_object.data'])
     self.assertNotIn('rxtx_factor', primitive['nova_object.data'])
     self.assertNotIn('vcpu_weight', primitive['nova_object.data'])
     self.assertNotIn('disabled', primitive['nova_object.data'])
     self.assertNotIn('is_public', primitive['nova_object.data'])