'Generate a service configuration'

def get_services_templates(self):

    def _create_service(name, service):
        template = CommentedMap()
        state = service.get(self.CONFIG_KEY, {}).get('state', 'present')
        if (state == 'present'):
            ports = self.get_service_ports(service)
            if ports:
                template['apiVersion'] = self.DEFAULT_API_VERSION
                template['kind'] = 'Service'
                template['force'] = service.get(self.CONFIG_KEY, {}).get('service', {}).get('force', False)
                labels = CommentedMap([('app', self._namespace_name), ('service', name)])
                template['metadata'] = CommentedMap([('name', name), ('namespace', self._namespace_name), ('labels', copy.deepcopy(labels))])
                template['spec'] = CommentedMap([('selector', copy.deepcopy(labels)), ('ports', ports)])
                if service.get(self.CONFIG_KEY):
                    for (key, value) in service[self.CONFIG_KEY].items():
                        if (key == 'service'):
                            for (service_key, service_value) in value.items():
                                if (service_key == 'force'):
                                    continue
                                elif (service_key == 'metadata'):
                                    self.copy_attribute(template, service_key, service_value)
                                else:
                                    self.copy_attribute(template['spec'], service_key, service_value)
        return template
    templates = CommentedSeq()
    if self._services:
        for (name, service) in self._services.items():
            template = _create_service(name, service)
            if template:
                templates.append(template)
            if service.get('links'):
                for link in service['links']:
                    if (':' in link):
                        (service_name, alias) = link.split(':')
                        alias_config = self._services.get(service_name)
                        if alias_config:
                            new_service = _create_service(alias, alias_config)
                            if new_service:
                                templates.append(new_service)
    return templates
