Search in sources :

Example 6 with Host

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

the class PinVm 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 tree of services:
    SystemService systemService = connection.systemService();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Update the placement policy of the virtual machine so that it is pinned to the host:
    VmService vmService = vmsService.vmService(vm.id());
    vmService.update().vm(vm().placementPolicy(vmPlacementPolicy().hosts(host().name("myhost")))).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 7 with Host

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

the class RemoveHost 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 hosts:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Find the service that manages the host:
    HostService hostService = hostsService.hostService(host.id());
    // If the host isn't down or in maintenance then move it to maintenance:
    if (host.status() != HostStatus.MAINTENANCE) {
        hostService.deactivate().send();
    }
    // Remove the host:
    hostService.remove().send();
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 8 with Host

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

the class ListHostStatistics 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 host:
    HostsService hostsService = connection.systemService().hostsService();
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Follow the link to the statistics and print their names and values:
    List<Statistic> stats = connection.followLink(host.statistics());
    for (Statistic stat : stats) {
        System.out.printf("%s: %s\n", stat.name(), stat.values().get(0).datum());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Statistic(org.ovirt.engine.sdk4.types.Statistic) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 9 with Host

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

the class AddNfsIsoStorageDomain 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 storage domains service:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    // Create a new NFS storage domain:
    StorageDomain sd = sdsService.add().storageDomain(storageDomain().name("myiso").description("My ISO").type(StorageDomainType.ISO).host(host().name("myhost")).storage(hostStorage().type(StorageType.NFS).address("server0.example.com").path("/nfs/ovirt/40/myiso"))).send().storageDomain();
    // Wait till the storage domain is unattached:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = sdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.UNATTACHED) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Connection(org.ovirt.engine.sdk4.Connection)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)9 HostsService (org.ovirt.engine.sdk4.services.HostsService)6 Host (org.ovirt.engine.sdk4.types.Host)6 HostService (org.ovirt.engine.sdk4.services.HostService)5 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)2 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)2 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)2 ArrayList (java.util.ArrayList)1 FenceAgentService (org.ovirt.engine.sdk4.services.FenceAgentService)1 FenceAgentsService (org.ovirt.engine.sdk4.services.FenceAgentsService)1 SystemService (org.ovirt.engine.sdk4.services.SystemService)1 VmService (org.ovirt.engine.sdk4.services.VmService)1 VmsService (org.ovirt.engine.sdk4.services.VmsService)1 Agent (org.ovirt.engine.sdk4.types.Agent)1 IscsiDetails (org.ovirt.engine.sdk4.types.IscsiDetails)1 Option (org.ovirt.engine.sdk4.types.Option)1 Statistic (org.ovirt.engine.sdk4.types.Statistic)1 Vm (org.ovirt.engine.sdk4.types.Vm)1