Search in sources :

Example 26 with Vm

use of org.ovirt.engine.sdk4.types.Vm in project ovirt-engine-sdk-java by oVirt.

the class AssignTagToVm 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=myvm0").send().vms().get(0);
    // Find the service that manages the vm:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the tags of the vm:
    AssignedTagsService assignedTagsService = vmService.tagsService();
    // Assign tag to virtual machine:
    assignedTagsService.add().tag(tag().name("mytag")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : 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) AssignedTagsService(org.ovirt.engine.sdk4.services.AssignedTagsService)

Example 27 with Vm

use of org.ovirt.engine.sdk4.types.Vm in project ovirt-engine-sdk-java by oVirt.

the class FollowVmLinks 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 service that manages virtual machines:
    VmsService vmsService = connection.systemService().vmsService();
    // Find the virtual machine:
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // When the server returns a virtual machine it will return links to related objects, like the cluster,
    // template and permissions something like this:
    // 
    // <link href="/api/vms/123/permissions" rel="permissions"/>
    // ...
    // <cluster id="123" href="/api/clusters/123"/>
    // <template id="456" href="/api/templates/456"/>
    // 
    // The SDK provides a "followLink" method that can be used to retrieve the complete content of these related
    // objects.
    Cluster cluster = connection.followLink(vm.cluster());
    Template template = connection.followLink(vm.template());
    List<Permission> permissions = connection.followLink(vm.permissions());
    // Now we can use the details of the cluster, template and permissions:
    System.out.printf("cluster: %s\n", cluster.name());
    System.out.printf("template: %s\n", template.name());
    for (Permission permission : permissions) {
        System.out.printf("role: %s\n", permission.role().id());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) Permission(org.ovirt.engine.sdk4.types.Permission) Cluster(org.ovirt.engine.sdk4.types.Cluster) VmsService(org.ovirt.engine.sdk4.services.VmsService) Template(org.ovirt.engine.sdk4.types.Template)

Example 28 with Vm

use of org.ovirt.engine.sdk4.types.Vm in project ovirt-engine-sdk-java by oVirt.

the class ExportVm 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 virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Export the virtual machine. Note that the 'exclusive' parameter is optional, and only required if you want
    // to overwrite a virtual machine that has already been exported before.
    VmService vmService = vmsService.vmService(vm.id());
    vmService.export().exclusive(true).discardSnapshots(true).storageDomain(storageDomain().name("myexport")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : SystemService(org.ovirt.engine.sdk4.services.SystemService) 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)

Example 29 with Vm

use of org.ovirt.engine.sdk4.types.Vm in project ovirt-engine-sdk-java by oVirt.

the class ResponseCodeTest method test202codeDontThrowException.

/**
 * Test when server return response with 202 code,
 * the SDK don't raise exception.
 */
@Test
public void test202codeDontThrowException() throws Exception {
    setXmlResponse("vms", 202, "<vms/>");
    startServer();
    Connection connection = testConnection();
    VmsService vmsService = connection.systemService().vmsService();
    vmsService.add().vm(vm()).send();
    connection.close();
    stopServer();
}
Also used : VmsService(org.ovirt.engine.sdk4.services.VmsService) Test(org.junit.Test)

Example 30 with Vm

use of org.ovirt.engine.sdk4.types.Vm in project ovirt-engine-sdk-java by oVirt.

the class ResponseCodeTest method test201codeDontThrowException.

/**
 * Test when server return response with 201 code,
 * the SDK don't raise exception.
 */
@Test
public void test201codeDontThrowException() throws Exception {
    setXmlResponse("vms", 201, "<vms/>");
    startServer();
    Connection connection = testConnection();
    VmsService vmsService = connection.systemService().vmsService();
    vmsService.add().vm(vm()).send();
    connection.close();
    stopServer();
}
Also used : VmsService(org.ovirt.engine.sdk4.services.VmsService) Test(org.junit.Test)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)34 VmsService (org.ovirt.engine.sdk4.services.VmsService)34 Vm (org.ovirt.engine.sdk4.types.Vm)32 VmService (org.ovirt.engine.sdk4.services.VmService)21 Test (org.junit.Test)8 SystemService (org.ovirt.engine.sdk4.services.SystemService)8 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)6 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)5 Disk (org.ovirt.engine.sdk4.types.Disk)5 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)5 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)4 SnapshotsService (org.ovirt.engine.sdk4.services.SnapshotsService)4 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 VmContainer (org.ovirt.engine.sdk4.internal.containers.VmContainer)2 AffinityLabelsService (org.ovirt.engine.sdk4.services.AffinityLabelsService)2 SnapshotDisksService (org.ovirt.engine.sdk4.services.SnapshotDisksService)2 SnapshotService (org.ovirt.engine.sdk4.services.SnapshotService)2