code: def _sort_resources_per_hosting_device(resources):
          
          hosting_devices = {}
          for key in resources.keys():
              for r in resources.get(key) or []:
                  if r.get('hosting_device') is None:
                      continue
                  hd_id = r['hosting_device']['id']
                  hosting_devices.setdefault(hd_id, {})
                  hosting_devices[hd_id].setdefault(key, []).append(r)
          return hosting_devices
docs: This function will sort the resources on hosting device.
  
          The sorting on hosting device is done by looking up the
          `hosting_device` attribute of the resource, and its `id`.
  
          :param resources: a dict with key of resource name
          :return dict sorted on the hosting device of input resource. Format:
          hosting_devices = {
                              'hd_id1' : {'routers':[routers],
                                          'removed_routers':[routers], .... }
                              'hd_id2' : {'routers':[routers], .. }
                              .......
                              }