flavors

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Overview

Package flavors provides information and interaction with the flavor API in the OpenStack Compute service.

A flavor is an available hardware configuration for a server. Each flavor has a unique combination of disk space, memory capacity and priority for CPU time.

Example to List Flavors

listOpts := flavors.ListOpts{
	AccessType: flavors.PublicAccess,
}

allPages, err := flavors.ListDetail(computeClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allFlavors, err := flavors.ExtractFlavors(allPages)
if err != nil {
	panic(err)
}

for _, flavor := range allFlavors {
	fmt.Printf("%+v\n", flavor)
}

Example to Create a Flavor

createOpts := flavors.CreateOpts{
	ID:         "1",
	Name:       "m1.tiny",
	Disk:       golangsdk.IntToPointer(1),
	RAM:        512,
	VCPUs:      1,
	RxTxFactor: 1.0,
}

flavor, err := flavors.Create(computeClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to List Flavor Access

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

allPages, err := flavors.ListAccesses(computeClient, flavorID).AllPages()
if err != nil {
	panic(err)
}

allAccesses, err := flavors.ExtractAccesses(allPages)
if err != nil {
	panic(err)
}

for _, access := range allAccesses {
	fmt.Printf("%+v", access)
}

Example to Grant Access to a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

accessOpts := flavors.AddAccessOpts{
	Tenant: "15153a0979884b59b0592248ef947921",
}

accessList, err := flavors.AddAccess(computeClient, flavor.ID, accessOpts).Extract()
if err != nil {
	panic(err)
}

Example to Remove/Revoke Access to a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

accessOpts := flavors.RemoveAccessOpts{
	Tenant: "15153a0979884b59b0592248ef947921",
}

accessList, err := flavors.RemoveAccess(computeClient, flavor.ID, accessOpts).Extract()
if err != nil {
	panic(err)
}

Example to Create Extra Specs for a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

createOpts := flavors.ExtraSpecsOpts{
	"hw:cpu_policy":        "CPU-POLICY",
	"hw:cpu_thread_policy": "CPU-THREAD-POLICY",
}
createdExtraSpecs, err := flavors.CreateExtraSpecs(computeClient, flavorID, createOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Printf("%+v", createdExtraSpecs)

Example to Get Extra Specs for a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

extraSpecs, err := flavors.ListExtraSpecs(computeClient, flavorID).Extract()
if err != nil {
	panic(err)
}

fmt.Printf("%+v", extraSpecs)

Example to Update Extra Specs for a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"

updateOpts := flavors.ExtraSpecsOpts{
	"hw:cpu_thread_policy": "CPU-THREAD-POLICY-UPDATED",
}
updatedExtraSpec, err := flavors.UpdateExtraSpec(computeClient, flavorID, updateOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Printf("%+v", updatedExtraSpec)

Example to Delete an Extra Spec for a Flavor

flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b"
err := flavors.DeleteExtraSpec(computeClient, flavorID, "hw:cpu_thread_policy").ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDFromName

func IDFromName(client *golangsdk.ServiceClient, name string) (string, error)

IDFromName is a convienience function that returns a flavor's ID given its name.

func ListAccesses

func ListAccesses(client *golangsdk.ServiceClient, id string) pagination.Pager

ListAccesses retrieves the tenants which have access to a flavor.

func ListDetail

func ListDetail(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager

ListDetail instructs OpenStack to provide a list of flavors. You may provide criteria by which List curtails its results for easier processing.

Types

type AccessPage

type AccessPage struct {
	pagination.SinglePageBase
}

AccessPage contains a single page of all FlavorAccess entries for a flavor.

func (AccessPage) IsEmpty

func (page AccessPage) IsEmpty() (bool, error)

IsEmpty indicates whether an AccessPage is empty.

type AccessType

type AccessType string

AccessType maps to OpenStack's Flavor.is_public field. Although the is_public field is boolean, the request options are ternary, which is why AccessType is a string. The following values are allowed:

The AccessType arguement is optional, and if it is not supplied, OpenStack returns the PublicAccess flavors.

const (
	// PublicAccess returns public flavors and private flavors associated with
	// that project.
	PublicAccess AccessType = "true"

	// PrivateAccess (admin only) returns private flavors, across all projects.
	PrivateAccess AccessType = "false"

	// AllAccess (admin only) returns public and private flavors across all
	// projects.
	AllAccess AccessType = "None"
)

type AddAccessOpts

type AddAccessOpts struct {
	// Tenant is the project/tenant ID to grant access.
	Tenant string `json:"tenant"`
}

AddAccessOpts represents options for adding access to a flavor.

func (AddAccessOpts) ToFlavorAddAccessMap

func (opts AddAccessOpts) ToFlavorAddAccessMap() (map[string]interface{}, error)

ToFlavorAddAccessMap constructs a request body from AddAccessOpts.

type AddAccessOptsBuilder

type AddAccessOptsBuilder interface {
	ToFlavorAddAccessMap() (map[string]interface{}, error)
}

AddAccessOptsBuilder allows extensions to add additional parameters to the AddAccess requests.

type AddAccessResult

type AddAccessResult struct {
	// contains filtered or unexported fields
}

AddAccessResult is the response of an AddAccess operation. Call its Extract method to interpret it as a slice of FlavorAccess.

func AddAccess

func AddAccess(client *golangsdk.ServiceClient, id string, opts AddAccessOptsBuilder) (r AddAccessResult)

AddAccess grants a tenant/project access to a flavor.

func (AddAccessResult) Extract

func (r AddAccessResult) Extract() ([]FlavorAccess, error)

Extract provides access to the result of an access create or delete. The result will be all accesses that the flavor has.

type CreateExtraSpecsOptsBuilder

type CreateExtraSpecsOptsBuilder interface {
	ToFlavorExtraSpecsCreateMap() (map[string]interface{}, error)
}

CreateExtraSpecsOptsBuilder allows extensions to add additional parameters to the CreateExtraSpecs requests.

type CreateExtraSpecsResult

type CreateExtraSpecsResult struct {
	// contains filtered or unexported fields
}

CreateExtraSpecResult contains the result of a Create operation. Call its Extract method to interpret it as a map[string]interface.

func CreateExtraSpecs

func CreateExtraSpecs(client *golangsdk.ServiceClient, flavorID string, opts CreateExtraSpecsOptsBuilder) (r CreateExtraSpecsResult)

CreateExtraSpecs will create or update the extra-specs key-value pairs for the specified Flavor.

func (CreateExtraSpecsResult) Extract

func (r CreateExtraSpecsResult) Extract() (map[string]string, error)

Extract interprets any extraSpecsResult as ExtraSpecs, if possible.

type CreateOpts

type CreateOpts struct {
	// Name is the name of the flavor.
	Name string `json:"name" required:"true"`

	// RAM is the memory of the flavor, measured in MB.
	RAM int `json:"ram" required:"true"`

	// VCPUs is the number of vcpus for the flavor.
	VCPUs int `json:"vcpus" required:"true"`

	// Disk the amount of root disk space, measured in GB.
	Disk *int `json:"disk" required:"true"`

	// ID is a unique ID for the flavor.
	ID string `json:"id,omitempty"`

	// Swap is the amount of swap space for the flavor, measured in MB.
	Swap *int `json:"swap,omitempty"`

	// RxTxFactor alters the network bandwidth of a flavor.
	RxTxFactor float64 `json:"rxtx_factor,omitempty"`

	// IsPublic flags a flavor as being available to all projects or not.
	IsPublic *bool `json:"os-flavor-access:is_public,omitempty"`

	// Ephemeral is the amount of ephemeral disk space, measured in GB.
	Ephemeral *int `json:"OS-FLV-EXT-DATA:ephemeral,omitempty"`
}

CreateOpts specifies parameters used for creating a flavor.

func (CreateOpts) ToFlavorCreateMap

func (opts CreateOpts) ToFlavorCreateMap() (map[string]interface{}, error)

ToFlavorCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToFlavorCreateMap() (map[string]interface{}, error)
}

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

CreateResult is the response of a Get operations. Call its Extract method to interpret it as a Flavor.

func Create

func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new flavor.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Flavor, error)

Extract provides access to the individual Flavor returned by the Get and Create functions.

type DeleteExtraSpecResult

type DeleteExtraSpecResult struct {
	golangsdk.ErrResult
}

DeleteExtraSpecResult contains the result of a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.

func DeleteExtraSpec

func DeleteExtraSpec(client *golangsdk.ServiceClient, flavorID, key string) (r DeleteExtraSpecResult)

DeleteExtraSpec will delete the key-value pair with the given key for the given flavor ID.

type DeleteResult

type DeleteResult struct {
	golangsdk.ErrResult
}

DeleteResult is the result from a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.

func Delete

func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult)

Delete deletes the specified flavor ID.

type ExtraSpecsOpts

type ExtraSpecsOpts map[string]string

ExtraSpecsOpts is a map that contains key-value pairs.

func (ExtraSpecsOpts) ToFlavorExtraSpecUpdateMap

func (opts ExtraSpecsOpts) ToFlavorExtraSpecUpdateMap() (map[string]string, string, error)

ToFlavorExtraSpecUpdateMap assembles a body for an Update request based on the contents of a ExtraSpecOpts.

func (ExtraSpecsOpts) ToFlavorExtraSpecsCreateMap

func (opts ExtraSpecsOpts) ToFlavorExtraSpecsCreateMap() (map[string]interface{}, error)

ToFlavorExtraSpecsCreateMap assembles a body for a Create request based on the contents of ExtraSpecsOpts.

type Flavor

type Flavor struct {
	// ID is the flavor's unique ID.
	ID string `json:"id"`

	// Disk is the amount of root disk, measured in GB.
	Disk int `json:"disk"`

	// RAM is the amount of memory, measured in MB.
	RAM int `json:"ram"`

	// Name is the name of the flavor.
	Name string `json:"name"`

	// RxTxFactor describes bandwidth alterations of the flavor.
	RxTxFactor float64 `json:"rxtx_factor"`

	// Swap is the amount of swap space, measured in MB.
	Swap int `json:"-"`

	// VCPUs indicates how many (virtual) CPUs are available for this flavor.
	VCPUs int `json:"vcpus"`

	// IsPublic indicates whether the flavor is public.
	IsPublic bool `json:"os-flavor-access:is_public"`

	// Ephemeral is the amount of ephemeral disk space, measured in GB.
	Ephemeral int `json:"OS-FLV-EXT-DATA:ephemeral"`
}

Flavor represent (virtual) hardware configurations for server resources in a region.

func ExtractFlavors

func ExtractFlavors(r pagination.Page) ([]Flavor, error)

ExtractFlavors provides access to the list of flavors in a page acquired from the ListDetail operation.

func (*Flavor) UnmarshalJSON

func (r *Flavor) UnmarshalJSON(b []byte) error

type FlavorAccess

type FlavorAccess struct {
	// FlavorID is the unique ID of the flavor.
	FlavorID string `json:"flavor_id"`

	// TenantID is the unique ID of the tenant.
	TenantID string `json:"tenant_id"`
}

FlavorAccess represents an ACL of tenant access to a specific Flavor.

func ExtractAccesses

func ExtractAccesses(r pagination.Page) ([]FlavorAccess, error)

ExtractAccesses interprets a page of results as a slice of FlavorAccess.

type FlavorPage

type FlavorPage struct {
	pagination.LinkedPageBase
}

FlavorPage contains a single page of all flavors from a ListDetails call.

func (FlavorPage) IsEmpty

func (page FlavorPage) IsEmpty() (bool, error)

IsEmpty determines if a FlavorPage contains any results.

func (FlavorPage) NextPageURL

func (page FlavorPage) NextPageURL() (string, error)

NextPageURL uses the response's embedded link reference to navigate to the next page of results.

type GetExtraSpecResult

type GetExtraSpecResult struct {
	// contains filtered or unexported fields
}

GetExtraSpecResult contains the result of a Get operation. Call its Extract method to interpret it as a map[string]interface.

func GetExtraSpec

func GetExtraSpec(client *golangsdk.ServiceClient, flavorID string, key string) (r GetExtraSpecResult)

func (GetExtraSpecResult) Extract

func (r GetExtraSpecResult) Extract() (map[string]string, error)

Extract interprets any extraSpecResult as an ExtraSpec, if possible.

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult is the response of a Get operations. Call its Extract method to interpret it as a Flavor.

func Get

func Get(client *golangsdk.ServiceClient, id string) (r GetResult)

Get retrieves details of a single flavor. Use ExtractFlavor to convert its result into a Flavor.

func (GetResult) Extract

func (r GetResult) Extract() (*Flavor, error)

Extract provides access to the individual Flavor returned by the Get and Create functions.

type ListExtraSpecsResult

type ListExtraSpecsResult struct {
	// contains filtered or unexported fields
}

ListExtraSpecsResult contains the result of a Get operation. Call its Extract method to interpret it as a map[string]interface.

func ListExtraSpecs

func ListExtraSpecs(client *golangsdk.ServiceClient, flavorID string) (r ListExtraSpecsResult)

ExtraSpecs requests all the extra-specs for the given flavor ID.

func (ListExtraSpecsResult) Extract

func (r ListExtraSpecsResult) Extract() (map[string]string, error)

Extract interprets any extraSpecsResult as ExtraSpecs, if possible.

type ListOpts

type ListOpts struct {
	// ChangesSince, if provided, instructs List to return only those things which
	// have changed since the timestamp provided.
	ChangesSince string `q:"changes-since"`

	// MinDisk and MinRAM, if provided, elides flavors which do not meet your
	// criteria.
	MinDisk int `q:"minDisk"`
	MinRAM  int `q:"minRam"`

	// SortDir allows to select sort direction.
	// It can be "asc" or "desc" (default).
	SortDir string `q:"sort_dir"`

	// SortKey allows to sort by one of the flavors attributes.
	// Default is flavorid.
	SortKey string `q:"sort_key"`

	// Marker and Limit control paging.
	// Marker instructs List where to start listing from.
	Marker string `q:"marker"`

	// Limit instructs List to refrain from sending excessively large lists of
	// flavors.
	Limit int `q:"limit"`

	// AccessType, if provided, instructs List which set of flavors to return.
	// If IsPublic not provided, flavors for the current project are returned.
	AccessType AccessType `q:"is_public"`
}

ListOpts filters the results returned by the List() function. For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20.

Typically, software will use the last ID of the previous call to List to set the Marker for the current call.

func (ListOpts) ToFlavorListQuery

func (opts ListOpts) ToFlavorListQuery() (string, error)

ToFlavorListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToFlavorListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

type RemoveAccessOpts

type RemoveAccessOpts struct {
	// Tenant is the project/tenant ID to grant access.
	Tenant string `json:"tenant"`
}

RemoveAccessOpts represents options for removing access to a flavor.

func (RemoveAccessOpts) ToFlavorRemoveAccessMap

func (opts RemoveAccessOpts) ToFlavorRemoveAccessMap() (map[string]interface{}, error)

ToFlavorRemoveAccessMap constructs a request body from RemoveAccessOpts.

type RemoveAccessOptsBuilder

type RemoveAccessOptsBuilder interface {
	ToFlavorRemoveAccessMap() (map[string]interface{}, error)
}

RemoveAccessOptsBuilder allows extensions to add additional parameters to the RemoveAccess requests.

type RemoveAccessResult

type RemoveAccessResult struct {
	// contains filtered or unexported fields
}

RemoveAccessResult is the response of a RemoveAccess operation. Call its Extract method to interpret it as a slice of FlavorAccess.

func RemoveAccess

func RemoveAccess(client *golangsdk.ServiceClient, id string, opts RemoveAccessOptsBuilder) (r RemoveAccessResult)

RemoveAccess removes/revokes a tenant/project access to a flavor.

func (RemoveAccessResult) Extract

func (r RemoveAccessResult) Extract() ([]FlavorAccess, error)

Extract provides access to the result of an access create or delete. The result will be all accesses that the flavor has.

type UpdateExtraSpecOptsBuilder

type UpdateExtraSpecOptsBuilder interface {
	ToFlavorExtraSpecUpdateMap() (map[string]string, string, error)
}

UpdateExtraSpecOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateExtraSpecResult

type UpdateExtraSpecResult struct {
	// contains filtered or unexported fields
}

UpdateExtraSpecResult contains the result of an Update operation. Call its Extract method to interpret it as a map[string]interface.

func UpdateExtraSpec

func UpdateExtraSpec(client *golangsdk.ServiceClient, flavorID string, opts UpdateExtraSpecOptsBuilder) (r UpdateExtraSpecResult)

UpdateExtraSpec will updates the value of the specified flavor's extra spec for the key in opts.

func (UpdateExtraSpecResult) Extract

func (r UpdateExtraSpecResult) Extract() (map[string]string, error)

Extract interprets any extraSpecResult as an ExtraSpec, if possible.

Directories

Path Synopsis
flavors unit tests
flavors unit tests

Jump to

Keyboard shortcuts

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