Пример #1
0
    def notification_callback(self, event_type, payload):
        """Handle a notification message.

        It is used as a callback of a notification-based resource monitor.

        :param event_type: an event type of a notification.
        :param payload: a payload of a notification.
        :return: a dictionary of {reservation id: flags to update}
                 e.g. {'de27786d-bd96-46bb-8363-19c13b2c6657':
                       {'missing_resources': True}}
        """
        LOG.trace('Handling a notification...')
        reservation_flags = {}

        data = payload.get('nova_object.data', None)
        if data:
            if data['disabled'] or data['forced_down']:
                failed_hosts = db_api.reservable_host_get_all_by_queries(
                    ['hypervisor_hostname == ' + data['host']])
                if failed_hosts:
                    LOG.warn('%s failed.',
                             failed_hosts[0]['hypervisor_hostname'])
                    reservation_flags = self._handle_failures(failed_hosts)
            else:
                recovered_hosts = db_api.host_get_all_by_queries(
                    ['reservable == 0',
                     'hypervisor_hostname == ' + data['host']])
                if recovered_hosts:
                    db_api.host_update(recovered_hosts[0]['id'],
                                       {'reservable': True})
                    LOG.warn('%s recovered.',
                             recovered_hosts[0]['hypervisor_hostname'])

        return reservation_flags
Пример #2
0
 def _filter_hosts_by_properties(self, hypervisor_properties,
                                 resource_properties):
     filter = []
     if hypervisor_properties:
         filter += plugins_utils.convert_requirements(hypervisor_properties)
     if resource_properties:
         filter += plugins_utils.convert_requirements(resource_properties)
     if filter:
         return db_api.host_get_all_by_queries(filter)
     else:
         return db_api.host_list()