Documentation ¶
Overview ¶
Package quotas provides the ability to retrieve and update quotas through the Quota Manager API.
Example of getting quota limits for a single project
limits, _, err := quotas.GetLimits(ctx, QuotaRegionalClient) if err != nil { log.Fatal(err) } for _, limit := range limits { fmt.Println(limit) }
Example of getting quotas for a single project in specific region
singleProjectQuotas, _, err := quotas.GetProjectQuotas(ctx, ResellClient, QuotaRegionalClient, projectID, regionName) if err != nil { log.Fatal(err) } for _, singleProjectQuota := range singleProjectQuotas { fmt.Println(singleProjectQuota) }
Example of updating quotas for a single project in specific region
projectQuotaUpdateOpts := quotas.UpdateProjectQuotasOpts{ QuotasOpts: []*quota-manager.QuotaOpts{ { Name: "image_gigabytes", ResourceQuotasOpts: []quotas.ResourceQuotaOpts{ { Value: 10, }, { Value: 20, }, }, }, }, } updatedProjectQuotas, _, err := quotas.UpdateProjectQuotas(context, ResellClient, QuotaRegionalClient, projectID, regionName, projectQuotaUpdateOpts) if err != nil { log.Fatal(err) } for _, updatedProjectQuota := range updatedProjectQuotas { fmt.Println(updatedProjectQuota) }
Index ¶
- type InfoQuotas
- type Quota
- func GetLimits(ctx context.Context, client *quotamanager.QuotaRegionalClient, ...) ([]*Quota, *quotamanager.ResponseResult, error)
- func GetProjectQuotas(ctx context.Context, client *quotamanager.QuotaRegionalClient, ...) ([]*Quota, *quotamanager.ResponseResult, error)
- func UpdateProjectQuotas(ctx context.Context, client *quotamanager.QuotaRegionalClient, ...) ([]*Quota, *quotamanager.ResponseResult, error)
- type QuotaOpts
- type ResourceError
- type ResourceQuotaEntity
- type ResourceQuotaOpts
- type ResourcesQuotas
- type ResponseQuotas
- type UpdateProjectQuotasOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InfoQuotas ¶
type InfoQuotas map[string][]ResourceQuotaEntity
type Quota ¶
type Quota struct { // Name is a resource human-readable name. Name string `json:"-"` // ResourceQuotasEntities contains information about quotas of a single billing resource in specific region. ResourceQuotasEntities []ResourceQuotaEntity `json:"-"` // ResourceQuotasErrors contains errors about quotas of a single billing resource in specific region. ResourceQuotasErrors []ResourceError `json:"-"` }
Quota represents a quota information for a single billing resource.
func GetLimits ¶
func GetLimits(ctx context.Context, client *quotamanager.QuotaRegionalClient, projectID, region string, ) ([]*Quota, *quotamanager.ResponseResult, error)
GetLimits returns limits for a single project referenced by id in specific region.
func GetProjectQuotas ¶
func GetProjectQuotas(ctx context.Context, client *quotamanager.QuotaRegionalClient, projectID, region string, ) ([]*Quota, *quotamanager.ResponseResult, error)
GetProjectQuotas returns the quotas info for a single project referenced by id in specific region.
func UpdateProjectQuotas ¶
func UpdateProjectQuotas(ctx context.Context, client *quotamanager.QuotaRegionalClient, projectID, region string, updateOpts UpdateProjectQuotasOpts, ) ([]*Quota, *quotamanager.ResponseResult, error)
UpdateProjectQuotas updates the quotas info for a single project referenced by id in specific region.
type QuotaOpts ¶
type QuotaOpts struct { // Name is a human-readable name of the resource. Name string `json:"-"` // ResourceQuotasOpts represents quota update options of a single resource in // different locations. ResourceQuotasOpts []ResourceQuotaOpts `json:"-"` }
QuotaOpts represents quota options for a single resource that can be used in the update request.
type ResourceError ¶
type ResourceError struct { // Resource is a resource human-readable name. Resource string `json:"resource"` // Zone contains the quota zone data. Zone string `json:"zone,omitempty"` // Message contains human-readable error message. Message string `json:"message"` // Code contains error code value. Code int `json:"code"` }
ResourceError represents an information about errors that occurred during the request.
type ResourceQuotaEntity ¶
type ResourceQuotaEntity struct { // Zone contains the quota zone data. Zone string `json:"zone,omitempty"` // Value contains value of resource quota in the specific region and zone. Value int `json:"value"` // Used contains quantity of a used quota in the specific region and zone. Used int `json:"used,omitempty"` }
ResourceQuotaEntity represents a single entity of the resource quota data in the specific region and zone.
type ResourceQuotaOpts ¶
type ResourceQuotaOpts struct { // Zone contains the quota zone data. Zone *string `json:"zone,omitempty"` // Value contains value of resource quota in the specific region and zone. Value *int `json:"value"` }
ResourceQuotaOpts represents update options for the resource quota value in the specific region and zone.
type ResourcesQuotas ¶
type ResourcesQuotas struct { // Quotas represents slice of Quotas. Quotas []*Quota `json:"-"` }
ResourcesQuotas represents quotas for different resources.
func (*ResourcesQuotas) UnmarshalJSON ¶
func (result *ResourcesQuotas) UnmarshalJSON(b []byte) error
UnmarshalJSON implements custom unmarshalling method for the ResourcesQuotas type.
We need it to work with a JSON structure that the Quota Manager API responses with:
"quotas": { "compute_cores": [ { "value": 200, "zone": "ru-2a" }, ... ], ... }
type ResponseQuotas ¶
type ResponseQuotas struct { Quotas InfoQuotas `json:"quotas"` Errors []ResourceError `json:"errors"` }
type UpdateProjectQuotasOpts ¶
type UpdateProjectQuotasOpts struct { // QuotasOpts represents a slice of QuotaOpts. QuotasOpts []QuotaOpts `json:"-"` }
UpdateProjectQuotasOpts represents options for the UpdateProjectQuotas request.
func (*UpdateProjectQuotasOpts) MarshalJSON ¶
func (opts *UpdateProjectQuotasOpts) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshalling method for the UpdateProjectQuotasOpts.
We need it to marshal structure to a JSON that the quota manager v1 API wants:
"quotas": { "compute_cores": [ { "value": 200, "zone": "ru-2a" }, ... ], ... }