Source:
public static void main ( java.lang.String [ ] args ) throws java.lang.Exception { org.ovirt.engine.sdk4.Connection connection = org.ovirt.engine.sdk4.ConnectionBuilder.connection ( ) . url ( "https://engine40.example.com/ovirt-engine/api" ) . user ( "admin@internal" ) . password ( "redhat123" ) . trustStoreFile ( "truststore.jks" ) . build ( ) ; org.ovirt.engine.sdk4.services.SystemService systemService = connection.systemService ( ) ; org.ovirt.engine.sdk4.services.TemplatesService templatesService = systemService.templatesService ( ) ; java.util.List < org.ovirt.engine.sdk4.types.Template > templates = templatesService.list ( ) . search ( "name=mytemplate" ) . send ( ) . templates ( ) ; java.lang.String templateId = null ; for ( org.ovirt.engine.sdk4.types.Template template : templates ) { if ( template.version ( ) . versionNumber ( ) . equals ( java.math.BigInteger.valueOf ( 3 ) ) ) { templateId = template.id ( ) ; break ; } } org.ovirt.engine.sdk4.services.VmsService vmsService = connection.systemService ( ) . vmsService ( ) ; vmsService.add ( ) . vm ( org.ovirt.engine.sdk4.builders.Builders.vm ( ) . name ( "myvm" ) . cluster ( org.ovirt.engine.sdk4.builders.Builders.cluster ( ) . name ( "mycluster" ) ) . template ( org.ovirt.engine.sdk4.builders.Builders.template ( ) . id ( templateId ) ) ) . send ( ) ; connection.close ( ) ; }

Target:
public static void main ( java.lang.String [ ] args ) throws java.lang.Exception { org.ovirt.engine.sdk4.Connection connection = org.ovirt.engine.sdk4.ConnectionBuilder.connection ( ) . url ( "https://engine40.example.com/ovirt-engine/api" ) . user ( "admin@internal" ) . password ( "redhat123" ) . trustStoreFile ( "truststore.jks" ) . build ( ) ; org.ovirt.engine.sdk4.services.SystemService systemService = connection.systemService ( ) ; org.ovirt.engine.sdk4.services.StorageDomainsService storageDomainsService = systemService.storageDomainsService ( ) ; org.ovirt.engine.sdk4.types.StorageDomain storageDomain = storageDomainsService.list ( ) . search ( "name=mydata" ) . send ( ) . storageDomains ( ) . get ( 0 ) ; org.ovirt.engine.sdk4.services.TemplatesService templatesService = systemService.templatesService ( ) ; java.util.List < org.ovirt.engine.sdk4.types.Template > templates = templatesService.list ( ) . search ( "name=mytemplate" ) . send ( ) . templates ( ) ; java.lang.String templateId = null ; for ( org.ovirt.engine.sdk4.types.Template template : templates ) { if ( template.version ( ) . versionNumber ( ) . equals ( java.math.BigInteger.valueOf ( 3 ) ) ) { templateId = template.id ( ) ; break ; } } org.ovirt.engine.sdk4.services.TemplateService templateService = templatesService.templateService ( templateId ) ; java.util.List < org.ovirt.engine.sdk4.types.DiskAttachment > diskAttachments = connection.followLink ( templateService.get ( ) . send ( ) . template ( ) . diskAttachments ( ) ) ; org.ovirt.engine.sdk4.types.Disk disk = diskAttachments.get ( 0 ) . disk ( ) ; org.ovirt.engine.sdk4.services.VmsService vmsService = connection.systemService ( ) . vmsService ( ) ; vmsService.add ( ) . vm ( org.ovirt.engine.sdk4.builders.Builders.vm ( ) . name ( "myvm" ) . cluster ( org.ovirt.engine.sdk4.builders.Builders.cluster ( ) . name ( "mycluster" ) ) . template ( org.ovirt.engine.sdk4.builders.Builders.template ( ) . id ( templateId ) ) . diskAttachments ( org.ovirt.engine.sdk4.builders.Builders.diskAttachment ( ) . disk ( org.ovirt.engine.sdk4.builders.Builders.disk ( ) . id ( disk.id ( ) ) . format ( DiskFormat.COW ) . storageDomains ( org.ovirt.engine.sdk4.builders.Builders.storageDomain ( ) . id ( storageDomain.id ( ) ) ) ) ) ) . send ( ) ; connection.close ( ) ; }