Search in sources :

Example 16 with Vm

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

the class VmsServiceTest method testNullObjectForNonExistingID.

/**
 * Test we don get null VM object for non-existing VM id.
 */
@Test
public void testNullObjectForNonExistingID() {
    boolean raised = false;
    VmService vmService = vmsService.vmService("456");
    try {
        vmService.get().send().vm();
    } catch (Error e) {
        assertTrue(e.getMessage().contains("404"));
        raised = true;
    }
    assertTrue(raised);
}
Also used : VmService(org.ovirt.engine.sdk4.services.VmService) Test(org.junit.Test)

Example 17 with Vm

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

the class IscsiDiscoverTest method testActionParameters.

/**
 * Test we don't get null vm service for existing vm id and correct object
 */
@Test
public void testActionParameters() {
    HostsService hostsService = connection.systemService().hostsService();
    HostService hostService = hostsService.hostService("123");
    HostService.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("iscsi.example.com").port(3260)).send();
    assertEquals("<action>" + "<iscsi>" + "<address>iscsi.example.com</address>" + "<port>3260</port>" + "</iscsi>" + "</action>", getLastRequestContent());
    assertEquals("192.168.121.102", response.discoveredTargets().get(0).address());
    assertEquals(BigInteger.valueOf(3260), response.discoveredTargets().get(0).port());
    assertEquals("myiqn", response.iscsiTargets().get(0));
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) HostsService(org.ovirt.engine.sdk4.services.HostsService) Test(org.junit.Test)

Example 18 with Vm

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

the class ListVms 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 "list" method of the "vms" service to list all the virtual machines of the system:
    List<Vm> vms = vmsService.list().send().vms();
    // Print the virtual machine names and identifiers:
    for (Vm vm : vms) {
        System.out.printf("%s: %s\n", vm.name(), vm.id());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Example 19 with Vm

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

the class RemoveVm 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 service that manages VMs:
    VmsService vmsService = connection.systemService().vmsService();
    // Find the VM:
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Note that the "vm" variable that we assigned above contains only the data of the VM, it doesn't have any
    // method like "remove". Methods are defined in the services. So now that we have the description of the VM
    // we can find the service that manages it, calling the locator method "vmService" defined in the "vms"
    // service. This locator method receives as parameter the identifier of the VM and returns a reference to the
    // service that manages that VM.
    VmService vmService = vmsService.vmService(vm.id());
    // Now that we have the reference to the service that manages the VM we can use it to remove the VM. Note that
    // this method doesn't need any parameter, as the identifier of the VM is already known by the service that we
    // located in the previous step.
    vmService.remove().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)

Example 20 with Vm

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

the class SearchVms 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 "list" method of the "vms" service to search the virtual machines that match a search query:
    List<Vm> vms = vmsService.list().search("name=MYVM").caseSensitive(false).send().vms();
    // Print the virtual machine names and identifiers:
    for (Vm vm : vms) {
        System.out.printf("%s: %s", vm.name(), vm.id());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

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