code: def linkify_h_by_hg(self, hostgroups):
          
          # Register host in the hostgroups
          for host in self:
              new_hostgroups = []
              if hasattr(host, 'hostgroups') and host.hostgroups != []:
                  hgs = [n.strip() for n in host.hostgroups if n.strip()]
                  for hg_name in hgs:
                      # TODO: should an unknown hostgroup raise an error ?
                      hostgroup = hostgroups.find_by_name(hg_name)
                      if hostgroup is not None:
                          new_hostgroups.append(hostgroup.uuid)
                      else:
                          err = ("the hostgroup '%s' of the host '%s' is "
                                 "unknown" % (hg_name, host.host_name))
                          host.add_error(err)
              host.hostgroups = new_hostgroups
docs: Link hosts with hostgroups
  
          :param hostgroups: hostgroups object to link with
          :type hostgroups: alignak.objects.hostgroup.Hostgroups
          :return: None