<commit_before>---
title: Quota
category: sla
authors: amureini, doron, mlipchuk, oliel
wiki_category: SLA
wiki_title: Features/Design/Quota
wiki_revision_count: 112
wiki_last_updated: 2012-08-23
---

# Quota

This document describes the design for the Quota feature.

### Motivation

Ovirt makes it very easy for users to add VMs, thus using CPU, memory and storage resources, thus there is a requirement that system administrators will be able to limit the resource usage of users in the environment by setting a Quota on these resources.
 The resources in scope for this feature are:

1.  Per-cluster resources:
    1.  Virtual CPUs
    2.  Virtual RAM

2.  Storage resources

... ... ...

Please see <http://www.ovirt.org/wiki/Features/Quota>

### GUI

Please see [Mockups](Features/DetailedQuota#User_Experience)

#### Design

### REST Design (Modeling)

This section describes the REST design for this feature.

### Backend

This section describes the backend design for this feature.

#### DB Design

**quota_storage_pool** - Represents the properties of the Quota configured on the DC.

| Column Name                       | Column Type  | Null? / Default | Definition                                                                                        |
|-----------------------------------|--------------|-----------------|---------------------------------------------------------------------------------------------------|
| quota_id                         | UUID         | PK(not null)    | The Quota Id                                                                                      |
| storage_pool_id                 | UUID         | not null        | Storage pool Id                                                                                   |
| quota_name                       | VARCHAR(50)  | not null        | Quota name                                                                                        |
| description                       | VARCHAR(500) | not null        | Quota description                                                                                 |
| creation_date                    | Date         | not null        | Quota creation date                                                                               |
| update_date                      | Date         | not null        | Quota update date                                                                                 |
| threshold_vds_group_percentage | INTEGER      | null            | The threshold of the Vds Group Quota the default should be configured in the vdc_options         |
| threshold_storage_percentage    | INTEGER      | null            | The threshold of the Storage Quota the default should be configured in the vdc_options           |
| grace_vds_group_percentage     | INTEGER      | null            | The grace in percentage of the Cluster Quota the default should be configured in the vdc_options |
| grace_storage_percentage        | INTEGER      | null            | The grace in percentage of the Storage Quota the default should be configured in the vdc_options |

**quota_limitation** - Represents the quota limitation which are part of the Quota, the limitation can be defined for storage/vds cluster/storage pool.

| Column Name                | Column Type | Null? / Default | Definition                               |
|----------------------------|-------------|-----------------|------------------------------------------|
| quota_limitation_id      | UUID        | PK(not null)    | The primary key of the quota limitation. |
| quota_id                  | UUID        | not null        | Foreign key for the quota id.            |
| storage_id                | UUID        | null            | Foreign key for storage id.              |
| vds_group_id             | UUID        | null            | Foreign key for vds group id.            |
| virtual_cpu               | INTEGER     | null            | The limited virtual cpu.                 |
| virtual_ram_mega_byte   | BIGINT      | null            | The limited ram defined in mega byte.    |
| storage_limit_giga_byte | BIGINT      | null            | The limited defined in Giga byte.        |

**quota_usage** - The table is similar to quota limitation only it represents how much is used from the limitation.

| Column Name                | Column Type | Null? / Default | Definition                               |
|----------------------------|-------------|-----------------|------------------------------------------|
| quota_usage_id           | UUID        | PK(not null)    | The primary key of the quota usage.      |
| quota_limitation_id      | UUID        | not null        | Foreign key for the quota limitation id. |
| virtual_cpu               | INTEGER     | not null        | The limited cpu defined in Giga byte.    |
| storage_limit_giga_byte | INTEGER     | null            | The limited GB defined in Giga byte.     |
| virtual_ram_mega_byte   | BIGINT      | null            | The limited ram defined in Mega byte.    |

**quota_users** - Represents the Quota users which are permitted to consume from the Quota.

| Column Name | Column Type | Null? / Default | Definition                                                                                      |
|-------------|-------------|-----------------|-------------------------------------------------------------------------------------------------|
| quota_id   | UUID        | Not null        | Foreign key for Quota ID represented in the quota table                                         |
| user_id    | UUID        | null            | Foreign key to the users.user_id (null indicates no users permitted to consume from the Quota) |

Use cases :

1.  When quota_limitation vds_group_id=null and storage_id=null then the limitation is referenced to global limitation
2.  When quota_limitation vds_group_id=null but storage_id!=null then the limitation is referenced only to storage quota
3.  When quota_limitation vds_group_id!=null but storage_id=null then the limitation is referenced only to vdsGroup quota
4.  unlimited quota - vds_group_id=null and storage_id=null in quota_limitation table and fields of vcpu, vram and storage will be initialized with -1.
5.  general limited quota - vds_group_id=null and storage_id=null in quota_limitation table, fields of vcpu, vram and storage will be initialized with specific number.
6.  specific limited quota - vds_group_id!=null and/or storage_id!=null in quota_limitation table, quota fields (vcpu, vram and storage) will be null.
7.  quota without any resources - vds_group_id=null and storage_id=null in quota_limitation table, quota fields (vcpu, vram and storage) will be 0.

***vm_dynamic*** - Add column *quota_id*, which indicates the Quota the VM should be depended on its resources.
 ***image*** - Add column *quota_id*, which indicates the Quota the image should be depended on its storage resources.
 ***storage_pool*** - Add column *quota_enforcement*, Indicates the DC enforcement status for Quota (Disalbe(0) , Soft Limit (1),Hard Limit (2)) will be presented by Enum (see [QuotaStatusEnum](Features/Design/Quota#Classes).).

###### Views

[all_quotas](Features/Design/Quota#Appendix) - View of all the Quotas attached to all the storage pools for all Users.

**quota_global_view** - View of all the storage pool quota in the setup, that is all the quota that vds_group_id and storage_id values are null in the quota_limitation.

| Column Name                       | Column Type | Definition                                                      |
|-----------------------------------|-------------|-----------------------------------------------------------------|
| storage_pool                     | UUID        | The Storage Pool Id                                             |
| Quota_ID                         | UUID        | The Quota Id                                                    |
| Quota_Name                       | String      | The Quota name                                                  |
| virtual_cpu                      | INTEGER     | The limited cpu, defined in Giga byte.                          |
| virtual_cpu_usage               | INTEGER     | The usage of the cpu in the storage pool, defined in Giga byte. |
| storage_limit_giga_byte        | INTEGER     | The limited GB, defined in Giga byte.                           |
| storage_limit_giga_byte_usage | INTEGER     | The used GB in the storage pool, defined in Giga byte.          |
| virtual_ram_mega_byte          | BIGINT      | The limited ram, defined in Mega byte.                          |
| virtual_ram_mega_byte_usage   | BIGINT      | The used ram in the storage pool.                               |

**quota_vds_group_view** - View of all the vds group quotas in the setup, that is all the quotas that vds_group_id is not null but storage_id is null in the quota_limitation.

| Column Name                     | Column Type | Definition                                                 |
|---------------------------------|-------------|------------------------------------------------------------|
| storage_pool                   | UUID        | The Storage Pool Id                                        |
| Quota_ID                       | UUID        | The Quota Id                                               |
| Quota_Name                     | String      | The Quota name                                             |
| vds_static_id                 | UUID        | The vds group Id                                           |
| vds_static_name               | UUID        | The vds group name from vds_group_static                 |
| virtual_cpu                    | INTEGER     | The limited cpu, defined in Giga byte.                     |
| virtual_cpu_usage             | INTEGER     | The usage of the cpu in the cluster, defined in Giga byte. |
| virtual_ram_mega_byte        | BIGINT      | The limited ram defined in Mega byte.                      |
| virtual_ram_mega_byte_usage | BIGINT      | The used ram in the cluster.                               |

**quota_storage_view** - View of all the storage quotas in the setup, that is all the quotas that storage_id is not null but vds_cluster_id is null in the quota_limitation.

| Column Name                       | Column Type | Definition                               |
|-----------------------------------|-------------|------------------------------------------|
| storage_pool                     | UUID        | The Storage Pool Id                      |
| Quota_ID                         | UUID        | The Quota Id                             |
| storage_Name                     | String      | The storage name                         |
| storage_id                       | UUID        | The vds group Id                         |
| storage_limit_giga_byte        | INTEGER     | The limited GB defined in Giga byte.     |
| storage_limit_giga_byte_usage | INTEGER     | The used GB on the quota storage domain. |

###### Stored Procedures

*GetQuotaVdsGroupByVdsGroupGuid*

*   Input - vds_group_id UUID, storage_pool_id UUID.
*   Output - a business entity mapped by quota_vds_group_view for specified vds_group with vds_group_id. (if vds_group_id=null then returns a list of all the vds group quotas for the storage pool_id)

*GetQuotaStorageByStorageGuid*

*   Input - storage_id UUID, storage_pool_id UUID.
*   output - a business entity mapped by quota_storage_view for specified cluster_id, (if storage_id=null then returns a list of all the quota Storage for the storage pool_id)

*GetQuotaByStoragePoolGuid* -

*   Input - storage_pool_id UUID.
*   output - a business entity mapped by quota_global_view for specified storage_pool_id, (if storage_pool_id=null then returns a list of all the quota in the setup)

#### Logic Design

Each time the user will run or edit the VM, there will be a Quota check against the quota cluster view.
 Both views, quota_storage and quota_cluster should be reflected in the memory as Concurrent HashMap tables. The memory tables should be checked and updated in the canDoAction in a synchronized context (Using java.util.concurrency). Those memory tables should be managed in a pessimistic way, considering resource allocation, to prevent over-commit situations.
 Those tables should be synchronized from time to time from VdsUpdateRunTimeInfo (for cluster quota) and AsyncTaskManager(for storage quota).

###### Synchronized Vds commands

When calling synchronized Vds commands (such as createVm, MigrateVm), which should increase the consumption on cluster quota, we will update the quota dynamic table in the DB when the VdsCommand is being called.
 When we will decrease the consumption on cluster quota, the update on the Quota tables should be at the end of the VDS command.

###### A-synchronized Vds commands
<commit_msg>Stored Procedures<commit_after>---
title: Quota
category: sla
authors: amureini, doron, mlipchuk, oliel
wiki_category: SLA
wiki_title: Features/Design/Quota
wiki_revision_count: 112
wiki_last_updated: 2012-08-23
---

# Quota

This document describes the design for the Quota feature.

### Motivation

Ovirt makes it very easy for users to add VMs, thus using CPU, memory and storage resources, thus there is a requirement that system administrators will be able to limit the resource usage of users in the environment by setting a Quota on these resources.
 The resources in scope for this feature are:

1.  Per-cluster resources:
    1.  Virtual CPUs
    2.  Virtual RAM

2.  Storage resources

... ... ...

Please see <http://www.ovirt.org/wiki/Features/Quota>

### GUI

Please see [Mockups](Features/DetailedQuota#User_Experience)

#### Design

### REST Design (Modeling)

This section describes the REST design for this feature.

### Backend

This section describes the backend design for this feature.

#### DB Design

**quota_storage_pool** - Represents the properties of the Quota configured on the DC.

| Column Name                       | Column Type  | Null? / Default | Definition                                                                                        |
|-----------------------------------|--------------|-----------------|---------------------------------------------------------------------------------------------------|
| quota_id                         | UUID         | PK(not null)    | The Quota Id                                                                                      |
| storage_pool_id                 | UUID         | not null        | Storage pool Id                                                                                   |
| quota_name                       | VARCHAR(50)  | not null        | Quota name                                                                                        |
| description                       | VARCHAR(500) | not null        | Quota description                                                                                 |
| creation_date                    | Date         | not null        | Quota creation date                                                                               |
| update_date                      | Date         | not null        | Quota update date                                                                                 |
| threshold_vds_group_percentage | INTEGER      | null            | The threshold of the Vds Group Quota the default should be configured in the vdc_options         |
| threshold_storage_percentage    | INTEGER      | null            | The threshold of the Storage Quota the default should be configured in the vdc_options           |
| grace_vds_group_percentage     | INTEGER      | null            | The grace in percentage of the Cluster Quota the default should be configured in the vdc_options |
| grace_storage_percentage        | INTEGER      | null            | The grace in percentage of the Storage Quota the default should be configured in the vdc_options |

**quota_limitation** - Represents the quota limitation which are part of the Quota, the limitation can be defined for storage/vds cluster/storage pool.

| Column Name                | Column Type | Null? / Default | Definition                               |
|----------------------------|-------------|-----------------|------------------------------------------|
| quota_limitation_id      | UUID        | PK(not null)    | The primary key of the quota limitation. |
| quota_id                  | UUID        | not null        | Foreign key for the quota id.            |
| storage_id                | UUID        | null            | Foreign key for storage id.              |
| vds_group_id             | UUID        | null            | Foreign key for vds group id.            |
| virtual_cpu               | INTEGER     | null            | The limited virtual cpu.                 |
| virtual_ram_mega_byte   | BIGINT      | null            | The limited ram defined in mega byte.    |
| storage_limit_giga_byte | BIGINT      | null            | The limited defined in Giga byte.        |

**quota_usage** - The table is similar to quota limitation only it represents how much is used from the limitation.

| Column Name                | Column Type | Null? / Default | Definition                               |
|----------------------------|-------------|-----------------|------------------------------------------|
| quota_usage_id           | UUID        | PK(not null)    | The primary key of the quota usage.      |
| quota_limitation_id      | UUID        | not null        | Foreign key for the quota limitation id. |
| virtual_cpu               | INTEGER     | not null        | The limited cpu defined in Giga byte.    |
| storage_limit_giga_byte | INTEGER     | null            | The limited GB defined in Giga byte.     |
| virtual_ram_mega_byte   | BIGINT      | null            | The limited ram defined in Mega byte.    |

**quota_users** - Represents the Quota users which are permitted to consume from the Quota.

| Column Name | Column Type | Null? / Default | Definition                                                                                      |
|-------------|-------------|-----------------|-------------------------------------------------------------------------------------------------|
| quota_id   | UUID        | Not null        | Foreign key for Quota ID represented in the quota table                                         |
| user_id    | UUID        | null            | Foreign key to the users.user_id (null indicates no users permitted to consume from the Quota) |

Use cases :

1.  When quota_limitation vds_group_id=null and storage_id=null then the limitation is referenced to global limitation
2.  When quota_limitation vds_group_id=null but storage_id!=null then the limitation is referenced only to storage quota
3.  When quota_limitation vds_group_id!=null but storage_id=null then the limitation is referenced only to vdsGroup quota
4.  unlimited quota - vds_group_id=null and storage_id=null in quota_limitation table and fields of vcpu, vram and storage will be initialized with -1.
5.  general limited quota - vds_group_id=null and storage_id=null in quota_limitation table, fields of vcpu, vram and storage will be initialized with specific number.
6.  specific limited quota - vds_group_id!=null and/or storage_id!=null in quota_limitation table, quota fields (vcpu, vram and storage) will be null.
7.  quota without any resources - vds_group_id=null and storage_id=null in quota_limitation table, quota fields (vcpu, vram and storage) will be 0.

***vm_dynamic*** - Add column *quota_id*, which indicates the Quota the VM should be depended on its resources.
 ***image*** - Add column *quota_id*, which indicates the Quota the image should be depended on its storage resources.
 ***storage_pool*** - Add column *quota_enforcement*, Indicates the DC enforcement status for Quota (Disalbe(0) , Soft Limit (1),Hard Limit (2)) will be presented by Enum (see [QuotaStatusEnum](Features/Design/Quota#Classes).).

###### Views

[all_quotas](Features/Design/Quota#Appendix) - View of all the Quotas attached to all the storage pools for all Users.

**quota_global_view** - View of all the storage pool quota in the setup, that is all the quota that vds_group_id and storage_id values are null in the quota_limitation.

| Column Name                       | Column Type | Definition                                                      |
|-----------------------------------|-------------|-----------------------------------------------------------------|
| storage_pool                     | UUID        | The Storage Pool Id                                             |
| Quota_ID                         | UUID        | The Quota Id                                                    |
| Quota_Name                       | String      | The Quota name                                                  |
| virtual_cpu                      | INTEGER     | The limited cpu, defined in Giga byte.                          |
| virtual_cpu_usage               | INTEGER     | The usage of the cpu in the storage pool, defined in Giga byte. |
| storage_limit_giga_byte        | INTEGER     | The limited GB, defined in Giga byte.                           |
| storage_limit_giga_byte_usage | INTEGER     | The used GB in the storage pool, defined in Giga byte.          |
| virtual_ram_mega_byte          | BIGINT      | The limited ram, defined in Mega byte.                          |
| virtual_ram_mega_byte_usage   | BIGINT      | The used ram in the storage pool.                               |

**quota_vds_group_view** - View of all the vds group quotas in the setup, that is all the quotas that vds_group_id is not null but storage_id is null in the quota_limitation.

| Column Name                     | Column Type | Definition                                                 |
|---------------------------------|-------------|------------------------------------------------------------|
| storage_pool                   | UUID        | The Storage Pool Id                                        |
| Quota_ID                       | UUID        | The Quota Id                                               |
| Quota_Name                     | String      | The Quota name                                             |
| vds_static_id                 | UUID        | The vds group Id                                           |
| vds_static_name               | UUID        | The vds group name from vds_group_static                 |
| virtual_cpu                    | INTEGER     | The limited cpu, defined in Giga byte.                     |
| virtual_cpu_usage             | INTEGER     | The usage of the cpu in the cluster, defined in Giga byte. |
| virtual_ram_mega_byte        | BIGINT      | The limited ram defined in Mega byte.                      |
| virtual_ram_mega_byte_usage | BIGINT      | The used ram in the cluster.                               |

**quota_storage_view** - View of all the storage quotas in the setup, that is all the quotas that storage_id is not null but vds_cluster_id is null in the quota_limitation.

| Column Name                       | Column Type | Definition                               |
|-----------------------------------|-------------|------------------------------------------|
| storage_pool                     | UUID        | The Storage Pool Id                      |
| Quota_ID                         | UUID        | The Quota Id                             |
| storage_Name                     | String      | The storage name                         |
| storage_id                       | UUID        | The vds group Id                         |
| storage_limit_giga_byte        | INTEGER     | The limited GB defined in Giga byte.     |
| storage_limit_giga_byte_usage | INTEGER     | The used GB on the quota storage domain. |

###### Stored Procedures

*GetQuotaVdsGroupByVdsGroupGuid*

*   Input - vds_group_id UUID, storage_pool_id UUID.
*   Output - a business entity mapped by quota_vds_group_view for specified vds_group with vds_group_id. (if vds_group_id=null then returns a list of all the vds group quotas for the storage pool_id)

*GetQuotaStorageByStorageGuid*

*   Input - storage_id UUID, storage_pool_id UUID.
*   output - a business entity mapped by quota_storage_view for specified cluster_id, (if storage_id=null then returns a list of all the quota Storage for the storage pool_id)

*GetQuotaByStoragePoolGuid*

*   Input - storage_pool_id UUID.
*   output - a business entity mapped by quota_global_view for specified storage_pool_id, (if storage_pool_id=null then returns a list of all the quota in the setup)

*GetQuotaUserByQuotaGuid*

*   Input - quota_storage_pool_id UUID.
*   output - all users for quota id

#### Logic Design

Each time the user will run or edit the VM, there will be a Quota check against the quota cluster view.
 Both views, quota_storage and quota_cluster should be reflected in the memory as Concurrent HashMap tables. The memory tables should be checked and updated in the canDoAction in a synchronized context (Using java.util.concurrency). Those memory tables should be managed in a pessimistic way, considering resource allocation, to prevent over-commit situations.
 Those tables should be synchronized from time to time from VdsUpdateRunTimeInfo (for cluster quota) and AsyncTaskManager(for storage quota).

###### Synchronized Vds commands

When calling synchronized Vds commands (such as createVm, MigrateVm), which should increase the consumption on cluster quota, we will update the quota dynamic table in the DB when the VdsCommand is being called.
 When we will decrease the consumption on cluster quota, the update on the Quota tables should be at the end of the VDS command.

###### A-synchronized Vds commands

{'fraction_non_alphanumeric': 0.11402631376471493, 'fraction_numerical': 0.0024621066399938447, 'mean_word_length': 1.4369550951532764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 94, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1970200', 'n_tokens_mistral': 6090, 'n_tokens_neox': 5703, 'n_words': 2437}