示例#1
0
 def execute(self, database):
     SNAPSHOT_SOFTWARE = {
         'DDI': 'Workbench',
         'Scan': 'AndroidApp',
         'DeviceHubClient': 'Web'
     }
     for snapshot in DeviceEventDomain.get({'@type': "devices:Snapshot"}):
         with suppress(KeyError):
             snapshot['snapshotSoftware'] = SNAPSHOT_SOFTWARE[snapshot.get(
                 'snapshotSoftware', 'DDI')]
         DeviceEventDomain.update_one_raw(
             snapshot['_id'],
             {'$set': {
                 'snapshotSoftware': snapshot['snapshotSoftware']
             }})
         for device in DeviceDomain.get({'events._id': snapshot['_id']}):
             materialized_snapshot = find(
                 device['events'],
                 lambda event: event['_id'] == snapshot['_id'])
             materialized_snapshot['snapshotSoftware'] = snapshot[
                 'snapshotSoftware']
             DeviceDomain.update_one_raw(
                 device['_id'], {'$set': {
                     'events': device['events']
                 }})
示例#2
0
def submit_migrate(migrates: dict):
    """
    Sends a Migrate event to the other DeviceHub.
    Note as the other DeviceHub requires the url of this event,
    this method needs to be executed after reaching the Database.
    """
    for migrate in migrates:
        if 'to' in migrate:
            auth = AgentAuth(migrate['to']['baseUrl'])
            submitter = MigrateSubmitter(current_app, MigrateTranslator(current_app.config), auth=auth)
            try:
                response, *_ = submitter.submit(migrate, AccountDomain.get_requested_database())
                migrate['to']['url'] = migrate['to']['baseUrl'] + response['_links']['self']['href']
                _update_same_as(response['returnedSameAs'])
            except InnerRequestError as e:
                execute_delete(Migrate.resource_name, migrate['_id'])
                raise e
            else:
                _remove_devices_from_places(migrate)
                update = {'$set': {'to.url': migrate['to']['url'], 'devices': [_id for _id in migrate['devices']]}}
                DeviceEventDomain.update_one_raw(migrate['_id'], update)
示例#3
0
文件: hooks.py 项目: eReuse/DeviceHub
def submit_migrate(migrates: dict):
    """
    Sends a Migrate event to the other DeviceHub.
    Note as the other DeviceHub requires the url of this event,
    this method needs to be executed after reaching the Database.
    """
    for migrate in migrates:
        if 'to' in migrate:
            auth = AgentAuth(migrate['to']['baseUrl'])
            submitter = MigrateSubmitter(current_app, MigrateTranslator(current_app.config), auth=auth)
            try:
                response, *_ = submitter.submit(migrate, AccountDomain.get_requested_database())
                migrate['to']['url'] = migrate['to']['baseUrl'] + response['_links']['self']['href']
                _update_same_as(response['returnedSameAs'])
            except InnerRequestError as e:
                execute_delete(Migrate.resource_name, migrate['_id'])
                raise e
            else:
                _remove_devices_from_places(migrate)
                update = {'$set': {'to.url': migrate['to']['url'], 'devices': [_id for _id in migrate['devices']]}}
                DeviceEventDomain.update_one_raw(migrate['_id'], update)