Search in sources :

Example 1 with QuotaStorageLimitsService

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();
}
Also used : StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) DataCentersService(org.ovirt.engine.sdk4.services.DataCentersService) Connection(org.ovirt.engine.sdk4.Connection) QuotaStorageLimitService(org.ovirt.engine.sdk4.services.QuotaStorageLimitService) QuotaStorageLimitsService(org.ovirt.engine.sdk4.services.QuotaStorageLimitsService) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) QuotaStorageLimit(org.ovirt.engine.sdk4.types.QuotaStorageLimit) DataCenter(org.ovirt.engine.sdk4.types.DataCenter) SystemService(org.ovirt.engine.sdk4.services.SystemService) Quota(org.ovirt.engine.sdk4.types.Quota) QuotasService(org.ovirt.engine.sdk4.services.QuotasService) DataCenterService(org.ovirt.engine.sdk4.services.DataCenterService) QuotaService(org.ovirt.engine.sdk4.services.QuotaService)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)1 DataCenterService (org.ovirt.engine.sdk4.services.DataCenterService)1 DataCentersService (org.ovirt.engine.sdk4.services.DataCentersService)1 QuotaService (org.ovirt.engine.sdk4.services.QuotaService)1 QuotaStorageLimitService (org.ovirt.engine.sdk4.services.QuotaStorageLimitService)1 QuotaStorageLimitsService (org.ovirt.engine.sdk4.services.QuotaStorageLimitsService)1 QuotasService (org.ovirt.engine.sdk4.services.QuotasService)1 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)1 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)1 SystemService (org.ovirt.engine.sdk4.services.SystemService)1 DataCenter (org.ovirt.engine.sdk4.types.DataCenter)1 Quota (org.ovirt.engine.sdk4.types.Quota)1 QuotaStorageLimit (org.ovirt.engine.sdk4.types.QuotaStorageLimit)1 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)1