Documentation ¶
Overview ¶
Package quotas provides the ability to retrieve and update quotas through the Resell v2 API.
Example of getting all quotas for a domain
allQuotas, _, err := quotas.GetAll(ctx, resellClient) if err != nil { log.Fatal(err) } for _, myQuota := range allQuotas { fmt.Println(myQuota) }
Example of getting free quotas for a domain
freeQuotas, _, err := quotas.GetFree(ctx, resellClient) if err != nil { log.Fatal(err) } for _, myQuota := range allQuotas { fmt.Println(myQuota) }
Example of getting projects quotas for a domain
projectsQuotas, _, err := quotas.GetProjectsQuotas(ctx, resellClient) if err != nil { log.Fatal(err) } for _, projectQuota := range projectsQuotas { fmt.Printf("quotas for %s:\n", projectQuota.ID) for _, resourceQuota := range projectQuota.ProjectQuotas { fmt.Println(resourceQuota) } }
Example of getting quotas for a single project
singleProjectQuotas, _, err := quotas.GetProjectQuotas(ctx, resellClient, updateProjectID) if err != nil { log.Fatal(err) } for _, singleProjectQuota := range singleProjectQuotas { fmt.Println(singleProjectQuota) }
Example of updating quotas for a single project
projectQuotaUpdateOpts := quotas.UpdateProjectQuotasOpts{ QuotasOpts: []*quotas.QuotaOpts{ { Name: "image_gigabytes", ResourceQuotasOpts: []quotas.ResourceQuotaOpts{ { Region: "ru-1", Value: 10, }, { Region: "ru-2", Value: 20, }, }, }, }, } updatedProjectQuotas, _, err := quotas.UpdateProjectQuotas(context, resellClient, updateProjectID, projectQuotaUpdateOpts) if err != nil { log.Fatal(err) } for _, updatedProjectQuota := range updatedProjectQuotas { fmt.Println(updatedProjectQuota) }
Index ¶
- type ProjectQuota
- type ProjectsQuotas
- type Quota
- func GetAll(ctx context.Context, client *selvpcclient.ServiceClient) ([]*Quota, *selvpcclient.ResponseResult, error)
- func GetFree(ctx context.Context, client *selvpcclient.ServiceClient) ([]*Quota, *selvpcclient.ResponseResult, error)
- func GetProjectQuotas(ctx context.Context, client *selvpcclient.ServiceClient, id string) ([]*Quota, *selvpcclient.ResponseResult, error)
- func UpdateProjectQuotas(ctx context.Context, client *selvpcclient.ServiceClient, id string, ...) ([]*Quota, *selvpcclient.ResponseResult, error)
- type QuotaOpts
- type ResourceQuotaEntity
- type ResourceQuotaOpts
- type ResourcesQuotas
- type UpdateProjectQuotasOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProjectQuota ¶
type ProjectQuota struct { // ID is a project unique id. ID string `json:"-"` // ProjectQuotas contains project's quota information. ProjectQuotas []Quota `json:"-"` }
ProjectQuota represents quota information of a single project.
func GetProjectsQuotas ¶
func GetProjectsQuotas(ctx context.Context, client *selvpcclient.ServiceClient) ([]*ProjectQuota, *selvpcclient.ResponseResult, error)
GetProjectsQuotas returns the quotas info for all domain projects.
type ProjectsQuotas ¶
type ProjectsQuotas struct { // ProjectQuotas represents slice of ProjectQuotas. ProjectQuotas []*ProjectQuota `json:"-"` }
ProjectsQuotas represents quotas for different projects.
func (*ProjectsQuotas) UnmarshalJSON ¶
func (result *ProjectsQuotas) UnmarshalJSON(b []byte) error
UnmarshalJSON implements custom unmarshalling method for the ProjectsQuotas type.
We need it to work with a JSON structure that the Resell v2 API responses with:
"quotas": { "6d23928357bb4e0eb302794bc57fb8fd": { "compute_cores": [ { "region": "ru-1", "used": 2, "value": 10, "zone": "ru-1b" }, ... ] }, ... }
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 different locations. ResourceQuotasEntities []ResourceQuotaEntity `json:"-"` }
Quota represents a quota information for a single billing resource.
func GetAll ¶
func GetAll(ctx context.Context, client *selvpcclient.ServiceClient) ([]*Quota, *selvpcclient.ResponseResult, error)
GetAll returns the total amount of resources available to be allocated to projects.
func GetFree ¶
func GetFree(ctx context.Context, client *selvpcclient.ServiceClient) ([]*Quota, *selvpcclient.ResponseResult, error)
GetFree returns the current amount of resources available to be allocated to projects.
func GetProjectQuotas ¶
func GetProjectQuotas(ctx context.Context, client *selvpcclient.ServiceClient, id string) ([]*Quota, *selvpcclient.ResponseResult, error)
GetProjectQuotas returns the quotas info for a single project referenced by id.
func UpdateProjectQuotas ¶
func UpdateProjectQuotas(ctx context.Context, client *selvpcclient.ServiceClient, id string, updateOpts UpdateProjectQuotasOpts) ([]*Quota, *selvpcclient.ResponseResult, error)
UpdateProjectQuotas updates the quotas info for a single project referenced by id.
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 ResourceQuotaEntity ¶
type ResourceQuotaEntity struct { // Region contains the quota region data. Region string `json:"region"` // Zone contains the quota zone data. Zone string `json:"zone"` // Value contans value of resource quota in the specific region and zone. // It represents a free quota value if used with the GetFree request. Value int `json:"value"` // Used contains quantity of a used quota in the specific region and zone. Used int `json:"used"` }
ResourceQuotaEntity represents a single entity of the resource quota data in the specific region and zone.
type ResourceQuotaOpts ¶
type ResourceQuotaOpts struct { // Region contains the quota region data. Region *string `json:"region"` // Zone contains the quota zone data. Zone *string `json:"zone"` // Value contans 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 Resell v2 API responses with:
"quotas": { "compute_cores": [ { "region": "ru-2", "value": 200, "zone": "ru-2a" }, ... ], ... }
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 a JSON that the Resell v2 API wants:
"quotas": { "compute_cores": [ { "region": "ru-2", "value": 200, "zone": "ru-2a" }, ... ], ... }