Exemplo n.º 1
0
 def _exec_event(self, event):
     """Execute an event function"""
     event_fn = getattr(self, event['event_type'], None)
     if event_fn is None:
         raise exceptions.EventError(
             error='Event type %s is not supported'
                   % event['event_type'])
     try:
         event_fn(lease_id=event['lease_id'], event_id=event['id'])
     except common_ex.InvalidStatus:
         now = datetime.datetime.utcnow()
         if now < event['time'] + datetime.timedelta(
                 seconds=CONF.manager.event_max_retries * 10):
             # Set the event status UNDONE for retrying the event
             db_api.event_update(event['id'],
                                 {'status': status.event.UNDONE})
         else:
             db_api.event_update(event['id'],
                                 {'status': status.event.ERROR})
             LOG.exception('Error occurred while handling %s event for '
                           'lease %s.', event['event_type'],
                           event['lease_id'])
     except Exception:
         db_api.event_update(event['id'],
                             {'status': status.event.ERROR})
         LOG.exception('Error occurred while handling %s event for '
                       'lease %s.', event['event_type'], event['lease_id'])
     else:
         lease = db_api.lease_get(event['lease_id'])
         with trusts.create_ctx_from_trust(lease['trust_id']) as ctx:
             self._send_notification(
                 lease, ctx, events=['event.%s' % event['event_type']])
Exemplo n.º 2
0
    def on_start(self, resource_id):
        ctx = context.current()
        instance_reservation = db_api.instance_reservation_get(resource_id)
        reservation_id = instance_reservation['reservation_id']

        try:
            self.nova.flavor_access.add_tenant_access(reservation_id,
                                                      ctx.project_id)
        except nova_exceptions.ClientException:
            LOG.info(
                'Failed to associate flavor %(reservation_id)s '
                'to project %(project_id)s', {
                    'reservation_id': reservation_id,
                    'project_id': ctx.project_id
                })
            raise mgr_exceptions.EventError()

        pool = nova.ReservationPool()

        # Dict of number of instances to reserve on a host keyed by the
        # host id
        allocation_map = collections.defaultdict(lambda: 0)
        for allocation in db_api.host_allocation_get_all_by_values(
                reservation_id=reservation_id):
            host_id = allocation['compute_host_id']
            allocation_map[host_id] += 1

        for host_id, num in allocation_map.items():
            host = db_api.host_get(host_id)
            pool.add_computehost(instance_reservation['aggregate_id'],
                                 host['service_name'],
                                 stay_in=True)
            self.placement_client.update_reservation_inventory(
                host['hypervisor_hostname'], reservation_id, num)
Exemplo n.º 3
0
    def on_start(self, resource_id):
        ctx = context.current()
        instance_reservation = db_api.instance_reservation_get(resource_id)
        reservation_id = instance_reservation['reservation_id']

        try:
            self.nova.flavor_access.add_tenant_access(reservation_id,
                                                      ctx.project_id)
        except nova_exceptions.ClientException:
            LOG.info('Failed to associate flavor %(reservation_id)s '
                     'to project %(project_id)s',
                     {'reservation_id': reservation_id,
                      'project_id': ctx.project_id})
            raise mgr_exceptions.EventError()

        pool = nova.ReservationPool()
        for allocation in db_api.host_allocation_get_all_by_values(
                reservation_id=reservation_id):
            host = db_api.host_get(allocation['compute_host_id'])
            pool.add_computehost(instance_reservation['aggregate_id'],
                                 host['service_name'], stay_in=True)