docs: def set_network_template(template_id, network_id, **kwargs):
      """
         Apply an existing template to a network. Used when a template has changed, and additional attributes
         must be added to the network's elements.
      """
  
      resource_types = []
  
      #There should only ever be one matching type, but if there are more,
      #all we can do is pick the first one.
      try:
          network_type = db.DBSession.query(ResourceType).filter(ResourceType.ref_key=='NETWORK',
                                                              ResourceType.network_id==network_id,
                                                              ResourceType.type_id==TemplateType.type_id,
                                                              TemplateType.template_id==template_id).one()
          resource_types.append(network_type)
  
      except NoResultFound:
          log.debug("No network type to set.")
          pass
  
      node_types = db.DBSession.query(ResourceType).filter(ResourceType.ref_key=='NODE',
                                                          ResourceType.node_id==Node.node_id,
                                                          Node.network_id==network_id,
                                                          ResourceType.type_id==TemplateType.type_id,
                                                          TemplateType.template_id==template_id).all()
      link_types = db.DBSession.query(ResourceType).filter(ResourceType.ref_key=='LINK',
                                                          ResourceType.link_id==Link.link_id,
                                                          Link.network_id==network_id,
                                                          ResourceType.type_id==TemplateType.type_id,
                                                          TemplateType.template_id==template_id).all()
      group_types = db.DBSession.query(ResourceType).filter(ResourceType.ref_key=='GROUP',
                                                          ResourceType.group_id==ResourceGroup.group_id,
                                                          ResourceGroup.network_id==network_id,
                                                          ResourceType.type_id==TemplateType.type_id,
                                                          TemplateType.template_id==template_id).all()
  
      resource_types.extend(node_types)
      resource_types.extend(link_types)
      resource_types.extend(group_types)
  
      assign_types_to_resources(resource_types)
  
      log.debug("Finished setting network template")