Search in sources :

Example 31 with VmsService

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();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Example 32 with VmsService

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();
}
Also used : SystemService(org.ovirt.engine.sdk4.services.SystemService) DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) ArrayList(java.util.ArrayList) VmsService(org.ovirt.engine.sdk4.services.VmsService) TemplateService(org.ovirt.engine.sdk4.services.TemplateService) TemplatesService(org.ovirt.engine.sdk4.services.TemplatesService) Template(org.ovirt.engine.sdk4.types.Template)

Example 33 with VmsService

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();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Example 34 with VmsService

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();
}
Also used : VmGraphicsConsolesService(org.ovirt.engine.sdk4.services.VmGraphicsConsolesService) Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) GraphicsConsole(org.ovirt.engine.sdk4.types.GraphicsConsole)

Example 35 with VmsService

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();
}
Also used : AffinityLabelsService(org.ovirt.engine.sdk4.services.AffinityLabelsService) AffinityLabel(org.ovirt.engine.sdk4.types.AffinityLabel) AffinityLabelService(org.ovirt.engine.sdk4.services.AffinityLabelService) AffinityLabelVmsService(org.ovirt.engine.sdk4.services.AffinityLabelVmsService) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) AffinityLabelVmsService(org.ovirt.engine.sdk4.services.AffinityLabelVmsService) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Aggregations

VmsService (org.ovirt.engine.sdk4.services.VmsService)34 Connection (org.ovirt.engine.sdk4.Connection)31 Vm (org.ovirt.engine.sdk4.types.Vm)29 VmService (org.ovirt.engine.sdk4.services.VmService)19 SystemService (org.ovirt.engine.sdk4.services.SystemService)8 Disk (org.ovirt.engine.sdk4.types.Disk)5 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)5 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)4 SnapshotsService (org.ovirt.engine.sdk4.services.SnapshotsService)4 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)4 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)4 Test (org.junit.Test)3 AssignedTagsService (org.ovirt.engine.sdk4.services.AssignedTagsService)3 Snapshot (org.ovirt.engine.sdk4.types.Snapshot)3 Template (org.ovirt.engine.sdk4.types.Template)3 ArrayList (java.util.ArrayList)2 SnapshotDisksService (org.ovirt.engine.sdk4.services.SnapshotDisksService)2 SnapshotService (org.ovirt.engine.sdk4.services.SnapshotService)2 TemplateService (org.ovirt.engine.sdk4.services.TemplateService)2 TemplatesService (org.ovirt.engine.sdk4.services.TemplatesService)2