use of org.ovirt.engine.sdk4.types.Template in project ovirt-engine-sdk-java by oVirt.
the class AddTemplate method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the root of the services tree:
SystemService systemService = connection.systemService();
// Find the original virtual machine:
VmsService vmsService = systemService.vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Get the identifiers of the disks attached to the virtual machine. We # need this because we want to tell the
// server to create the disks of the template using a format different to the format used by the original disks.
List<String> diskIds = new ArrayList<>();
for (DiskAttachment attachment : connection.followLink(vm.diskAttachments())) {
diskIds.add(attachment.disk().id());
}
// Create a customized list of disk attachments, explicitly indicating that we want COW disks, regardless of
// format the original disks had:
List<DiskAttachment> attachments = new ArrayList<>();
for (String diskId : diskIds) {
attachments.add(diskAttachment().disk(disk().id(diskId).format(DiskFormat.COW)).build());
}
// Send the request to create the template. Note that the way to specify the original virtual machine, and the
// customizations, is to use the 'vm' attribute of the 'Template' type.
TemplatesService templatesService = systemService.templatesService();
Template template = templatesService.add().template(template().name("mytemplate").vm(vm().id(vm.id()).diskAttachments(attachments))).send().template();
// Wait till the status of the template is OK, as that means that it is completely created and ready to use:
TemplateService templateService = templatesService.templateService(template.id());
for (; ; ) {
Thread.sleep(5 * 1000);
template = templateService.get().send().template();
if (template.status() == TemplateStatus.OK) {
break;
}
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.Template in project ovirt-engine-sdk-java by oVirt.
the class AddVm method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "vms" service:
VmsService vmsService = connection.systemService().vmsService();
// Use the "add" method to create a new virtual machine:
vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().name("Blank"))).send();
// Close the connection to the server:
connection.close();
}
Aggregations