use of org.ovirt.engine.sdk4.services.StorageDomainService in project ovirt-engine-sdk-java by oVirt.
the class UpdateQuotaLimits 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 reference to the root of the tree of services:
SystemService systemService = connection.systemService();
// Find the data center and the service that manages it:
DataCentersService dcsService = systemService.dataCentersService();
DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
DataCenterService dcService = dcsService.dataCenterService(dc.id());
// Find the storage domain and the service that manages it:
StorageDomainsService sdsService = systemService.storageDomainsService();
StorageDomain sd = sdsService.list().search("name=mydata").send().storageDomains().get(0);
StorageDomainService sdService = sdsService.storageDomainService(sd.id());
// Find the quota and the service that manages it. Note that the service that manages the quota doesn't support
// search, so we need to retrieve all the quotas and filter explicitly. If the quota doesn't exist, create it.
QuotasService quotasService = dcService.quotasService();
List<Quota> quotas = quotasService.list().send().quotas();
Quota quota = null;
for (Quota q : quotas) {
if (Objects.equals(q.id(), "myquota")) {
quota = q;
break;
}
}
if (quota == null) {
quota = quotasService.add().quota(quota().name("myquota").description("My quota").clusterHardLimitPct(20).clusterSoftLimitPct(80).storageHardLimitPct(20).storageSoftLimitPct(80)).send().quota();
}
QuotaService quotaService = quotasService.quotaService(quota.id());
// Find the quota limits for the storage domain that we are interested on:
QuotaStorageLimitsService limitsService = quotaService.quotaStorageLimitsService();
List<QuotaStorageLimit> limits = limitsService.list().send().limits();
QuotaStorageLimit limit = null;
for (QuotaStorageLimit l : limits) {
if (Objects.equals(l.id(), sd.id())) {
limit = l;
break;
}
}
// If that limit exists we will delete it:
if (limit != null) {
QuotaStorageLimitService limitService = limitsService.limitService(limit.id());
limitService.remove();
}
// Create the limit again with the desired values, in this example it will be 100 GiB:
limitsService.add().limit(quotaStorageLimit().name("mydatalimit").description("My storage domain limit").limit(100).storageDomain(storageDomain().id(sd.id()))).send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.StorageDomainService in project ovirt-engine-sdk-java by oVirt.
the class ListGlanceImages 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 service 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();
// List the images available in the storage domain:
List<Image> images = imagesService.list().send().images();
for (Image image : images) {
System.out.println(image.name());
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.StorageDomainService in project ovirt-engine-sdk-java by oVirt.
the class AddNfsDataStorageDomain 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("mydata").description("My data").type(StorageDomainType.DATA).host(host().name("myhost")).storage(hostStorage().type(StorageType.NFS).address("server0.example.com").path("/nfs/ovirt/40/mydata"))).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();
}
use of org.ovirt.engine.sdk4.services.StorageDomainService in project ovirt-engine-sdk-java by oVirt.
the class StorageDomainsServiceTest method testGetObjectFromStorageDomainService.
/**
* Test we don't get null storage service for existing storage id and correct object
*/
@Test
public void testGetObjectFromStorageDomainService() {
StorageDomainService sdService = storageDomainsService.storageDomainService("123");
StorageDomain sd = sdService.get().send().storageDomain();
assertEquals("123", sd.id());
assertEquals("testsd", sd.name());
assertNull(sd.description());
}
use of org.ovirt.engine.sdk4.services.StorageDomainService 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();
}
Aggregations