use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.
the class ExportVm 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 services tree:
SystemService systemService = connection.systemService();
// Find the virtual machine:
VmsService vmsService = systemService.vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Export the virtual machine. Note that the 'exclusive' parameter is optional, and only required if you want
// to overwrite a virtual machine that has already been exported before.
VmService vmService = vmsService.vmService(vm.id());
vmService.export().exclusive(true).discardSnapshots(true).storageDomain(storageDomain().name("myexport")).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.
the class ImportGlanceImage 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 root of the services tree:
SystemService systemService = connection.systemService();
// Find the Glance storage domain that is available for default in any oVirt installation:
StorageDomainsService sdsService = systemService.storageDomainsService();
StorageDomain sd = sdsService.list().search("name=ovirt-image-repository").send().storageDomains().get(0);
// Find the servie that manages the Glance storage domain:
StorageDomainService sdService = sdsService.storageDomainService(sd.id());
// Find the service that manages the images available in that storage domain:
ImagesService imagesService = sdService.imagesService();
// The images service doesn't support search, so in roder to find an image we need to retrieve all of them and
// do the filtering explicitly:
List<Image> images = imagesService.list().send().images();
Image image = null;
for (Image i : images) {
if (Objects.equals(i.name(), "CirrOS 0.3.4 for x86_64")) {
image = i;
break;
}
}
// Find the service that manages the image that we found in the previous step:
ImageService imageService = imagesService.imageService(image.id());
// Import the image:
imageService.import_().importAsTemplate(true).template(template().name("mytemplate")).cluster(cluster().name("mycluster")).storageDomain(storageDomain().name("mydata")).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.
the class RegisterVm method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "StorageDomains" service:
StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
// Find the storage domain with unregistered VM:
StorageDomain sd = storageDomainsService.list().search("name=mysd").send().storageDomains().get(0);
// Locate the service that manages the storage domain, as that is where the action methods are defined:
StorageDomainService storageDomainService = storageDomainsService.storageDomainService(sd.id());
// Locate the service that manages the VMs in storage domain:
StorageDomainVmsService storageDomainVmsService = storageDomainService.vmsService();
// Find the the unregistered VM we want to register:
List<Vm> unregisteredVms = storageDomainVmsService.list().unregistered(true).send().vm();
Vm vm = null;
for (Vm x : unregisteredVms) {
if ("myvm".equals(x.name())) {
vm = x;
break;
}
}
// Locate the service that manages virtual machine in the storage domain, as that is where the action methods
// are defined:
StorageDomainVmService storageDomainVmService = storageDomainVmsService.vmService(vm.id());
// Register the VM into the system:
storageDomainVmService.register().vm(vm().name("exported_myvm")).cluster(cluster().name("mycluster")).vnicProfileMappings(vnicProfileMapping().sourceNetworkName("mynetwork").sourceNetworkProfileName("mynetwork").targetVnicProfile(vnicProfile().name("mynetwork"))).reassignBadMacs(true).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.
the class SetVmLeaseStorageDomain 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);
// Find the storage domain:
StorageDomainsService sdsService = systemService.storageDomainsService();
StorageDomain sd = sdsService.list().search("name=mydata").send().storageDomains().get(0);
// Update the virtual machine so that high availability is enabled and the lease is created in the selected
// storage domain:
VmService vmService = vmsService.vmService(vm.id());
vmService.update().vm(vm().highAvailability(highAvailability().enabled(true)).lease(storageDomainLease().storageDomain(storageDomain().id(sd.id())))).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.types.StorageDomain 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();
}
Aggregations