use of org.ovirt.engine.sdk4.services.StorageDomainsService 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();
}
use of org.ovirt.engine.sdk4.services.StorageDomainsService 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();
}
Aggregations