flavors

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package flavors provides information and interaction with the flavor API in the Enterprise Cloud 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:       eclcloud.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 *eclcloud.ServiceClient, name string) (string, error)

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

func ListDetail

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

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

Types

type AccessType

type AccessType string

AccessType maps to Enterprise Cloud'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, Enterprise Cloud 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 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 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 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 *eclcloud.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 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.

Jump to

Keyboard shortcuts

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