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