quotas

package
v3.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

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(client, projectID, regionName)
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(client, 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, client, projectID, regionName, projectQuotaUpdateOpts)
if err != nil {
  log.Fatal(err)
}
for _, updatedProjectQuota := range updatedProjectQuotas {
  fmt.Println(updatedProjectQuota)
}

Index

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(client *selvpcclient.Client, projectID, region string,
) ([]*Quota, *clientservices.ResponseResult, error)

GetLimits returns limits for a single project referenced by id in specific region.

func GetProjectQuotas

func GetProjectQuotas(client *selvpcclient.Client, projectID, region string,
) ([]*Quota, *clientservices.ResponseResult, error)

GetProjectQuotas returns the quotas info for a single project referenced by id in specific region.

func UpdateProjectQuotas

func UpdateProjectQuotas(client *selvpcclient.Client, projectID, region string,
	updateOpts UpdateProjectQuotasOpts,
) ([]*Quota, *clientservices.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"
        },
        ...
    ],
    ...
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL