Search in sources :

Example 11 with Action

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

the class StopVm 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);
    // Locate the service that manages the virtual machine, as that is where the action methods are defined:
    VmService vmService = vmsService.vmService(vm.id());
    // Call the "stop" method of the service to stop it:
    vmService.stop().send();
    // What till the virtual machine is down:
    for (; ; ) {
        Thread.sleep(5 * 1000);
        vm = vmService.get().send().vm();
        if (vm.status() == VmStatus.DOWN) {
            break;
        }
    }
    // 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)

Aggregations

Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 XmlReader (org.ovirt.api.metamodel.runtime.xml.XmlReader)4 Connection (org.ovirt.engine.sdk4.Connection)4 VmService (org.ovirt.engine.sdk4.services.VmService)4 Action (org.ovirt.engine.sdk4.types.Action)4 Vm (org.ovirt.engine.sdk4.types.Vm)3 HostService (org.ovirt.engine.sdk4.services.HostService)2 HostsService (org.ovirt.engine.sdk4.services.HostsService)2 VmsService (org.ovirt.engine.sdk4.services.VmsService)2 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)1 StorageDomainVmService (org.ovirt.engine.sdk4.services.StorageDomainVmService)1 StorageDomainVmsService (org.ovirt.engine.sdk4.services.StorageDomainVmsService)1 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)1 Host (org.ovirt.engine.sdk4.types.Host)1 IscsiDetails (org.ovirt.engine.sdk4.types.IscsiDetails)1 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)1