def materialize_owners(devices_id): """Re-computes 'owners' for the given devices and components.""" # First let's erase all owners DeviceDomain.update_many_raw({'_id': { '$in': devices_id }}, {'$set': { 'owners': [] }}) # Then let's execute again the materialize hooks for Allocate/Deallocate query = { '$or': [{ '@type': 'devices:Allocate' }, { '@type': 'devices:Deallocate' }], 'devices': { '$in': devices_id } } order_by = {'_created': pymongo.ASCENDING} for event in DeviceEventDomain.get({ '$query': query, '$orderby': order_by }): if event['@type'] == 'devices:Allocate': materialize_actual_owners_add([event]) else: modified = materialize_actual_owners_remove([event]) if modified == 0: # This Remove does nothing and should be erased DeviceEventDomain.delete({'_id': event['_id']})
def execute(self, database): DeviceDomain.update_many_raw({}, {'$set': {'events': []}}) for event in DeviceEventDomain.get({ '$query': {}, '$orderby': { '_created': pymongo.ASCENDING } }): MaterializeEvents.materialize_events( Naming.resource(event['@type']), [event])
def re_materialize_events(): DeviceDomain.update_many_raw({}, {'$set': {'events': []}}) for event in DeviceEventDomain.get({ '$query': {}, '$orderby': { '_created': pymongo.ASCENDING } }): MaterializeEvents.materialize_events( Naming.resource(event['@type']), [event]) print('Events re-materialized.')
def materialize_owners(devices_id): """Re-computes 'owners' for the given devices and components.""" # First let's erase all owners DeviceDomain.update_many_raw({'_id': {'$in': devices_id}}, {'$set': {'owners': []}}) # Then let's execute again the materialize hooks for Allocate/Deallocate query = {'$or': [{'@type': 'devices:Allocate'}, {'@type': 'devices:Deallocate'}], 'devices': {'$in': devices_id}} order_by = {'_created': pymongo.ASCENDING} for event in DeviceEventDomain.get({'$query': query, '$orderby': order_by}): if event['@type'] == 'devices:Allocate': materialize_actual_owners_add([event]) else: modified = materialize_actual_owners_remove([event]) if modified == 0: # This Remove does nothing and should be erased DeviceEventDomain.delete({'_id': event['_id']})
def re_materialize_events(): DeviceDomain.update_many_raw({}, {'$set': {'events': []}}) for event in DeviceEventDomain.get({'$query': {}, '$orderby': {'_created': pymongo.ASCENDING}}): MaterializeEvents.materialize_events(Naming.resource(event['@type']), [event]) print('Events re-materialized.')