nodes: 0, module; 1, function_definition; 2, function_name:_sort_resources_per_hosting_device; 3, parameters; 4, block; 5, identifier:resources; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:"""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], .. }
                              .......
                              }
          """; 11, assignment; 12, identifier:key; 13, call; 14, block; 15, identifier:hosting_devices; 16, identifier:hosting_devices; 17, dictionary; 18, attribute; 19, argument_list; 20, for_statement; 21, identifier:resources; 22, identifier:keys; 23, identifier:r; 24, boolean_operator; 25, block; 26, call; 27, list; 28, if_statement; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, attribute; 33, argument_list; 34, comparison_operator:r.get('hosting_device') is None; 35, block; 36, assignment; 37, call; 38, call; 39, identifier:resources; 40, identifier:get; 41, identifier:key; 42, call; 43, None; 44, continue_statement; 45, identifier:hd_id; 46, subscript; 47, attribute; 48, argument_list; 49, attribute; 50, argument_list; 51, attribute; 52, argument_list; 53, subscript; 54, string; 55, identifier:hosting_devices; 56, identifier:setdefault; 57, identifier:hd_id; 58, dictionary; 59, call; 60, identifier:append; 61, identifier:r; 62, identifier:r; 63, identifier:get; 64, string; 65, identifier:r; 66, string; 67, string_content:id; 68, attribute; 69, argument_list; 70, string_content:hosting_device; 71, string_content:hosting_device; 72, subscript; 73, identifier:setdefault; 74, identifier:key; 75, list; 76, identifier:hosting_devices; 77, identifier:hd_id
code: def _sort_resources_per_hosting_device(resources):
          """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], .. }
                              .......
                              }
          """
          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