use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class AddIndependentVm 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 "clone" parameter of the "add" method to request that the
// disks of the new virtual machine are independent of the template.
vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().name("mytemplate"))).clone_(true).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService 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.services.VmsService 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();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class AddVncConsole 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();
// Find the virtual machine:
VmsService vmsService = connection.systemService().vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
VmService vmService = vmsService.vmService(vm.id());
// Find the graphics consoles of the virtual machine:
VmGraphicsConsolesService consolesService = vmService.graphicsConsolesService();
List<GraphicsConsole> consoles = consolesService.list().send().consoles();
// Add a VNC console if it doesn't exist:
GraphicsConsole console = null;
for (GraphicsConsole c : consoles) {
if (c.protocol() == GraphicsType.VNC) {
console = c;
break;
}
}
if (console == null) {
consolesService.add().console(graphicsConsole().protocol(GraphicsType.VNC)).send();
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class AssignAffinityLabelToVm 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();
// Find the virtual machine:
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Get the reference to the affinity labels service:
AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService();
// Find the id of the affinity label:
String affinityLabelId = null;
for (AffinityLabel affinityLabel : affinityLabelsService.list().send().labels()) {
if (affinityLabel.name().equals("my_affinity_label")) {
affinityLabelId = affinityLabel.id();
break;
}
}
// Locate the service that manages the affinity label named `my_affinity_label`:
AffinityLabelService affinityLabelService = affinityLabelsService.labelService(affinityLabelId);
// Get the reference to the service that manages the set of virtual machines that have the affinity label
// named `my_affinity_label` assigned:
AffinityLabelVmsService affinityLabelVmsService = affinityLabelService.vmsService();
// Assign affinity label to virtual machine:
affinityLabelVmsService.add().vm(vm().id(vm.id())).send();
// Close the connection to the server:
connection.close();
}
Aggregations