Search in sources :

Example 56 with User

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

the class ListVmSnapshots 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 service:
    SystemService systemService = connection.systemService();
    // Find all the virtual machines and store the id and name in a
    // map, so that looking them up later will be faster:
    VmsService vmsService = systemService.vmsService();
    Map<String, String> vmsMap = new HashMap<>();
    for (Vm vm : vmsService.list().send().vms()) {
        vmsMap.put(vm.id(), vm.name());
    }
    // Same for storage domains:
    StorageDomainsService storageDomainsService = systemService.storageDomainsService();
    Map<String, String> storageDomainsMap = new HashMap<>();
    for (StorageDomain sd : storageDomainsService.list().send().storageDomains()) {
        storageDomainsMap.put(sd.id(), sd.name());
    }
    // find its disks:
    for (Map.Entry<String, String> vm : vmsMap.entrySet()) {
        VmService vmService = vmsService.vmService(vm.getKey());
        SnapshotsService snapshotsService = vmService.snapshotsService();
        Map<String, String> snapshotsMap = new HashMap<>();
        for (Snapshot snapshot : snapshotsService.list().send().snapshots()) {
            snapshotsMap.put(snapshot.id(), snapshot.description());
        }
        for (Map.Entry<String, String> snapshot : snapshotsMap.entrySet()) {
            SnapshotService snapshotService = snapshotsService.snapshotService(snapshot.getKey());
            SnapshotDisksService snapshotDisksService = snapshotService.disksService();
            for (Disk disk : snapshotDisksService.list().send().disks()) {
                if (disk.storageDomains().size() > 0) {
                    String storageDomainId = disk.storageDomains().get(0).id();
                    String storageDomainName = storageDomainsMap.get(storageDomainId);
                    System.out.printf("%s:%s:%s:%s\n", vm.getValue(), snapshot.getValue(), disk.alias(), storageDomainName);
                }
            }
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : SnapshotService(org.ovirt.engine.sdk4.services.SnapshotService) SnapshotsService(org.ovirt.engine.sdk4.services.SnapshotsService) HashMap(java.util.HashMap) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) Snapshot(org.ovirt.engine.sdk4.types.Snapshot) SnapshotDisksService(org.ovirt.engine.sdk4.services.SnapshotDisksService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) Vm(org.ovirt.engine.sdk4.types.Vm) HashMap(java.util.HashMap) Map(java.util.Map) Disk(org.ovirt.engine.sdk4.types.Disk)

Example 57 with User

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

the class ListVmTags 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 tagsService = vmService.tagsService();
    // For each tag print its name and description:
    for (Tag tag : tagsService.list().send().tags()) {
        System.out.printf("%s: %s\n", tag.name(), tag.description());
    }
    // 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) Tag(org.ovirt.engine.sdk4.types.Tag) AssignedTagsService(org.ovirt.engine.sdk4.services.AssignedTagsService)

Example 58 with User

use of org.ovirt.engine.sdk4.types.User 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 59 with User

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

the class AddInstanceType 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 instance types service:
    InstanceTypesService instanceTypesService = connection.systemService().instanceTypesService();
    // Add the instance type. Note that the size of the memory, the `memory`
    // attribute, is specified in bytes, so to create a instance type with
    // 2 GiB of memory the value should be 2 * 2^30.
    instanceTypesService.add().instanceType(instanceType().name("myinstancetype").description("My instance type").memory(BigInteger.valueOf(2).multiply(BigInteger.valueOf(2).pow(30))).highAvailability(highAvailability().enabled(true)).cpu(cpu().topology(cpuTopology().cores(2).sockets(2)))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) InstanceTypesService(org.ovirt.engine.sdk4.services.InstanceTypesService)

Example 60 with User

use of org.ovirt.engine.sdk4.types.User 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)63 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 VmService (org.ovirt.engine.sdk4.services.VmService)18 SystemService (org.ovirt.engine.sdk4.services.SystemService)13 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 HostsService (org.ovirt.engine.sdk4.services.HostsService)6 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)6 Host (org.ovirt.engine.sdk4.types.Host)6 DataCentersService (org.ovirt.engine.sdk4.services.DataCentersService)5 HostService (org.ovirt.engine.sdk4.services.HostService)5 Disk (org.ovirt.engine.sdk4.types.Disk)5 ClustersService (org.ovirt.engine.sdk4.services.ClustersService)4 Cluster (org.ovirt.engine.sdk4.types.Cluster)4 ArrayList (java.util.ArrayList)3 AffinityLabelsService (org.ovirt.engine.sdk4.services.AffinityLabelsService)3 AssignedTagsService (org.ovirt.engine.sdk4.services.AssignedTagsService)3 DataCenterService (org.ovirt.engine.sdk4.services.DataCenterService)3 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)3