go-selvpcclient: github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/quotas Index | Files | Directories

package quotas

import "github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/quotas"

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

Package Files

doc.go requests.go requests_opts.go schemas.go

type ProjectQuota Uses

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 Uses

func GetProjectsQuotas(ctx context.Context, client *selvpcclient.ServiceClient) ([]*ProjectQuota, *selvpcclient.ResponseResult, error)

GetProjectsQuotas returns the quotas info for all domain projects.

type ProjectsQuotas Uses

type ProjectsQuotas struct {
    // ProjectQuotas represents slice of ProjectQuotas.
    ProjectQuotas []*ProjectQuota `json:"-"`
}

ProjectsQuotas represents quotas for different projects.

func (*ProjectsQuotas) UnmarshalJSON Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type ResourceQuotaOpts struct {
    // Region contains the quota region data.
    Region string `json:"region,omitempty"`

    // Zone contains the quota zone data.
    Zone string `json:"zone,omitempty"`

    // 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 Uses

type ResourcesQuotas struct {
    // Quotas represents slice of Quotas.
    Quotas []*Quota `json:"-"`
}

ResourcesQuotas represents quotas for different resources.

func (*ResourcesQuotas) UnmarshalJSON Uses

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 Uses

type UpdateProjectQuotasOpts struct {
    // QuotasOpts represents a slice of QuotaOpts.
    QuotasOpts []QuotaOpts `json:"-"`
}

UpdateProjectQuotasOpts represents options for the UpdateProjectQuotas request.

func (*UpdateProjectQuotasOpts) MarshalJSON Uses

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"
        },
        ...
    ],
    ...
}

Directories

PathSynopsis
testing

Package quotas imports 7 packages (graph) and is imported by 3 packages. Updated 2018-12-12. Refresh now. Tools for package owners.