'Adds and index a template into the `templates` container.
This implementation takes into account that a service has two naming
attribute: `host_name` and `service_description`.
:param tpl: The template to add'

def add_template(self, tpl):

    objcls = self.inner_class.my_type
    name = getattr(tpl, 'name', '')
    hname = getattr(tpl, 'host_name', '')
    if ((not name) and (not hname)):
        mesg = ('a    %s    template    has    been    defined    without    name    nor    host_name%s' % (objcls, self.get_source(tpl)))
        tpl.configuration_errors.append(mesg)
    elif name:
        tpl = self.index_template(tpl)
    self.templates[tpl.id] = tpl
