To limit the resource consumed by each user, project, or organization, you can create a resource quota policy using the Service Broker Policies API. Applying the policy ensures that users do not consume all available resources.

With the policy defined, any new deployment requests are evaluated against the resource quota. If a resource request exceeds the quota, the deployment request fails with a message that indicates the reason for the failure. The resource quota does not apply to deployment requests that are already in-progress when the policy is defined.

In cases where multiple policies are defined for a resource at the same scope level, the request is evaluated against the quota with the lowest limit value.

For information about policy scope, see How do I configure scope in Service Broker policies.

The following examples show how to define a resource quota policy with:
  • Organization level limits.
  • Project level limits.

For both definitions, you use POST /policy/api/policies to create the policy with the input parameter "typeId": "com.vmware.policy.resource.quota".

Prerequisites for creating a resource quota policy

Resource quota policy with organizational level limits

This example shows how to define a resource quota policy with hard enforcement and limits on resource consumption by the organization and each user within the organization.

curl -k -X POST \
  "$url/policy/api/policies?apiVersion=$api_version" \
  -H "Authorization: Bearer $access_token" \
  -H 'Content-Type: application/json' \    
  -d '{
    "name": "Sample Resource Quota Policy 1",
    "enforcementType": "HARD",
    "typeId": "com.vmware.policy.resource.quota",    
    "definition": {
      "orgLevel": {
          "limits": {
              "cpu": {
                  "value": 50
              },
              "storage": {
                  "value": 150,
                  "unit": "GB"
              },
              "memory": {
                  "value": 150,
                  "unit": "GB"
              },
              "instances": {
                  "value": 50
              }
          },
          "userLevel": {
              "limits": {
                  "cpu": {
                      "value": 4
                  },
                  "storage": {
                      "value": 10,
                      "unit": "GB"
                  },
                  "memory": {
                      "value": 10,
                      "unit": "GB"
                  },
                  "instances": {
                      "value": 2
                  }
              }
          }
      }    
    }
  }' | jq "."

The response shows the resource quota policy with organization and organization user level limits.

{
    "id": "52f67297-3e15-4e0a-9336-35894d2be0bc",
    "name": "Sample Resource Quota Policy 1",
    "typeId": "com.vmware.policy.resource.quota",
    "enforcementType": "HARD",
    "orgId": "74a191fc-27e0-4f09-af0d-6acd04d60832",    
    "definition": {
      "orgLevel": {
          "limits": {
              "cpu": {
                  "value": 50
              },
              "storage": {
                  "value": 150,
                  "unit": "GB"
              },
              "memory": {
                  "value": 150,
                  "unit": "GB"
              },
              "instances": {
                  "value": 50
              }
          },
          "userLevel": {
              "limits": {
                  "cpu": {
                      "value": 4
                  },
                  "storage": {
                      "value": 10,
                      "unit": "GB"
                  },
                  "memory": {
                      "value": 10,
                      "unit": "GB"
                  },
                  "instances": {
                      "value": 2
                  }
              }
          }
      } 
    },
    "createdAt": "2021-11-08T11:51:47.742311Z",
    "createdBy": "[email protected]",
    "lastUpdatedAt": "2021-11-08T11:51:47.742311Z",
    "lastUpdatedBy": "[email protected]"
}

Resource quota policy with project level limits

This example shows how to define a resource quota policy with hard enforcement and limits on resource consumption by a project and each project user.

curl -k -X POST \
  "$url/policy/api/policies?apiVersion=$api_version" \
  -H "Authorization: Bearer $access_token" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Sample Resource Quota Policy 2",
    "enforcementType": "HARD",
    "projectId": "6df55bb1-7444-4c13-9997-4004ba0a321d",
    "scopeCriteria": null,
    "typeId": "com.vmware.policy.resource.quota",
    "definition": {
      "projectLevel": {
          "limits": {
              "cpu": {
                  "value": 50
              },
              "storage": {
                  "value": 80,
                  "unit": "GB"
              },
              "memory": {
                  "value": 80,
                  "unit": "GB"
              },
              "instances": {
                  "value": 40
              }
          },
          "userLevel": {
              "limits": {
                  "cpu": {
                      "value": 5
                  },
                  "storage": {
                      "value": 8,
                      "unit": "GB"
                  },
                  "memory": {
                      "value": 8,
                      "unit": "GB"
                  },
                  "instances": {
                      "value": 4
                  }
              }
          }
      }    
    }
  }' | jq "."

The response shows the resource quota policy with project and project user level limits.

{
    "id": "5809ec88-16fb-4553-98c3-5b588ebff322",
    "name": "Sample Resource Quota Policy 2",
    "typeId": "com.vmware.policy.resource.quota",
    "enforcementType": "HARD",
    "orgId": "74a191fc-27e0-4f09-af0d-6acd04d60832",
    "projectId": "6df55bb1-7444-4c13-9997-4004ba0a321d",
    "definition": {
      "projectLevel": {
          "limits": {
              "cpu": {
                  "value": 50
              },
              "storage": {
                  "value": 80,
                  "unit": "GB"
              },
              "memory": {
                  "value": 80,
                  "unit": "GB"
              },
              "instances": {
                  "value": 40
              }
          },
          "userLevel": {
              "limits": {
                  "cpu": {
                      "value": 5
                  },
                  "storage": {
                      "value": 8,
                      "unit": "GB"
                  },
                  "memory": {
                      "value": 8,
                      "unit": "GB"
                  },
                  "instances": {
                      "value": 4
                  }
              }
          }
      }    
    },
    "createdAt": "2021-11-08T12:09:34.160569Z",
    "createdBy": "[email protected]",
    "lastUpdatedAt": "2021-11-08T12:09:34.160569Z",
    "lastUpdatedBy": "[email protected]"
}