Skip to content

2.7 Searching templates

jwebs1 edited this page Jul 6, 2015 · 2 revisions

Searching templates

This section contains examples of template search queries that use various parameters, such as data center, OS type, version, architecture, name, description, etc.

TemplateMetadata metadata = 
    templateService
        .findByRef(
            Template.refByOs()
                .dataCenter(US_EAST_STERLING)
                .type(RHEL)
                .version("6")
                .architecture(x86_64)
        );

TemplateMetadata metadata = 
    templateService
        .findByRef(
            Template.refByName()
                .dataCenter(US_EAST_STERLING)
                .name("CENTOS-6-64-TEMPLATE")
        );

TemplateMetadata metadata = 
    templateService
        .findByRef(
            Template.refByDescription()
                .dataCenter(US_EAST_STERLING)
                .description("pxe boot")
        );

List<TemplateMetadata> results = 
    templateService
        .find(
            new TemplateFilter()
                .dataCenters(US_EAST_STERLING)
                .osTypes(
                    new OsFilter()
                        .type(CENTOS)
            )
        );
        
List<TemplateMetadata> results = 
    templateService
        .find(
            new TemplateFilter()
                .dataCenters(US_EAST_STERLING)
                .where(
                    t -> t.getCapabilities().contains(MANAGED_OS_VALUE)
                )
        );

Note that the Template reference and TemplateFilter can be used as search criteria.